List of usage examples for org.springframework.beans.factory.config AutowireCapableBeanFactory AUTOWIRE_AUTODETECT
int AUTOWIRE_AUTODETECT
To view the source code for org.springframework.beans.factory.config AutowireCapableBeanFactory AUTOWIRE_AUTODETECT.
Click Source Link
From source file:com.opensymphony.xwork2.spring.SpringObjectFactory.java
/** * Sets the autowiring strategy/*from w w w . j a v a 2s . co m*/ * * @param autowireStrategy the autowire strategy */ public void setAutowireStrategy(int autowireStrategy) { switch (autowireStrategy) { case AutowireCapableBeanFactory.AUTOWIRE_AUTODETECT: LOG.info("Setting autowire strategy to autodetect"); this.autowireStrategy = autowireStrategy; break; case AutowireCapableBeanFactory.AUTOWIRE_BY_NAME: LOG.info("Setting autowire strategy to name"); this.autowireStrategy = autowireStrategy; break; case AutowireCapableBeanFactory.AUTOWIRE_BY_TYPE: LOG.info("Setting autowire strategy to type"); this.autowireStrategy = autowireStrategy; break; case AutowireCapableBeanFactory.AUTOWIRE_CONSTRUCTOR: LOG.info("Setting autowire strategy to constructor"); this.autowireStrategy = autowireStrategy; break; case AutowireCapableBeanFactory.AUTOWIRE_NO: LOG.info("Setting autowire strategy to none"); this.autowireStrategy = autowireStrategy; break; default: throw new IllegalStateException("Invalid autowire type set"); } }
From source file:net.vitarara.groovyworks.GroovyStrutsSpringObjectFactory.java
@Inject public void setServletContext(ServletContext servletContext) { log.info("Groovy Spring Plugin: Initializing"); // Create the Groovy classloader and make it a child of the current thread's class loader. CompilerConfiguration cc = new CompilerConfiguration(); cc.setRecompileGroovySource(true);//from w w w . j a v a2 s .co m gcl = new GroovyClassLoader(Thread.currentThread().getContextClassLoader(), cc); gcl.setShouldRecompile(true); // gcl = new GroovyClassLoader (Thread.currentThread().getContextClassLoader () ); // gcl.setShouldRecompile (false); log.info("GroovyClassLoader recompilation set to: " + gcl.isShouldRecompile()); log.info("Initializing Struts-Spring integration..."); ApplicationContext appContext = WebApplicationContextUtils.getWebApplicationContext(servletContext); if (appContext == null) { // uh oh! looks like the lifecycle listener wasn't installed. Let's inform the user String message = "********** FATAL ERROR STARTING UP SPRING-STRUTS INTEGRATION **********\n" + "Looks like the Spring listener was not configured for your web app! \n" + "Nothing will work until WebApplicationContextUtils returns a valid ApplicationContext.\n" + "You might need to add the following to web.xml: \n" + " <listener>\n" + " <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>\n" + " </listener>"; log.fatal(message); return; } this.setApplicationContext(appContext); int type = AutowireCapableBeanFactory.AUTOWIRE_BY_NAME; // default if ("name".equals(autoWire)) { type = AutowireCapableBeanFactory.AUTOWIRE_BY_NAME; } else if ("type".equals(autoWire)) { type = AutowireCapableBeanFactory.AUTOWIRE_BY_TYPE; } else if ("auto".equals(autoWire)) { type = AutowireCapableBeanFactory.AUTOWIRE_AUTODETECT; } else if ("constructor".equals(autoWire)) { type = AutowireCapableBeanFactory.AUTOWIRE_CONSTRUCTOR; } this.setAutowireStrategy(type); this.setUseClassCache(useClassCache); log.info("... initialized Struts-Spring integration successfully"); // Set the appContext's class loader to the GroovyClassLoader. The refresh the context. // ((org.springframework.core.io.DefaultResourceLoader) appContext).setClassLoader (gcl); // ((ConfigurableWebApplicationContext) appContext).refresh (); log.info("Groovy Spring Plugin: Initialization complete"); }
From source file:org.apache.james.container.spring.bean.factory.protocols.ProtocolHandlerLoaderBeanFactory.java
@SuppressWarnings("unchecked") @Override//from w w w .j a va 2 s. c om public ProtocolHandler load(String name, Configuration config) throws LoadingException { try { // Use the classloader which is used for bean instance stuff Class<ProtocolHandler> c = (Class<ProtocolHandler>) getBeanFactory().getBeanClassLoader() .loadClass(name); @SuppressWarnings("deprecation") ProtocolHandler handler = (ProtocolHandler) getBeanFactory().createBean(c, AutowireCapableBeanFactory.AUTOWIRE_AUTODETECT, true); handler.init(config); return handler; } catch (ClassNotFoundException e) { throw new LoadingException("Unable to load handler", e); } catch (BeansException e) { throw new LoadingException("Unable to load handler", e); } catch (ConfigurationException e) { throw new LoadingException("Unable to load handler", e); } }
From source file:org.apache.struts2.spring.StrutsSpringObjectFactory.java
/** * Constructs the spring object factory//from www . j a v a 2s .co m * @param autoWire The type of autowiring to use * @param alwaysAutoWire Whether to always respect the autowiring or not * @param useClassCacheStr Whether to use the class cache or not * @param servletContext The servlet context * @since 2.1.3 */ @Inject public StrutsSpringObjectFactory( @Inject(value = StrutsConstants.STRUTS_OBJECTFACTORY_SPRING_AUTOWIRE, required = false) String autoWire, @Inject(value = StrutsConstants.STRUTS_OBJECTFACTORY_SPRING_AUTOWIRE_ALWAYS_RESPECT, required = false) String alwaysAutoWire, @Inject(value = StrutsConstants.STRUTS_OBJECTFACTORY_SPRING_USE_CLASS_CACHE, required = false) String useClassCacheStr, @Inject ServletContext servletContext, @Inject(StrutsConstants.STRUTS_DEVMODE) String devMode, @Inject Container container) { super(); boolean useClassCache = "true".equals(useClassCacheStr); if (LOG.isInfoEnabled()) { LOG.info("Initializing Struts-Spring integration..."); } Object rootWebApplicationContext = servletContext .getAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE); if (rootWebApplicationContext instanceof RuntimeException) { RuntimeException runtimeException = (RuntimeException) rootWebApplicationContext; LOG.fatal(runtimeException.getMessage()); return; } ApplicationContext appContext = (ApplicationContext) rootWebApplicationContext; if (appContext == null) { // uh oh! looks like the lifecycle listener wasn't installed. Let's inform the user String message = "********** FATAL ERROR STARTING UP STRUTS-SPRING INTEGRATION **********\n" + "Looks like the Spring listener was not configured for your web app! \n" + "Nothing will work until WebApplicationContextUtils returns a valid ApplicationContext.\n" + "You might need to add the following to web.xml: \n" + " <listener>\n" + " <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>\n" + " </listener>"; LOG.fatal(message); return; } String watchList = container.getInstance(String.class, "struts.class.reloading.watchList"); String acceptClasses = container.getInstance(String.class, "struts.class.reloading.acceptClasses"); String reloadConfig = container.getInstance(String.class, "struts.class.reloading.reloadConfig"); if ("true".equals(devMode) && StringUtils.isNotBlank(watchList) && appContext instanceof ClassReloadingXMLWebApplicationContext) { //prevent class caching useClassCache = false; ClassReloadingXMLWebApplicationContext reloadingContext = (ClassReloadingXMLWebApplicationContext) appContext; reloadingContext.setupReloading(watchList.split(","), acceptClasses, servletContext, "true".equals(reloadConfig)); if (LOG.isInfoEnabled()) { LOG.info("Class reloading is enabled. Make sure this is not used on a production environment!", watchList); } setClassLoader(reloadingContext.getReloadingClassLoader()); //we need to reload the context, so our isntance of the factory is picked up reloadingContext.refresh(); } this.setApplicationContext(appContext); int type = AutowireCapableBeanFactory.AUTOWIRE_BY_NAME; // default if ("name".equals(autoWire)) { type = AutowireCapableBeanFactory.AUTOWIRE_BY_NAME; } else if ("type".equals(autoWire)) { type = AutowireCapableBeanFactory.AUTOWIRE_BY_TYPE; } else if ("auto".equals(autoWire)) { type = AutowireCapableBeanFactory.AUTOWIRE_AUTODETECT; } else if ("constructor".equals(autoWire)) { type = AutowireCapableBeanFactory.AUTOWIRE_CONSTRUCTOR; } else if ("no".equals(autoWire)) { type = AutowireCapableBeanFactory.AUTOWIRE_NO; } this.setAutowireStrategy(type); this.setUseClassCache(useClassCache); this.setAlwaysRespectAutowireStrategy("true".equalsIgnoreCase(alwaysAutoWire)); if (LOG.isInfoEnabled()) { LOG.info("... initialized Struts-Spring integration successfully"); } }