List of usage examples for org.springframework.context ApplicationContext getAutowireCapableBeanFactory
AutowireCapableBeanFactory getAutowireCapableBeanFactory() throws IllegalStateException;
From source file:de.zib.gndms.infra.system.PluginLoader.java
public static void main(String[] args) throws Exception { if (args.length != 1) { System.out.println("java " + PluginLoader.class.getName() + " <plugin-dir>"); System.exit(1);/* ww w. ja v a 2 s . c om*/ } ApplicationContext context = new ClassPathXmlApplicationContext("classpath:META-INF/00_system.xml"); PluginLoader pl = new PluginLoader(args[0]); ClassLoader cl = pl.loadPlugins(); PluggableTaskFlowProvider provider = (PluggableTaskFlowProvider) context.getAutowireCapableBeanFactory() .getBean("taskFlowProvider"); provider.setCl(cl); provider.loadPlugins(); provider.listPlugins(); System.exit(0); }
From source file:com.laxser.blitz.util.SpringUtils.java
/** * @param bean//from w ww.j a va 2s . c om * @param context */ public static <T> T autowire(T bean, ApplicationContext context) { context.getAutowireCapableBeanFactory().autowireBeanProperties(bean, AutowireCapableBeanFactory.AUTOWIRE_NO, false); @SuppressWarnings("unchecked") T ret = (T) context.getAutowireCapableBeanFactory().initializeBean(bean, bean.getClass().getName()); return ret; }
From source file:org.shept.util.SheptBeanFactoryUtils.java
/** * @param ctx//from ww w .j a v a 2s .c o m * @param sourceName */ public static String getParentBeanName(ApplicationContext ctx, String beanName) { ApplicationContext pc = getRootContext(ctx); AutowireCapableBeanFactory factory = pc.getAutowireCapableBeanFactory(); if (factory instanceof DefaultListableBeanFactory) { BeanDefinition def = ((DefaultListableBeanFactory) factory).getBeanDefinition(beanName); if (def != null) { return def.getParentName(); } } return null; }
From source file:org.uimafit.spring.util.ResourceInitializationUtil.java
/** * Handle Spring-initialization of resoures produced by the UIMA framework. *//* w w w . ja v a2 s . c o m*/ public static Resource initResource(Resource aResource, ApplicationContext aApplicationContext) { AutowireCapableBeanFactory beanFactory = aApplicationContext.getAutowireCapableBeanFactory(); if (aResource instanceof PrimitiveAnalysisEngine_impl) { PropertyAccessor pa = PropertyAccessorFactory.forDirectFieldAccess(aResource); // Access the actual AnalysisComponent and initialize it AnalysisComponent analysisComponent = (AnalysisComponent) pa.getPropertyValue("mAnalysisComponent"); initializeBean(beanFactory, analysisComponent, aResource.getMetaData().getName()); pa.setPropertyValue("mAnalysisComponent", analysisComponent); return aResource; } else { return (Resource) beanFactory.initializeBean(aResource, aResource.getMetaData().getName()); } }
From source file:com.laxser.blitz.util.SpringUtils.java
/** * @param clazz/*from ww w . java2 s .c om*/ * @param context * @return */ public static <T> T createBean(Class<?> clazz, ApplicationContext context) { @SuppressWarnings("unchecked") T bean = (T) context.getAutowireCapableBeanFactory().createBean(clazz, AutowireCapableBeanFactory.AUTOWIRE_NO, false); if (logger.isDebugEnabled()) { logger.debug("create spring bean: " + bean.getClass() + "@" + bean.hashCode()); } return bean; }
From source file:com.codestd.spring.cxf.config.EndpointBeanProcessor.java
public static final void setBlocking(ApplicationContext ctx, EndpointImpl impl) { AutowireCapableBeanFactory fact = ctx.getAutowireCapableBeanFactory(); if (fact instanceof DefaultListableBeanFactory) { DefaultListableBeanFactory dlbf = (DefaultListableBeanFactory) fact; for (BeanPostProcessor bpp : dlbf.getBeanPostProcessors()) { if (CommonAnnotationBeanPostProcessor.class.isInstance(bpp)) { impl.getServerFactory().setBlockPostConstruct(true); impl.getServerFactory().setBlockInjection(false); return; }/*from w w w.j av a 2s . c o m*/ if (bpp instanceof Jsr250BeanPostProcessor) { impl.getServerFactory().setBlockInjection(true); } } } }
From source file:com.helpinput.spring.Commons.java
public static DefaultListableBeanFactory getDefaultListableBeanFactory(ApplicationContext context) { if (context instanceof AbstractApplicationContext) { return (DefaultListableBeanFactory) ((AbstractApplicationContext) context).getBeanFactory(); }/*from w w w .j a v a 2 s.c o m*/ return (DefaultListableBeanFactory) context.getAutowireCapableBeanFactory(); }
From source file:works.cirno.mocha.SpringMVCFactory.java
public static ObjectFactory fromCustomApplicationContext(ApplicationContext ac) { ObjectFactory factory;/* w w w . j a v a 2 s.c om*/ try { factory = ac.getBean(SpringMVCFactory.class); log.info("SpringObjectFactory got from application context"); } catch (NoSuchBeanDefinitionException e) { factory = ac.getAutowireCapableBeanFactory().createBean(SpringMVCFactory.class); log.info("SpringObjectFactory created"); } return factory; }
From source file:io.acme.solution.application.conf.CommandHandlerUtils.java
public static Map<String, CommandHandler> buildCommandHandlersRegistry(final String basePackage, final ApplicationContext context) { final Map<String, CommandHandler> registry = new HashMap<>(); final ClassPathScanningCandidateComponentProvider scanner = new ClassPathScanningCandidateComponentProvider( false);// w w w.j a va2 s . c o m final AutowireCapableBeanFactory beanFactory = context.getAutowireCapableBeanFactory(); scanner.addIncludeFilter(new AssignableTypeFilter(CommandHandler.class)); CommandHandler currentHandler = null; for (BeanDefinition bean : scanner.findCandidateComponents(basePackage)) { currentHandler = (CommandHandler) beanFactory.createBean( ClassUtils.resolveClassName(bean.getBeanClassName(), context.getClassLoader()), AutowireCapableBeanFactory.AUTOWIRE_BY_TYPE, true); registry.put(currentHandler.getInterest(), currentHandler); } return registry; }
From source file:com.taobao.itest.spring.context.SpringContextManager.java
public static void registerBeanDefinition(Field field, ApplicationContext applicationContext) { @SuppressWarnings("deprecation") RootBeanDefinition beanDefinition = new RootBeanDefinition(field.getType(), true); beanDefinition.setAutowireMode(AbstractBeanDefinition.AUTOWIRE_BY_NAME); DefaultListableBeanFactory defaultListableBeanFactory = (DefaultListableBeanFactory) (applicationContext .getAutowireCapableBeanFactory()); defaultListableBeanFactory.registerBeanDefinition(field.getName(), beanDefinition); }