List of usage examples for org.springframework.web.context WebApplicationContext getAutowireCapableBeanFactory
AutowireCapableBeanFactory getAutowireCapableBeanFactory() throws IllegalStateException;
From source file:org.lightadmin.core.config.bootstrap.LightAdminBeanDefinitionRegistryPostProcessor.java
private Set<ConfigurationUnits> configurationUnits(WebApplicationContext rootContext, Set<Class> administrationConfigs) { Set<ConfigurationUnits> configurationUnitsCollection = newLinkedHashSet(); for (Class administrationConfig : administrationConfigs) { ConfigurationUnits configurationUnits = unitsFromAutowiredConfiguration(administrationConfig, rootContext.getAutowireCapableBeanFactory()); configurationUnitsCollection.add(configurationUnits); }//from w ww . j ava 2 s . com return configurationUnitsCollection; }
From source file:com.laxser.blitz.web.instruction.ViewInstruction.java
/** * {@link ViewDispatcher}/*w w w.j a v a 2 s . c o m*/ * * @return */ protected ViewDispatcher registerViewDispatcher(WebApplicationContext applicationContext) { // ??????? synchronized (applicationContext) { if (SpringUtils.getBean(applicationContext, viewDispatcherName) == null) { GenericBeanDefinition beanDefinition = new AnnotatedGenericBeanDefinition(ViewDispatcherImpl.class); ((BeanDefinitionRegistry) applicationContext.getAutowireCapableBeanFactory()) .registerBeanDefinition(viewDispatcherName, beanDefinition); if (logger.isDebugEnabled()) { logger.debug("registered bean definition:" + ViewDispatcherImpl.class.getName()); } } return (ViewDispatcher) SpringUtils.getBean(applicationContext, viewDispatcherName); } }
From source file:org.codehaus.groovy.grails.web.context.GrailsConfigUtils.java
/** * Executes Grails bootstrap classes//from www . j a va 2 s . co m * * @param application The Grails ApplicationContext instance * @param webContext The WebApplicationContext instance * @param servletContext The ServletContext instance */ public static void executeGrailsBootstraps(GrailsApplication application, WebApplicationContext webContext, ServletContext servletContext) { PersistenceContextInterceptor interceptor = null; String[] beanNames = webContext.getBeanNamesForType(PersistenceContextInterceptor.class); if (beanNames.length > 0) { interceptor = (PersistenceContextInterceptor) webContext.getBean(beanNames[0]); } if (interceptor != null) { interceptor.init(); } // init the Grails application try { GrailsClass[] bootstraps = application.getArtefacts(BootstrapArtefactHandler.TYPE); for (GrailsClass bootstrap : bootstraps) { final GrailsBootstrapClass bootstrapClass = (GrailsBootstrapClass) bootstrap; final Object instance = bootstrapClass.getReferenceInstance(); webContext.getAutowireCapableBeanFactory().autowireBeanProperties(instance, AutowireCapableBeanFactory.AUTOWIRE_BY_NAME, false); bootstrapClass.callInit(servletContext); } if (interceptor != null) { interceptor.flush(); } } finally { if (interceptor != null) { interceptor.destroy(); } } }
From source file:org.codehaus.groovy.grails.web.pages.GroovyPagesServlet.java
@Override protected void initFrameworkServlet() throws ServletException, BeansException { context = getServletContext();/*from w ww . j a v a2 s . c o m*/ context.log("GSP servlet initialized"); context.setAttribute(SERVLET_INSTANCE, this); final WebApplicationContext webApplicationContext = getWebApplicationContext(); grailsAttributes = new DefaultGrailsApplicationAttributes(context); webApplicationContext.getAutowireCapableBeanFactory().autowireBeanProperties(this, AutowireCapableBeanFactory.AUTOWIRE_BY_TYPE, false); groovyPagesTemplateEngine = webApplicationContext.getBean(GroovyPagesTemplateEngine.BEAN_ID, GroovyPagesTemplateEngine.class); }
From source file:org.projectforge.business.user.filter.UserFilter.java
@Override public void init(final FilterConfig filterConfig) throws ServletException { WebApplicationContext springContext = WebApplicationContextUtils .getRequiredWebApplicationContext(filterConfig.getServletContext()); final AutowireCapableBeanFactory beanFactory = springContext.getAutowireCapableBeanFactory(); beanFactory.autowireBean(this); CONTEXT_PATH = filterConfig.getServletContext().getContextPath(); WICKET_PAGES_PREFIX = CONTEXT_PATH + "/" + Const.WICKET_APPLICATION_PATH; // IGNORE_PREFIX_WICKET = WICKET_PAGES_PREFIX + "resources"; // IGNORE_PREFIX_DOC = contextPath + "/secure/doc"; // IGNORE_PREFIX_SITE_DOC = contextPath + "/secure/site"; IGNORE_PREFIX_LOGO = CONTEXT_PATH + "/" + LogoServlet.BASE_URL; IGNORE_PREFIX_SMS_REVEIVE_SERVLET = CONTEXT_PATH + "/" + SMSReceiverServlet.URL; }
From source file:org.springframework.web.context.support.SpringBeanAutowiringSupport.java
/** * Process {@code @Autowired} injection for the given target object, * based on the current web application context. * <p>Intended for use as a delegate. * @param target the target object to process * @see org.springframework.web.context.ContextLoader#getCurrentWebApplicationContext() *//*from w w w. j a va2s.c om*/ public static void processInjectionBasedOnCurrentContext(Object target) { Assert.notNull(target, "Target object must not be null"); WebApplicationContext cc = ContextLoader.getCurrentWebApplicationContext(); if (cc != null) { AutowiredAnnotationBeanPostProcessor bpp = new AutowiredAnnotationBeanPostProcessor(); bpp.setBeanFactory(cc.getAutowireCapableBeanFactory()); bpp.processInjection(target); } else { if (logger.isDebugEnabled()) { logger.debug("Current WebApplicationContext is not available for processing of " + ClassUtils.getShortName(target.getClass()) + ": " + "Make sure this class gets constructed in a Spring web application. Proceeding without injection."); } } }
From source file:org.springframework.web.context.support.SpringBeanAutowiringSupport.java
/** * Process {@code @Autowired} injection for the given target object, * based on the current root web application context as stored in the ServletContext. * <p>Intended for use as a delegate. * @param target the target object to process * @param servletContext the ServletContext to find the Spring web application context in * @see WebApplicationContextUtils#getWebApplicationContext(javax.servlet.ServletContext) *//*from w ww . j a va2 s.c o m*/ public static void processInjectionBasedOnServletContext(Object target, ServletContext servletContext) { Assert.notNull(target, "Target object must not be null"); WebApplicationContext cc = WebApplicationContextUtils.getRequiredWebApplicationContext(servletContext); AutowiredAnnotationBeanPostProcessor bpp = new AutowiredAnnotationBeanPostProcessor(); bpp.setBeanFactory(cc.getAutowireCapableBeanFactory()); bpp.processInjection(target); }
From source file:org.springframework.web.socket.server.endpoint.SpringConfigurator.java
@Override public <T> T getEndpointInstance(Class<T> endpointClass) throws InstantiationException { WebApplicationContext wac = ContextLoader.getCurrentWebApplicationContext(); if (wac == null) { String message = "Failed to find the root WebApplicationContext. Was ContextLoaderListener not used?"; logger.error(message);//from ww w. j a v a 2 s. com throw new IllegalStateException(message); } Map<String, T> beans = wac.getBeansOfType(endpointClass); if (beans.isEmpty()) { if (logger.isTraceEnabled()) { logger.trace("Creating new @ServerEndpoint instance of type " + endpointClass); } return wac.getAutowireCapableBeanFactory().createBean(endpointClass); } else if (beans.size() == 1) { if (logger.isTraceEnabled()) { logger.trace("Using @ServerEndpoint singleton " + beans.keySet().iterator().next()); } return beans.values().iterator().next(); } else { // Should not happen .. String message = "Found more than one matching @ServerEndpoint beans of type " + endpointClass; logger.error(message); throw new IllegalStateException(message); } }
From source file:org.springframework.web.socket.server.standard.SpringConfigurator.java
@SuppressWarnings("unchecked") @Override//ww w.j a va 2s. c o m public <T> T getEndpointInstance(Class<T> endpointClass) throws InstantiationException { WebApplicationContext wac = ContextLoader.getCurrentWebApplicationContext(); if (wac == null) { String message = "Failed to find the root WebApplicationContext. Was ContextLoaderListener not used?"; logger.error(message); throw new IllegalStateException(message); } String beanName = ClassUtils.getShortNameAsProperty(endpointClass); if (wac.containsBean(beanName)) { T endpoint = wac.getBean(beanName, endpointClass); if (logger.isTraceEnabled()) { logger.trace("Using @ServerEndpoint singleton " + endpoint); } return endpoint; } Component ann = AnnotationUtils.findAnnotation(endpointClass, Component.class); if (ann != null && wac.containsBean(ann.value())) { T endpoint = wac.getBean(ann.value(), endpointClass); if (logger.isTraceEnabled()) { logger.trace("Using @ServerEndpoint singleton " + endpoint); } return endpoint; } beanName = getBeanNameByType(wac, endpointClass); if (beanName != null) { return (T) wac.getBean(beanName); } if (logger.isTraceEnabled()) { logger.trace("Creating new @ServerEndpoint instance of type " + endpointClass); } return wac.getAutowireCapableBeanFactory().createBean(endpointClass); }