List of usage examples for org.springframework.beans.factory.config AutowireCapableBeanFactory AUTOWIRE_NO
int AUTOWIRE_NO
To view the source code for org.springframework.beans.factory.config AutowireCapableBeanFactory AUTOWIRE_NO.
Click Source Link
From source file:com.zenika.stripes.contrib.spring.SpringRuntimeConfiguration.java
/** * Splits a comma-separated list of class names and maps each {@link LifecycleStage} to the * interceptors in the list that intercept it. Also automatically finds Interceptors in * packages listed in {@link BootstrapPropertyResolver#PACKAGES} if searchExtensionPackages is true. * //from www . j av a2 s.c o m * Interceptors are instancied from the Spring factory AutowireCapableBeanFactory. * @see <a href="http://grepcode.com/file/repo1.maven.org/maven2/org.springframework/spring-beans/3.0.2.RELEASE/org/springframework/beans/factory/support/AbstractAutowireCapableBeanFactory.java#AbstractAutowireCapableBeanFactory.createBean%28java.lang.Class%29">createBean code</a> * * @return a Map of {@link LifecycleStage} to Collection of {@link Interceptor} */ @Override protected Map<LifecycleStage, Collection<Interceptor>> initInterceptors(List classes) { Map<LifecycleStage, Collection<Interceptor>> map = new HashMap<LifecycleStage, Collection<Interceptor>>(); for (Object type : classes) { try { ServletContext servletContext = getServletContext(); ApplicationContext applicationContext = WebApplicationContextUtils .getWebApplicationContext(servletContext); AutowireCapableBeanFactory beanFactory = applicationContext.getAutowireCapableBeanFactory(); Interceptor interceptor = (Interceptor) beanFactory.createBean((Class) type, AutowireCapableBeanFactory.AUTOWIRE_NO, false); addInterceptor(map, interceptor); } catch (Exception e) { throw new StripesRuntimeException( "Could not instantiate configured Interceptor [" + type.getClass().getName() + "].", e); } } return map; }
From source file:org.jboss.arquillian.spring.integration.enricher.AbstractSpringInjectionEnricher.java
/** * <p>Injects dependencies into the test case.</p> * * @param applicationContext the {@link org.springframework.context.ApplicationContext} * @param testCase the test case for which the beans will be injected *//*from w w w .ja v a 2 s.co m*/ private void injectDependencies(ApplicationContext applicationContext, Object testCase) { // for applications that do not contain Annotation post processors, create new // application context with those and create test class from that context StaticApplicationContext staticContext = new StaticApplicationContext(applicationContext); AnnotationConfigUtils.registerAnnotationConfigProcessors(staticContext); staticContext.refresh(); // retrieves the bean factory AutowireCapableBeanFactory beanFactory = staticContext.getAutowireCapableBeanFactory(); // injects all the members beanFactory.autowireBeanProperties(testCase, AutowireCapableBeanFactory.AUTOWIRE_NO, false); // initialize the bean beanFactory.initializeBean(testCase, testCase.getClass().getName()); }
From source file:com.opensymphony.xwork2.spring.SpringObjectFactory.java
/** * Sets the autowiring strategy/*w ww . j av a 2 s . c o 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:minium.cucumber.MiniumCucumber.java
private void initializeInstance(Class<?> clazz, AutowireCapableBeanFactory beanFactory, Object testInstance) { try {/* ww w. j a va 2s.c om*/ beanFactory.autowireBeanProperties(testInstance, AutowireCapableBeanFactory.AUTOWIRE_NO, false); beanFactory.initializeBean(testInstance, clazz.getName()); } catch (Exception e) { throw Throwables.propagate(e); } }
From source file:org.apache.struts2.spring.StrutsSpringObjectFactory.java
/** * Constructs the spring object factory/* ww w . j a va 2 s. c o 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"); } }
From source file:org.openspaces.remoting.SpaceRemotingServiceExporter.java
private void autowireArguments(Object service, Object[] args) { if (disableAutowiredArguments) { return;//w ww .java2 s.c om } if (args == null) { return; } if (shouldAutowire(service)) { for (Object arg : args) { if (arg == null) { continue; } AutowireCapableBeanFactory beanFactory = applicationContext.getAutowireCapableBeanFactory(); beanFactory.autowireBeanProperties(arg, AutowireCapableBeanFactory.AUTOWIRE_NO, false); beanFactory.initializeBean(arg, arg.getClass().getName()); } } }
From source file:org.springframework.test.context.support.DependencyInjectionTestExecutionListener.java
/** * Performs dependency injection and bean initialization for the supplied * {@link TestContext} as described in/*from www. j a va 2 s.c o m*/ * {@link #prepareTestInstance(TestContext) prepareTestInstance()}. * <p>The {@link #REINJECT_DEPENDENCIES_ATTRIBUTE} will be subsequently removed * from the test context, regardless of its value. * @param testContext the test context for which dependency injection should * be performed (never {@code null}) * @throws Exception allows any exception to propagate * @see #prepareTestInstance(TestContext) * @see #beforeTestMethod(TestContext) */ protected void injectDependencies(final TestContext testContext) throws Exception { Object bean = testContext.getTestInstance(); AutowireCapableBeanFactory beanFactory = testContext.getApplicationContext() .getAutowireCapableBeanFactory(); beanFactory.autowireBeanProperties(bean, AutowireCapableBeanFactory.AUTOWIRE_NO, false); beanFactory.initializeBean(bean, testContext.getTestClass().getName()); testContext.removeAttribute(REINJECT_DEPENDENCIES_ATTRIBUTE); }