List of usage examples for org.springframework.context.support StaticApplicationContext registerSingleton
public void registerSingleton(String name, Class<?> clazz) throws BeansException
From source file:scriptella.driver.spring.EtlExecutorBean.java
/** * This method obtains a global ThreadLocal class independent of the classloader (JVM-scope singleton). * The easiest solution is to use System.getProperties().get/put, but this solution violate * Properties contract and have other drawbacks. * <p>Current solution relies on the idea behind * {@link org.springframework.beans.factory.access.SingletonBeanFactoryLocator}. See also bug #4648 * * @return Global ThreadLocal (JVM-scope singleton). *//*ww w. jav a 2s .co m*/ @SuppressWarnings("unchecked") private static ThreadLocal<BeanFactory> getGlobalThreadLocal() { BeanFactoryLocator locator = SingletonBeanFactoryLocator.getInstance(BEAN_FACTORY_XML_PATH); BeanFactoryReference ref = locator.useBeanFactory(FACTORY_BEAN_NAME); StaticApplicationContext ctx = (StaticApplicationContext) ref.getFactory(); if (!ctx.containsBean(THREAD_LOCAL_BEAN_NAME)) { ctx.registerSingleton(THREAD_LOCAL_BEAN_NAME, ThreadLocal.class); } return (ThreadLocal) ctx.getBean(THREAD_LOCAL_BEAN_NAME); }
From source file:de.itsvs.cwtrpc.controller.PreparedRemoteServiceConfigBuilderTest.java
@BeforeClass public static void initClass() { StaticApplicationContext appContext; appContext = new StaticApplicationContext(); appContext.registerSingleton("testService1", TestService1Impl.class); appContext.registerPrototype("testService2", TestService2Impl.class); appContext.registerSingleton("testService3", TestService3Impl.class); appContext.registerPrototype("testService4", TestService4Impl.class); appContext.registerSingleton("testService5", TestService5Impl.class); appContext.registerPrototype("testService10", TestService10Impl.class); appContext.registerSingleton("testService20", TestService20Impl.class); appContext.registerSingleton("rpcTokenValidatorXyz", TestRpcTokenValidator1Impl.class); appContext.registerSingleton("rpcTokenValidator100", TestRpcTokenValidator1Impl.class); appContext.registerSingleton("rpcTokenValidator200", TestRpcTokenValidator1Impl.class); appContext.registerSingleton("rpcTokenService", DefaultXsrfTokenService.class); PreparedRemoteServiceConfigBuilderTest.appContext = appContext; }
From source file:org.bonitasoft.web.designer.utils.TestWebMvcConfigurationSupport.java
public TestWebMvcConfigurationSupport(DesignerConfig config) { this.config = config; StaticApplicationContext applicationContext = new StaticApplicationContext(); applicationContext.registerSingleton("resourceControllerAdvice", ResourceControllerAdvice.class); setApplicationContext(applicationContext); }
From source file:org.jm.spring.controller.test.SpringMVCAPIReaderTest.java
@Before public void setUp() throws Exception { mapper = new ObjectMapper(); handler = new Handler(); StaticApplicationContext context = new StaticApplicationContext(); context.registerSingleton("handler", handler.getClass()); mapping = new RequestMappingHandlerMapping(); mapping.setApplicationContext(context); }
From source file:org.springframework.ws.transport.http.HttpComponentsMessageSenderIntegrationTest.java
@Test public void testContextClose() throws Exception { MessageFactory messageFactory = MessageFactory.newInstance(); int port = FreePortScanner.getFreePort(); Server jettyServer = new Server(port); Context jettyContext = new Context(jettyServer, "/"); jettyContext.addServlet(new ServletHolder(new EchoServlet()), "/"); jettyServer.start();//from w w w . j av a 2 s .co m WebServiceConnection connection = null; try { StaticApplicationContext appContext = new StaticApplicationContext(); appContext.registerSingleton("messageSender", HttpComponentsMessageSender.class); appContext.refresh(); HttpComponentsMessageSender messageSender = appContext.getBean("messageSender", HttpComponentsMessageSender.class); connection = messageSender.createConnection(new URI("http://localhost:" + port)); connection.send(new SaajSoapMessage(messageFactory.createMessage())); connection.receive(new SaajSoapMessageFactory(messageFactory)); appContext.close(); } finally { if (connection != null) { try { connection.close(); } catch (IOException ex) { // ignore } } if (jettyServer.isRunning()) { jettyServer.stop(); } } }
From source file:com.github.pjungermann.config.types.DefaultConfigFactorySelectorTest.java
@Test public void beanCreation_withSpringContextAndNoFactory_noErrorAndEmptyListAsDefault() { StaticApplicationContext context = new StaticApplicationContext(); context.registerSingleton(DefaultConfigFactorySelector.class.getName(), DefaultConfigFactorySelector.class); ConfigFactorySelector selector = context.getBean(ConfigFactorySelector.class); assertValidBean(selector);/*from w w w . j a va 2 s. c o m*/ }
From source file:com.urbanmania.spring.beans.factory.config.annotations.PropertyAnnotationAndPlaceholderConfigurerTest.java
@Test public void testProcessPropertiesAndUpdate() throws Exception { configurer.setPropertyLoaders(new MockPropertyLoader[] { new MockPropertyLoader(properties) }); GenericBeanDefinition beanDefinition = new GenericBeanDefinition(); beanDefinition.setBeanClass(UpdateableTestBean.class); beanFactory.registerBeanDefinition(TEST_BEAN_NAME, beanDefinition); properties.put(TEST_KEY, TEST_VALUE); configurer.loadProperties(properties); configurer.processProperties(beanFactory, properties); StaticApplicationContext context = new StaticApplicationContext(); context.registerSingleton(TEST_BEAN_NAME, UpdateableTestBean.class); configurer.setApplicationContext(context); configurer.setBeanFactory(beanFactory); configurer.propertyChanged(new PropertyEvent(this, TEST_KEY, TEST_CHANGED_VALUE)); assertEquals(TEST_CHANGED_VALUE, ((UpdateableTestBean) context.getBean(TEST_BEAN_NAME)).getProperty()); assertNull(System.getProperties().get(TEST_KEY)); }
From source file:com.urbanmania.spring.beans.factory.config.annotations.PropertyAnnotationAndPlaceholderConfigurerTest.java
@Test public void testProcessPropertiesConvertAndUpdate() throws Exception { configurer.setPropertyLoaders(new MockPropertyLoader[] { new MockPropertyLoader(properties) }); GenericBeanDefinition beanDefinition = new GenericBeanDefinition(); beanDefinition.setBeanClass(ConvertableTestBean.class); beanFactory.registerBeanDefinition(TEST_BEAN_NAME, beanDefinition); properties.put(TEST_KEY, "1"); configurer.loadProperties(properties); configurer.processProperties(beanFactory, properties); StaticApplicationContext context = new StaticApplicationContext(); context.registerSingleton(TEST_BEAN_NAME, ConvertableTestBean.class); configurer.setApplicationContext(context); configurer.setBeanFactory(beanFactory); configurer.propertyChanged(new PropertyEvent(this, TEST_KEY, "2")); assertEquals(2, ((ConvertableTestBean) context.getBean(TEST_BEAN_NAME)).getProperty()); assertNull(System.getProperties().get(TEST_KEY)); }
From source file:de.itsvs.cwtrpc.controller.AutowiredRemoteServiceGroupConfigTest.java
@Test public void testAfterPropertiesSet2() { final StaticApplicationContext appContext; final AutowiredRemoteServiceGroupConfig config; appContext = new StaticApplicationContext(); appContext.registerSingleton("testService1", TestService1Impl.class); config = new AutowiredRemoteServiceGroupConfig(); config.setBasePackages(Arrays.asList(new String[] { "de.itsvs.cwtrpc.controller.config." })); config.setApplicationContext(appContext); config.afterPropertiesSet();//from w w w . jav a 2s . c om Assert.assertTrue(config.getChildGroupConfigs().isEmpty()); Assert.assertEquals(1, config.getServiceConfigs().size()); }
From source file:de.itsvs.cwtrpc.controller.AutowiredRemoteServiceGroupConfigTest.java
@Test public void testAfterPropertiesSet3() { final StaticApplicationContext appContext; final AutowiredRemoteServiceGroupConfig config; appContext = new StaticApplicationContext(); appContext.registerSingleton("testService1", TestService1Impl.class); config = new AutowiredRemoteServiceGroupConfig(); config.setBasePackages(Arrays.asList(new String[] { "de.itsvs.cwtrpc.controller.config2." })); config.setApplicationContext(appContext); config.afterPropertiesSet();//from w ww . j a v a2 s.c o m Assert.assertTrue(config.getChildGroupConfigs().isEmpty()); Assert.assertEquals(0, config.getServiceConfigs().size()); }