List of usage examples for org.springframework.beans.factory.config AutowireCapableBeanFactory AUTOWIRE_BY_NAME
int AUTOWIRE_BY_NAME
To view the source code for org.springframework.beans.factory.config AutowireCapableBeanFactory AUTOWIRE_BY_NAME.
Click Source Link
From source file:architecture.ee.spring.context.impl.ApplicationHelperImpl.java
@SuppressWarnings("unchecked") public <T> T createComponent(Class<T> requiredType) { if (getConfigurableApplicationContext() != null) return (T) getConfigurableApplicationContext().getAutowireCapableBeanFactory().createBean(requiredType, AutowireCapableBeanFactory.AUTOWIRE_BY_NAME, false); throw new IllegalStateException(""); }
From source file:org.usergrid.management.cassandra.ManagementTestHelperImpl.java
@Override public void setup() throws Exception { // assertNotNull(client); String maven_opts = System.getenv("MAVEN_OPTS"); logger.info("Maven options: " + maven_opts); logger.info("Starting Cassandra"); embedded = new EmbeddedServerHelper(); embedded.setup();/*from w w w .j a va 2s.c o m*/ // copy("/testApplicationContext.xml", TMP); String[] locations = { "testApplicationContext.xml" }; ApplicationContext ac = new ClassPathXmlApplicationContext(locations); AutowireCapableBeanFactory acbf = ac.getAutowireCapableBeanFactory(); acbf.autowireBeanProperties(this, AutowireCapableBeanFactory.AUTOWIRE_BY_NAME, false); acbf.initializeBean(this, "testClient"); assertNotNull(emf); assertTrue("EntityManagerFactory is instance of EntityManagerFactoryImpl", emf instanceof EntityManagerFactoryImpl); emf.setup(); management.setup(); }
From source file:org.grails.plugin.batch.Launcher.java
public void init(String[] args) { logDebug(true, "init(): begin"); synchronized (initLock) { logDebug(true, "init(): this classLoader ", this.getClass().getClassLoader()); logDebug(true, "init(): thread classLoader ", Thread.currentThread().getContextClassLoader()); logDebug(true, "init(): env ", Environment.getCurrent()); String resourcePath = getSystemProperty("resourcePath", null); if (resourcePath == null) { resourcePath = "war"; }/*from www . j a va2s .c om*/ logDebug(true, "init(): resourcePath ", resourcePath); servletContext = resourcePath != null ? new MockServletContext(resourcePath) : new MockServletContext(); servletContext.setAttribute("args", args); servletContextListeners = new ServletContextListener[] { new Log4jConfigListener(), new GrailsContextLoaderListener() }; this.shutdownHook = new Thread() { public void run() { logDebug(true, "shutdown hook run():"); Launcher.this.destroy(); } }; this.destroyed = false; Runtime.getRuntime().addShutdownHook(this.shutdownHook); logDebug(true, "init(): shutdown hook added"); try { ServletContextEvent event = new ServletContextEvent(servletContext); for (ServletContextListener l : servletContextListeners) { l.contextInitialized(event); } } catch (RuntimeException e) { log.error("init()", e); throw e; } logDebug("init(): thread classLoader ", Thread.currentThread().getContextClassLoader()); GrailsApplication grailsApplication = ApplicationHolder.getApplication(); DefaultGrailsMainClass main = getMainClass(grailsApplication); if (main != null) { final Object instance = main.getReferenceInstance(); WebApplicationContext webContext = (WebApplicationContext) grailsApplication.getMainContext(); webContext.getAutowireCapableBeanFactory().autowireBeanProperties(instance, AutowireCapableBeanFactory.AUTOWIRE_BY_NAME, false); main.callInit(); } logDebug("init(): end"); } }
From source file:com.meidusa.venus.frontend.http.VenusPoolFactory.java
@SuppressWarnings("unchecked") public void afterPropertiesSet() throws Exception { logger.trace("current Venus Client id=" + PacketConstant.VENUS_CLIENT_ID); beanContext = new BeanContext() { public Object getBean(String beanName) { if (beanFactory != null) { return beanFactory.getBean(beanName); } else { return null; }/*from w ww. jav a2 s . com*/ } public Object createBean(Class clazz) throws Exception { if (beanFactory instanceof AutowireCapableBeanFactory) { AutowireCapableBeanFactory factory = (AutowireCapableBeanFactory) beanFactory; return factory.autowire(clazz, AutowireCapableBeanFactory.AUTOWIRE_BY_NAME, false); } return null; } }; BeanContextBean.getInstance().setBeanContext(beanContext); VenusBeanUtilsBean.setInstance(new BeanUtilsBean(new ConvertUtilsBean(), new PropertyUtilsBean()) { public void setProperty(Object bean, String name, Object value) throws IllegalAccessException, InvocationTargetException { if (value instanceof String) { PropertyDescriptor descriptor = null; try { descriptor = getPropertyUtils().getPropertyDescriptor(bean, name); if (descriptor == null) { return; // Skip this property setter } else { if (descriptor.getPropertyType().isEnum()) { Class<Enum> clazz = (Class<Enum>) descriptor.getPropertyType(); value = Enum.valueOf(clazz, (String) value); } else { Object temp = null; try { temp = ConfigUtil.filter((String) value, beanContext); } catch (Exception e) { } if (temp == null) { temp = ConfigUtil.filter((String) value); } value = temp; } } } catch (NoSuchMethodException e) { return; // Skip this property setter } } super.setProperty(bean, name, value); } }); reloadConfiguration(); __RELOAD: { if (enableReload) { File[] files = new File[this.configFiles.length]; for (int i = 0; i < this.configFiles.length; i++) { try { files[i] = ResourceUtils.getFile(configFiles[i].trim()); } catch (FileNotFoundException e) { logger.warn(e.getMessage()); enableReload = false; logger.warn("venus serviceFactory configuration reload disabled!"); break __RELOAD; } } VenusFileWatchdog dog = new VenusFileWatchdog(files); dog.setDelay(1000 * 10); dog.start(); } } }
From source file:org.usergrid.websocket.WebSocketServer.java
public void startSpring() { String[] locations = getApplicationContextLocations(); ApplicationContext ac = new ClassPathXmlApplicationContext(locations); AutowireCapableBeanFactory acbf = ac.getAutowireCapableBeanFactory(); acbf.autowireBeanProperties(this, AutowireCapableBeanFactory.AUTOWIRE_BY_NAME, false); acbf.initializeBean(this, "webSocketServer"); assertNotNull(emf);/*from w ww . jav a2 s .co m*/ assertTrue("EntityManagerFactory is instance of EntityManagerFactoryImpl", emf instanceof EntityManagerFactoryImpl); }
From source file:de.zib.gndms.gndmc.gorfx.GORFXTaskFlowExample.java
public <T> T createBean(final Class<T> beanClass, int autowireMode) { return (T) context.getAutowireCapableBeanFactory().createBean(beanClass, AutowireCapableBeanFactory.AUTOWIRE_BY_NAME, true); }
From source file:org.grails.datastore.gorm.events.DomainEventListener.java
protected void autowireBeanProperties(final Object entity) { datastore.getApplicationContext().getAutowireCapableBeanFactory().autowireBeanProperties(entity, AutowireCapableBeanFactory.AUTOWIRE_BY_NAME, false); }
From source file:net.danielkvasnicka.flower.FlowerDispatcherServlet.java
/** * Setup Spring managed resources on me/*from w w w . j a v a2s . com*/ */ @Override public void init(final ServletConfig servletConfig) throws ServletException { this.servletConfig = servletConfig; this.appCtx = WebApplicationContextUtils.getWebApplicationContext(servletConfig.getServletContext()); this.appCtx.getAutowireCapableBeanFactory().autowireBeanProperties(this, AutowireCapableBeanFactory.AUTOWIRE_BY_NAME, true); }