Java Code Examples for org.springframework.context.support.ClassPathXmlApplicationContext#registerShutdownHook()
The following examples show how to use
org.springframework.context.support.ClassPathXmlApplicationContext#registerShutdownHook() .
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: AgentMain.java From gocd with Apache License 2.0 | 6 votes |
public static void main(String... argv) { AgentBootstrapperArgs args = new AgentCLI().parse(argv); LogConfigurator logConfigurator = new LogConfigurator(DEFAULT_LOGBACK_CONFIGURATION_FILE); logConfigurator.initialize(); new SystemEnvironment().setProperty("go.process.type", "agent"); Map<String, String> stringStringMap = args.toProperties(); new SystemEnvironment().setProperty(SystemEnvironment.SERVICE_URL, args.getServerUrl().toString()); for (Map.Entry<String, String> entry : stringStringMap.entrySet()) { new SystemEnvironment().setProperty(entry.getKey(), entry.getValue()); } ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("applicationContext.xml"); ctx.registerShutdownHook(); }
Example 2
Source File: SpringContainer.java From dubbo-2.6.5 with Apache License 2.0 | 5 votes |
@Override public void start() { String configPath = ConfigUtils.getProperty(SPRING_CONFIG); if (configPath == null || configPath.length() == 0) { configPath = DEFAULT_SPRING_CONFIG; } context = new ClassPathXmlApplicationContext(configPath.split("[,\\s]+"), false); context.addApplicationListener(new DubboApplicationListener()); context.registerShutdownHook(); context.refresh(); context.start(); }
Example 3
Source File: ApplicationContextTest.java From Spring with Apache License 2.0 | 5 votes |
@Test public void testDataSource1() { ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("classpath:spring/test-config-01.xml"); System.out.println(" >> init done."); DataSource dataSource1 = ctx.getBean("dataSource1", DataSource.class); assertNotNull(dataSource1); System.out.println(" >> usage done."); ctx.registerShutdownHook(); }
Example 4
Source File: ApplicationContextTest.java From Spring with Apache License 2.0 | 5 votes |
@Test public void testDataSource1() { ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("classpath:spring/test-config-01.xml"); logger.info(" >> init done."); DataSource dataSource1 = ctx.getBean("dataSource1", DataSource.class); assertNotNull(dataSource1); logger.info(" >> usage done."); ctx.registerShutdownHook(); }
Example 5
Source File: BasicProvider.java From dubbo-samples with Apache License 2.0 | 5 votes |
public static void main(String[] args) throws Exception { new EmbeddedZooKeeper(2181, false).start(); ZKTools.generateDubboProperties(); Thread.sleep(2000); ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("spring/configcenter-provider.xml"); context.registerShutdownHook(); context.start(); System.out.println("dubbo service started"); new CountDownLatch(1).await(); }
Example 6
Source File: BasicProvider.java From dubbo-samples with Apache License 2.0 | 5 votes |
public static void main(String[] args) throws Exception { ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("spring/configcenter-provider.xml"); context.registerShutdownHook(); context.start(); System.out.println("dubbo service started"); new CountDownLatch(1).await(); }
Example 7
Source File: Provider.java From dubbo-samples with Apache License 2.0 | 5 votes |
/** * To get ipv6 address to work, add * System.setProperty("java.net.preferIPv6Addresses", "true"); * before running your application. */ public static void main(String[] args) throws Exception { new EmbeddedZooKeeper(2181, false).start(); ZKTools.generateDubboProperties(); Thread.sleep(2000); ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("META-INF/spring/dubbo.provider.xml"); context.registerShutdownHook(); context.start(); System.out.println("dubbo service started"); new CountDownLatch(1).await(); }
Example 8
Source File: Provider.java From dubbo-samples with Apache License 2.0 | 5 votes |
/** * To get ipv6 address to work, add * System.setProperty("java.net.preferIPv6Addresses", "true"); * before running your application. */ public static void main(String[] args) throws Exception { new EmbeddedZooKeeper(2181, false).start(); ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("META-INF/spring/dubbo.provider.xml"); context.registerShutdownHook(); context.start(); System.out.println("dubbo service started"); new CountDownLatch(1).await(); }
Example 9
Source File: BeanLifeCycleDemo.java From spring-tutorial with Creative Commons Attribution Share Alike 4.0 International | 5 votes |
public static void main(String[] args) { System.out.println("现在开始初始化容器"); ClassPathXmlApplicationContext factory = new ClassPathXmlApplicationContext("spring-beans.xml"); System.out.println("容器初始化成功"); Person person = factory.getBean("person", Person.class); System.out.println(person); System.out.println("现在开始关闭容器!"); factory.registerShutdownHook(); }
Example 10
Source File: EntryPoint.java From pgptool with GNU General Public License v3.0 | 4 votes |
public static void main(String[] args) { DOMConfigurator.configure(EntryPoint.class.getClassLoader().getResource("pgptool-gui-log4j.xml")); log.info("EntryPoint first scream"); SplashScreenView splashScreenView = null; try { args = OsNativeApiResolver.resolve().getCommandLineArguments(args); if (!isContinueStartupSequence(args)) { System.exit(0); return; } UiUtils.setLookAndFeel(); splashScreenView = new SplashScreenView(); SwingPmSettings.setBindingContextFactory(new BindingContextFactoryImpl()); // Startup application context String[] contextPaths = new String[] { "app-context.xml" }; currentApplicationContext = new ClassPathXmlApplicationContext(contextPaths); log.debug("App context loaded"); LocaleContextHolder.setLocale(new Locale(System.getProperty("user.language"))); currentApplicationContext.registerShutdownHook(); log.debug("Shutdown hook registered"); // Now startup application logic EntryPoint entryPoint = currentApplicationContext.getBean(EntryPoint.class); usageLoggerStatic = currentApplicationContext.getBean(UsageLogger.class); log.debug("EntryPoint bean resolved"); prefetchKeys(); splashScreenView.close(); splashScreenView = null; entryPoint.startUp(args); rootPmStatic = entryPoint.getRootPm(); log.debug("RootPM bean resolved"); processPendingArgsIfAny(rootPmStatic); } catch (Throwable t) { log.error("Failed to startup application", t); reportAppInitFailureMessageToUser(determineWindowForGeneralFailure(splashScreenView), t); System.exit(-1); } finally { if (splashScreenView != null) { splashScreenView.close(); splashScreenView = null; } } }
Example 11
Source File: Main.java From Okra with Apache License 2.0 | 4 votes |
public static void main(String[] args) { // Spring ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("classpath:spring/beans.xml"); context.registerShutdownHook(); }
Example 12
Source File: CommandTest.java From Okra with Apache License 2.0 | 4 votes |
@Before public void setUp() throws Exception { ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("classpath:spring/beans.xml"); context.registerShutdownHook(); }