Spring Framework GenericApplicationContext - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Spring Framework GenericApplicationContext class.

This code example shows how to use the following methods:registerBeanDefinition, refresh
 */ 
public class DuplicateConfigurationClassPostProcessorTests { 
 
	@Test
	public void repro() { 
		GenericApplicationContext ctx = new GenericApplicationContext();
		ctx.registerBeanDefinition("a", new RootBeanDefinition(ConfigurationClassPostProcessor.class));
		ctx.registerBeanDefinition("b", new RootBeanDefinition(ConfigurationClassPostProcessor.class));
		ctx.registerBeanDefinition("myConfig", new RootBeanDefinition(Config.class));
		ctx.refresh();
	} 
 
	@Configuration 
	static class Config { 
		@Bean 
		public String string() {
			return "bean"; 
		} 
	} 
} 
8
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:registerBeanDefinition, close, getBean, refresh
		context.close();
	} 
 
	@Test
	public void testBeanNameWithParentBeanDefinition() throws Exception {
		GenericApplicationContext context = new GenericApplicationContext();
		ConstructorArgumentValues args = new ConstructorArgumentValues();
		args.addGenericArgumentValue("bar");
		context.registerBeanDefinition("parent", new RootBeanDefinition(
				JobSupport.class, args, null));
		context.registerBeanDefinition("bean", new ChildBeanDefinition("parent"));
		context.refresh();
		JobSupport configuration = (JobSupport) context
				.getBean("bean");
		assertNotNull(configuration.getName());
		assertEquals("bar", configuration.getName());
		configuration.setBeanName("foo");
		assertEquals("bar", configuration.getName());
		configuration.setName("foo");
		assertEquals("foo", configuration.getName());

8
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:getBeanFactory, getBean, refresh
		assertTrue(simpleMap instanceof HashMap);
	} 
 
	@Test
	public void testScopedOverride() throws Exception {
		GenericApplicationContext ctx = new GenericApplicationContext();
		new XmlBeanDefinitionReader(ctx).loadBeanDefinitions(OVERRIDE_CONTEXT);
		SimpleMapScope scope = new SimpleMapScope();
		ctx.getBeanFactory().registerScope("request", scope);
		ctx.refresh();
 
		ITestBean bean = (ITestBean) ctx.getBean("testBean");
		assertEquals("male", bean.getName());
		assertEquals(99, bean.getAge());
 
		assertTrue(scope.getMap().containsKey("scopedTarget.testBean"));
		assertEquals(TestBean.class, scope.getMap().get("scopedTarget.testBean").getClass());
	} 
 
	@Test
8
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:registerBeanDefinition, getBean, refresh
 
@SuppressWarnings("resource") 
public class PropertyPlaceholderConfigurerEnvironmentIntegrationTests { 
	@Test
	public void test() { 
		GenericApplicationContext ctx = new GenericApplicationContext();
		ctx.registerBeanDefinition("ppc",
				rootBeanDefinition(PropertyPlaceholderConfigurer.class)
				.addPropertyValue("searchSystemEnvironment", false)
				.getBeanDefinition());
		ctx.refresh();
		ctx.getBean("ppc");
	} 
} 
8
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:refresh, registerShutdownHook, getDefaultListableBeanFactory
	public final ConfigurableApplicationContext loadContext(String... locations) throws Exception {
		if (logger.isDebugEnabled()) {
			logger.debug(String.format("Loading ApplicationContext for locations [%s].",
				StringUtils.arrayToCommaDelimitedString(locations)));
		} 
		GenericApplicationContext context = new GenericApplicationContext();
		prepareContext(context);
		customizeBeanFactory(context.getDefaultListableBeanFactory());
		createBeanDefinitionReader(context).loadBeanDefinitions(locations);
		AnnotationConfigUtils.registerAnnotationConfigProcessors(context);
		customizeContext(context);
		context.refresh();
		context.registerShutdownHook();
		return context;
	} 
 
	/** 
	 * Prepare the {@link GenericApplicationContext} created by this {@code ContextLoader}. 
	 * Called <i>before</i> bean definitions are read. 
	 * 
7
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:getDefaultListableBeanFactory, refresh
			throw ex;
		} 
	} 
 
	protected ConfigurableApplicationContext loadContext(String configLocation) {
		GenericApplicationContext ctx = new GenericApplicationContext();
		new XmlBeanDefinitionReader(ctx).loadBeanDefinitions(configLocation);
		ctx.getDefaultListableBeanFactory().registerSingleton("server", this.server);
		ctx.refresh();
		return ctx;
	} 
 
	@After 
	public void tearDown() throws Exception {
		releaseServer(); 
		onTearDown(); 
	} 
 
	private void releaseServer() throws Exception {
		MBeanServerFactory.releaseMBeanServer(getServer());
7
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:registerBeanDefinition, refresh
 */ 
