logger.debug("Root context path: {}", applicationContext.getServletContext().getContextPath()); ConfigurableBeanFactory factory = applicationContext.getBeanFactory();
ConfigurableBeanFactory factory = applicationContext.getBeanFactory();
public void registerSubContext(String webAppKey) { // get the sub contexts - servlet context ServletContext ctx = servletContext.getContext(webAppKey); if (ctx == null) { ctx = servletContext; } ContextLoader loader = new ContextLoader(); ConfigurableWebApplicationContext appCtx = (ConfigurableWebApplicationContext) loader.initWebApplicationContext(ctx); appCtx.setParent(applicationContext); appCtx.refresh(); ctx.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, appCtx); ConfigurableBeanFactory appFactory = appCtx.getBeanFactory(); logger.debug("About to grab Webcontext bean for {}", webAppKey); Context webContext = (Context) appCtx.getBean("web.context"); webContext.setCoreBeanFactory(parentFactory); webContext.setClientRegistry(clientRegistry); webContext.setServiceInvoker(globalInvoker); webContext.setScopeResolver(globalResolver); webContext.setMappingStrategy(globalStrategy); WebScope scope = (WebScope) appFactory.getBean("web.scope"); scope.setServer(server); scope.setParent(global); scope.register(); scope.start(); // register the context so we dont try to reinitialize it registeredContexts.add(ctx); }
public void autowire() { this.context.setServletContext(new MockServletContext()); this.context.setServletConfig(new MockServletConfig()); this.context.refresh(); if (this.context.containsBean(SPRING_SECURITY_FILTER_CHAIN)) { MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(this.context) .apply(springSecurity()) .apply(new AddFilter()).build(); this.context.getBeanFactory() .registerResolvableDependency(MockMvc.class, mockMvc); } AutowiredAnnotationBeanPostProcessor bpp = new AutowiredAnnotationBeanPostProcessor(); bpp.setBeanFactory(this.context.getBeanFactory()); bpp.processInjection(this.test); }
propertyValues.addPropertyValue(new PropertyValue("resourceLoaderPath", "/")); beanDefinition.setPropertyValues(propertyValues); ((BeanDefinitionRegistry) getApplicationContext().getBeanFactory()) .registerBeanDefinition("velocityConfigurer", beanDefinition); logger.info("registered bean definition named" + " velocityConfigurer: " ((BeanDefinitionRegistry) getApplicationContext().getBeanFactory()).registerBeanDefinition( beanName, beanDefinition); logger.info("registered bean definition named " + beanName + ": "
protected ViewResolver getJspViewResolver() throws IOException { if (this.jspViewResolver != null) { return this.jspViewResolver; } String beanName = "jspViewResolver"; this.jspViewResolver = (ViewResolver) SpringUtils .getBean(getApplicationContext(), beanName); if (jspViewResolver == null) { GenericBeanDefinition beanDefinition = new GenericBeanDefinition(); beanDefinition.setBeanClass(InternalResourceViewResolver.class); MutablePropertyValues propertyValues = new MutablePropertyValues(); propertyValues.addPropertyValue(new PropertyValue("viewClass", JstlView.class)); beanDefinition.setPropertyValues(propertyValues); ((BeanDefinitionRegistry) getApplicationContext().getBeanFactory()) .registerBeanDefinition(beanName, beanDefinition); logger.info("registered bean definition named " + beanName + ": " + InternalResourceViewResolver.class.getName()); jspViewResolver = (ViewResolver) SpringUtils.getBean(getApplicationContext(), beanName); } return this.jspViewResolver; }
@Override public synchronized ConfigurableListableBeanFactory getBeanFactory() throws IllegalStateException { return this.appContext.getBeanFactory(); }
@Autowired ConfigurableWebApplicationContext applicationContext; ... applicationContext.getBeanFactory().getBeanDefinition("beanName").getScope()
public <T> T instanceFor(Class<T> type) { try { return parentContext.getBean(type); } catch (NoSuchBeanDefinitionException e) { Map<String, T> beans = parentContext.getBeansOfType(type); for (Entry<String, T> def : beans.entrySet()) { BeanDefinition definition = parentContext.getBeanFactory().getBeanDefinition(def.getKey()); if (isPrimary(definition) || hasGreaterRoleThanInfrastructure(definition)) { return def.getValue(); } } throw e; } }
public void register(Class<?> requiredType, Class<?> componentType) { if (parentContext.isActive() && "VRaptor".equals(parentContext.getId())) { logger.info("registering class {} to {} after container initialization. Please avoid this", requiredType, componentType); new SpringRegistry(parentContext.getBeanFactory(), this).register(componentType); } else { toRegister.add(componentType); } }
propertyValues.addPropertyValue(new PropertyValue("resourceLoaderPath", "/")); beanDefinition.setPropertyValues(propertyValues); ((BeanDefinitionRegistry) getApplicationContext().getBeanFactory()) .registerBeanDefinition("velocityConfigurer", beanDefinition); logger.info("registered bean definition named" + " velocityConfigurer: " ((BeanDefinitionRegistry) getApplicationContext().getBeanFactory()).registerBeanDefinition( beanName, beanDefinition); logger.info("registered bean definition named " + beanName + ": "
protected ViewResolver getJspViewResolver() throws IOException { if (this.jspViewResolver != null) { return this.jspViewResolver; } String beanName = "jspViewResolver"; this.jspViewResolver = (ViewResolver) SpringUtils .getBean(getApplicationContext(), beanName); if (jspViewResolver == null) { GenericBeanDefinition beanDefinition = new GenericBeanDefinition(); beanDefinition.setBeanClass(InternalResourceViewResolver.class); MutablePropertyValues propertyValues = new MutablePropertyValues(); propertyValues.addPropertyValue(new PropertyValue("viewClass", JstlView.class)); beanDefinition.setPropertyValues(propertyValues); ((BeanDefinitionRegistry) getApplicationContext().getBeanFactory()) .registerBeanDefinition(beanName, beanDefinition); logger.info("registered bean definition named " + beanName + ": " + InternalResourceViewResolver.class.getName()); jspViewResolver = (ViewResolver) SpringUtils.getBean(getApplicationContext(), beanName); } return this.jspViewResolver; }
expect(ac.getBeanFactory()).andReturn(beanFactory); expect(ac.getBeanDefinitionNames()).andReturn(new String[] { "fred", "&barney", "arnold" });