Java Code Examples for org.springframework.context.support.AbstractApplicationContext#close()
The following examples show how to use
org.springframework.context.support.AbstractApplicationContext#close() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: UserProducerApp.java From Spring with Apache License 2.0 | 6 votes |
public static void main(String[] args) throws IOException { AbstractApplicationContext context = new AnnotationConfigApplicationContext( ServiceConfig.class, JmsCommonConfig.class, JmsProducerConfig.class); UserService userService = context.getBean(UserService.class); UserSender userSender = context.getBean(UserSender.class); List<User> users = userService.findAll(); assertTrue(users.size() > 0); for (User user : users) { userSender.sendMessage(user); } log.info("User message sent. Wait for confirmation..."); System.in.read(); context.close(); }
Example 2
Source File: SpringProcessApplicationTest.java From camunda-bpm-platform with Apache License 2.0 | 6 votes |
@Test public void testDeployProcessArchive() { // start a spring application context AbstractApplicationContext applicationContext = new ClassPathXmlApplicationContext("org/camunda/bpm/engine/spring/test/application/SpringProcessArchiveDeploymentTest-context.xml"); applicationContext.start(); // assert the process archive is deployed: ProcessEngine processEngine = BpmPlatform.getDefaultProcessEngine(); Assert.assertNotNull(processEngine.getRepositoryService().createDeploymentQuery().deploymentName("pa").singleResult()); applicationContext.close(); // assert the process is undeployed Assert.assertNull(processEngine.getRepositoryService().createDeploymentQuery().deploymentName("pa").singleResult()); }
Example 3
Source File: SpringProcessApplicationTest.java From camunda-bpm-platform with Apache License 2.0 | 6 votes |
@Test public void testProcessApplicationDeployment() { // initially no applications are deployed: Assert.assertEquals(0, BpmPlatform.getProcessApplicationService().getProcessApplicationNames().size()); // start a spring application context AbstractApplicationContext applicationContext = new ClassPathXmlApplicationContext("org/camunda/bpm/engine/spring/test/application/SpringProcessApplicationDeploymentTest-context.xml"); applicationContext.start(); // assert that there is a process application deployed with the name of the process application bean Assert.assertNotNull(BpmPlatform.getProcessApplicationService() .getProcessApplicationInfo("myProcessApplication")); // close the spring application context applicationContext.close(); // after closing the application context, the process application is undeployed. Assert.assertNull(BpmPlatform.getProcessApplicationService() .getProcessApplicationInfo("myProcessApplication")); }
Example 4
Source File: ApplicationLoaderListener.java From nextreports-server with Apache License 2.0 | 6 votes |
private static void updateStorage() { if (LOG.isDebugEnabled()) { LOG.debug("Update storage..."); } try { long t = System.currentTimeMillis(); String[] paths = { UPDATE_CONTEXT_PATH }; AbstractApplicationContext updateContext = new ClassPathXmlApplicationContext(paths); updateContext.getBean("updater"); updateContext.close(); t = System.currentTimeMillis() - t; if (LOG.isDebugEnabled()) { LOG.debug("Updated storage in " + t + " ms"); } } catch (Throwable tex) { LOG.error(tex.getMessage(), tex); } }
Example 5
Source File: ManagedProcessEngineFactoryBeanTest.java From camunda-bpm-platform with Apache License 2.0 | 6 votes |
@Test public void testProcessApplicationDeployment() { // initially, no process engine is registered: Assert.assertNull(BpmPlatform.getDefaultProcessEngine()); Assert.assertEquals(0, BpmPlatform.getProcessEngineService().getProcessEngines().size()); // start spring application context AbstractApplicationContext applicationContext = new ClassPathXmlApplicationContext("org/camunda/bpm/engine/spring/test/container/ManagedProcessEngineFactoryBean-context.xml"); applicationContext.start(); // assert that now the process engine is registered: Assert.assertNotNull(BpmPlatform.getDefaultProcessEngine()); // close the spring application context applicationContext.close(); // after closing the application context, the process engine is gone Assert.assertNull(BpmPlatform.getDefaultProcessEngine()); Assert.assertEquals(0, BpmPlatform.getProcessEngineService().getProcessEngines().size()); }
Example 6
Source File: PublicNetworkTest.java From cloudstack with Apache License 2.0 | 6 votes |
@AfterClass public static void globalTearDown() throws Exception { s_lockMaster.cleanupForServer(s_msId); JmxUtil.unregisterMBean("Locks", "Locks"); s_lockMaster = null; AbstractApplicationContext ctx = (AbstractApplicationContext)ComponentContext.getApplicationContext(); Map<String, ComponentLifecycle> lifecycleComponents = ctx.getBeansOfType(ComponentLifecycle.class); for (ComponentLifecycle bean : lifecycleComponents.values()) { bean.stop(); } ctx.close(); s_logger.info("destroying mysql server instance running at port <" + s_mysqlServerPort + ">"); TestDbSetup.destroy(s_mysqlServerPort, null); }
Example 7
Source File: NetworkProviderTest.java From cloudstack with Apache License 2.0 | 6 votes |
@AfterClass public static void globalTearDown() throws Exception { s_lockMaster.cleanupForServer(s_msId); JmxUtil.unregisterMBean("Locks", "Locks"); s_lockMaster = null; AbstractApplicationContext ctx = (AbstractApplicationContext)ComponentContext.getApplicationContext(); Map<String, ComponentLifecycle> lifecycleComponents = ctx.getBeansOfType(ComponentLifecycle.class); for (ComponentLifecycle bean : lifecycleComponents.values()) { bean.stop(); } ctx.close(); s_logger.info("destroying mysql server instance running at port <" + s_mysqlSrverPort + ">"); TestDbSetup.destroy(s_mysqlSrverPort, null); }
Example 8
Source File: TxIntegrationConfig.java From tutorials with MIT License | 6 votes |
public static void main(final String... args) { final AbstractApplicationContext context = new AnnotationConfigApplicationContext(TxIntegrationConfig.class); context.registerShutdownHook(); final Scanner scanner = new Scanner(System.in); System.out.print("Integration flow is running. Type q + <enter> to quit "); while (true) { final String input = scanner.nextLine(); if ("q".equals(input.trim())) { context.close(); scanner.close(); break; } } System.exit(0); }
Example 9
Source File: JavaDSLFileCopyConfig.java From tutorials with MIT License | 5 votes |
public static void main(final String... args) { final AbstractApplicationContext context = new AnnotationConfigApplicationContext(JavaDSLFileCopyConfig.class); context.registerShutdownHook(); final Scanner scanner = new Scanner(System.in); System.out.print("Please enter a string and press <enter>: "); while (true) { final String input = scanner.nextLine(); if ("q".equals(input.trim())) { context.close(); scanner.close(); break; } } System.exit(0); }
Example 10
Source File: ContentBasedFileRouterIntegrationTest.java From tutorials with MIT License | 5 votes |
@Test @Ignore public void routeWithJavaConfigTest() throws InterruptedException { AbstractApplicationContext applicationContext = new AnnotationConfigApplicationContext( ContentBasedFileRouterConfig.class); Thread.sleep(DURATION_MILIS); applicationContext.close(); }
Example 11
Source File: ContentBasedFileRouterIntegrationTest.java From tutorials with MIT License | 5 votes |
@Test @Ignore public void routeWithXMLConfigTest() throws InterruptedException { AbstractApplicationContext applicationContext = new ClassPathXmlApplicationContext( "camel-context-ContentBasedFileRouterTest.xml"); Thread.sleep(DURATION_MILIS); applicationContext.close(); }
Example 12
Source File: FileCopyConfig.java From tutorials with MIT License | 5 votes |
public static void main(final String... args) { final AbstractApplicationContext context = new AnnotationConfigApplicationContext(FileCopyConfig.class); context.registerShutdownHook(); final Scanner scanner = new Scanner(System.in); System.out.print("Please enter a string and press <enter>: "); while (true) { final String input = scanner.nextLine(); if ("q".equals(input.trim())) { context.close(); scanner.close(); break; } } System.exit(0); }
Example 13
Source File: UserConsumerApp.java From Spring with Apache License 2.0 | 5 votes |
public static void main(String[] args) throws IOException { AbstractApplicationContext context = new AnnotationConfigApplicationContext( JmsCommonConfig.class, JmsConsumerConfig.class); UserReceiver userReceiver = context.getBean(UserReceiver.class); assertNotNull(userReceiver); log.info("Waiting for user ..."); System.in.read(); context.close(); }
Example 14
Source File: AnnotationResource.java From spring-tutorial with Creative Commons Attribution Share Alike 4.0 International | 5 votes |
public static void main(String[] args) throws Exception { AbstractApplicationContext ctx = new ClassPathXmlApplicationContext("spring/spring-annotation.xml"); AnnotationResource annotationResource = (AnnotationResource) ctx.getBean("annotationResource"); log.debug("type: {}, name: {}", annotationResource.getFieldA().getClass(), annotationResource.getFieldA().getName()); log.debug("type: {}, name: {}", annotationResource.getFieldB().getClass(), annotationResource.getFieldB().getName()); log.debug("type: {}, name: {}", annotationResource.getFieldC().getClass(), annotationResource.getFieldC().getName()); ctx.close(); }
Example 15
Source File: AnnotationInject.java From spring-tutorial with Creative Commons Attribution Share Alike 4.0 International | 5 votes |
public static void main(String[] args) throws Exception { AbstractApplicationContext ctx = new ClassPathXmlApplicationContext("spring/spring-annotation.xml"); AnnotationInject annotationInject = (AnnotationInject) ctx.getBean("annotationInject"); log.debug("type: {}, name: {}", annotationInject.getFieldA().getClass(), annotationInject.getFieldA().getName()); log.debug("type: {}, name: {}", annotationInject.getFieldB().getClass(), annotationInject.getFieldB().getName()); log.debug("type: {}, name: {}", annotationInject.getFieldC().getClass(), annotationInject.getFieldC().getName()); ctx.close(); }
Example 16
Source File: AnnotationQualifier.java From spring-tutorial with Creative Commons Attribution Share Alike 4.0 International | 5 votes |
public static void main(String[] args) throws Exception { AbstractApplicationContext ctx = new ClassPathXmlApplicationContext("spring/spring-annotation.xml"); AnnotationQualifier annotationQualifier = (AnnotationQualifier) ctx.getBean("annotationQualifier"); log.debug("type: {}, name: {}", annotationQualifier.getFieldA().getClass(), annotationQualifier.getFieldA().getName()); log.debug("type: {}, name: {}", annotationQualifier.getFieldB().getClass(), annotationQualifier.getFieldB().getName()); ctx.close(); }
Example 17
Source File: AnnotationRequired.java From spring-tutorial with Creative Commons Attribution Share Alike 4.0 International | 5 votes |
public static void main(String[] args) throws Exception { AbstractApplicationContext ctx = new ClassPathXmlApplicationContext("spring/spring-annotation.xml"); AnnotationRequired annotationRequired = (AnnotationRequired) ctx.getBean("annotationRequired"); log.debug("name: {}", annotationRequired.getName()); ctx.close(); }
Example 18
Source File: AnnotationAutowired.java From spring-tutorial with Creative Commons Attribution Share Alike 4.0 International | 5 votes |
public static void main(String[] args) throws Exception { AbstractApplicationContext ctx = new ClassPathXmlApplicationContext("spring/spring-annotation.xml"); AnnotationAutowired annotationAutowired = (AnnotationAutowired) ctx.getBean("annotationAutowired"); log.debug("type: {}, name: {}", annotationAutowired.getFieldA().getClass(), annotationAutowired.getFieldA().getName()); log.debug("type: {}, name: {}", annotationAutowired.getFieldB().getClass(), annotationAutowired.getFieldB().getName()); log.debug("type: {}, name: {}", annotationAutowired.getFieldC().getClass(), annotationAutowired.getFieldC().getName()); ctx.close(); }
Example 19
Source File: SpringLifecycle.java From incubator-batchee with Apache License 2.0 | 4 votes |
@Override public void stop(final AbstractApplicationContext state) { state.close(); }
Example 20
Source File: SpringProcessApplicationTest.java From camunda-bpm-platform with Apache License 2.0 | 4 votes |
@Test public void testPostDeployRegistrationPa() { // this test verifies that a process application is able to register a deployment from the @PostDeploy callback: AbstractApplicationContext applicationContext = new ClassPathXmlApplicationContext("org/camunda/bpm/engine/spring/test/application/PostDeployRegistrationPaTest-context.xml"); applicationContext.start(); ProcessEngine processEngine = BpmPlatform.getDefaultProcessEngine(); // create a manual deployment: Deployment deployment = processEngine.getRepositoryService() .createDeployment() .addClasspathResource("org/camunda/bpm/engine/spring/test/application/process.bpmn20.xml") .deploy(); // lookup the process application spring bean: PostDeployRegistrationPa processApplication = applicationContext.getBean("customProcessApplicaiton", PostDeployRegistrationPa.class); Assert.assertFalse(processApplication.isPostDeployInvoked()); processApplication.deploy(); Assert.assertTrue(processApplication.isPostDeployInvoked()); // the process application was not invoked Assert.assertFalse(processApplication.isInvoked()); // start process instance: processEngine.getRuntimeService() .startProcessInstanceByKey("startToEnd"); // now the process application was invoked: Assert.assertTrue(processApplication.isInvoked()); // undeploy PA Assert.assertFalse(processApplication.isPreUndeployInvoked()); processApplication.undeploy(); Assert.assertTrue(processApplication.isPreUndeployInvoked()); // manually undeploy the process processEngine.getRepositoryService() .deleteDeployment(deployment.getId(), true); applicationContext.close(); }