public class BeanValidationPostProcessorTests { 
 
	@Test
	public void testNotNullConstraint() { 
		GenericApplicationContext ac = new GenericApplicationContext();
		ac.registerBeanDefinition("bvpp", new RootBeanDefinition(BeanValidationPostProcessor.class));
		ac.registerBeanDefinition("capp", new RootBeanDefinition(CommonAnnotationBeanPostProcessor.class));
		ac.registerBeanDefinition("bean", new RootBeanDefinition(NotNullConstrainedBean.class));
		try { 
			ac.refresh();
			fail("Should have thrown BeanCreationException"); 
		} 
		catch (BeanCreationException ex) {
			assertTrue(ex.getRootCause().getMessage().contains("testBean"));
			assertTrue(ex.getRootCause().getMessage().contains("invalid"));
		} 
	} 
 
	@Test
8
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:getBeanFactory, refresh
 
 
	@Before 
	public void setup() throws Exception {
		@SuppressWarnings("resource") 
		GenericApplicationContext cxt = new GenericApplicationContext();
		cxt.refresh();
		this.resolver = new HeaderMethodArgumentResolver(new DefaultConversionService(), cxt.getBeanFactory());
 
		Method method = getClass().getDeclaredMethod("handleMessage",
				String.class, String.class, String.class, String.class, String.class);
		this.paramRequired = new MethodParameter(method, 0);
		this.paramNamedDefaultValueStringHeader = new MethodParameter(method, 1);
		this.paramSystemProperty = new MethodParameter(method, 2);
		this.paramNotAnnotated = new MethodParameter(method, 3);
		this.paramNativeHeader = new MethodParameter(method, 4);
 
		this.paramRequired.initParameterNameDiscovery(new DefaultParameterNameDiscoverer());
		GenericTypeResolver.resolveParameterType(this.paramRequired, HeaderMethodArgumentResolver.class);
	} 
7
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:registerBeanDefinition, getBean, refresh
     * 
     * @return ApplicationContext a parent {@link ApplicationContext} configured 
     *         to exclude certain classes from package scanning 
     */ 
    protected ApplicationContext getRouteExcludingApplicationContext() {
        GenericApplicationContext routeExcludingContext = new GenericApplicationContext();
        routeExcludingContext.registerBeanDefinition("excludingResolver", new RootBeanDefinition(ExcludingPackageScanClassResolver.class));
        routeExcludingContext.refresh();
 
        ExcludingPackageScanClassResolver excludingResolver = routeExcludingContext.getBean("excludingResolver", ExcludingPackageScanClassResolver.class);
        List<Class<?>> excluded = Arrays.asList(excludeRoutes());
        excludingResolver.setExcludedClasses(new HashSet<Class<?>>(excluded));
 
        return routeExcludingContext;
    } 
 
    /** 
     * Template method used to exclude {@link org.apache.camel.Route} from the test time context 
     * route scanning 
     * 
7
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:getBeanFactory
 
	@Test
	public void testNoFailOnStartupWithMissingBroker() throws Exception {
		SingleConnectionFactory connectionFactory = new SingleConnectionFactory("foo");
		connectionFactory.setPort(434343);
		GenericApplicationContext applicationContext = new GenericApplicationContext();
		applicationContext.getBeanFactory().registerSingleton("foo", new Queue("queue"));
		RabbitAdmin rabbitAdmin = new RabbitAdmin(connectionFactory);
		rabbitAdmin.setApplicationContext(applicationContext);
		rabbitAdmin.setAutoStartup(true);
		rabbitAdmin.afterPropertiesSet();
		connectionFactory.destroy();
	} 
 
	@Test
	public void testFailOnFirstUseWithMissingBroker() throws Exception {
		SingleConnectionFactory connectionFactory = new SingleConnectionFactory("foo");
		connectionFactory.setPort(434343);
		GenericApplicationContext applicationContext = new GenericApplicationContext();
		applicationContext.getBeanFactory().registerSingleton("foo", new Queue("queue"));
6
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
See Code Examples for Spring Framework GenericApplicationContext Methods: