Java Code Examples for org.springframework.context.ApplicationContext#getAutowireCapableBeanFactory()
The following examples show how to use
org.springframework.context.ApplicationContext#getAutowireCapableBeanFactory() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SpecialBeanInstantiationDemo.java From geekbang-lessons with Apache License 2.0 | 6 votes |
public static void main(String[] args) { // 配置 XML 配置文件 // 启动 Spring 应用上下文 ApplicationContext applicationContext = new ClassPathXmlApplicationContext("classpath:/META-INF/special-bean-instantiation-context.xml"); // 通过 ApplicationContext 获取 AutowireCapableBeanFactory AutowireCapableBeanFactory beanFactory = applicationContext.getAutowireCapableBeanFactory(); ServiceLoader<UserFactory> serviceLoader = beanFactory.getBean("userFactoryServiceLoader", ServiceLoader.class); displayServiceLoader(serviceLoader); // demoServiceLoader(); // 创建 UserFactory 对象,通过 AutowireCapableBeanFactory UserFactory userFactory = beanFactory.createBean(DefaultUserFactory.class); System.out.println(userFactory.createUser()); }
Example 2
Source File: AppUI.java From cuba with Apache License 2.0 | 6 votes |
protected void autowireContext(Object instance, ApplicationContext applicationContext) { AutowireCapableBeanFactory autowireBeanFactory = applicationContext.getAutowireCapableBeanFactory(); autowireBeanFactory.autowireBean(instance); if (instance instanceof ApplicationContextAware) { ((ApplicationContextAware) instance).setApplicationContext(applicationContext); } if (instance instanceof InitializingBean) { try { ((InitializingBean) instance).afterPropertiesSet(); } catch (Exception e) { throw new RuntimeException( "Unable to initialize UI Component - calling afterPropertiesSet for " + instance.getClass(), e); } } }
Example 3
Source File: CommandHandlerUtils.java From cqrs-es-kafka with MIT License | 6 votes |
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); 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; }
Example 4
Source File: ModuleBasedFilter.java From cloudstack with Apache License 2.0 | 6 votes |
@Override public void init(FilterConfig filterConfig) throws ServletException { String module = filterConfig.getInitParameter("module"); CloudStackSpringContext context = (CloudStackSpringContext)filterConfig.getServletContext().getAttribute(CloudStackSpringContext.CLOUDSTACK_CONTEXT_SERVLET_KEY); if (context == null) return; ApplicationContext applicationContext = context.getApplicationContextForWeb(module); if (applicationContext != null) { AutowireCapableBeanFactory factory = applicationContext.getAutowireCapableBeanFactory(); if (factory != null) { factory.autowireBean(this); enabled = true; } } }
Example 5
Source File: Neo4jMappingContext.java From sdn-rx with Apache License 2.0 | 5 votes |
@Override public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { super.setApplicationContext(applicationContext); this.beanFactory = applicationContext.getAutowireCapableBeanFactory(); Driver driver = this.beanFactory.getBean(Driver.class); ((DefaultNeo4jConverter) this.converter).setTypeSystem(driver.defaultTypeSystem()); }
Example 6
Source File: JAXRSClientFactoryBeanDefinitionParser.java From cxf with Apache License 2.0 | 5 votes |
static List<Object> getProviders(ApplicationContext context, Collection<Class<?>> providerClasses) { List<Object> providers = new LinkedList<>(); AutowireCapableBeanFactory beanFactory = context.getAutowireCapableBeanFactory(); for (final Class< ? > providerClass: providerClasses) { Object bean = null; try { bean = beanFactory.createBean(providerClass, AutowireCapableBeanFactory.AUTOWIRE_BY_TYPE, true); } catch (Exception ex) { bean = beanFactory.createBean(providerClass); } providers.add(bean); } return providers; }
Example 7
Source File: AbstractSpringManagedBeanFactory.java From dolphin-platform with Apache License 2.0 | 5 votes |
@Override public <T> T createDependentInstance(Class<T> cls, PostConstructInterceptor<T> interceptor) { Assert.requireNonNull(cls, "cls"); Assert.requireNonNull(interceptor, "interceptor"); ApplicationContext context = getContext(); AutowireCapableBeanFactory beanFactory = context.getAutowireCapableBeanFactory(); SpringPreInjector.getInstance().prepare(cls, interceptor); return beanFactory.createBean(cls); }
Example 8
Source File: AdminMenuJspBeanTest.java From lutece-core with BSD 3-Clause "New" or "Revised" License | 5 votes |
private AdminUserDAO getAdminUserDAO( ) { AdminUserDAO adminUserDAO = new AdminUserDAO( ); ApplicationContext context = SpringContextService.getContext( ); AutowireCapableBeanFactory beanFactory = context.getAutowireCapableBeanFactory( ); beanFactory.autowireBean( adminUserDAO ); return adminUserDAO; }
Example 9
Source File: LuteceDefaultAdminAuthenticationTest.java From lutece-core with BSD 3-Clause "New" or "Revised" License | 5 votes |
private AdminUserDAO getAdminUserDAO( ) { AdminUserDAO adminUserDAO = new AdminUserDAO( ); ApplicationContext context = SpringContextService.getContext( ); AutowireCapableBeanFactory beanFactory = context.getAutowireCapableBeanFactory( ); beanFactory.autowireBean( adminUserDAO ); return adminUserDAO; }
Example 10
Source File: DubboConfigBeanDefinitionConflictApplicationListener.java From dubbo-spring-boot-project with Apache License 2.0 | 5 votes |
private BeanDefinitionRegistry getBeanDefinitionRegistry(ApplicationContext applicationContext) { AutowireCapableBeanFactory beanFactory = applicationContext.getAutowireCapableBeanFactory(); if (beanFactory instanceof BeanDefinitionRegistry) { return (BeanDefinitionRegistry) beanFactory; } throw new IllegalStateException(""); }
Example 11
Source File: MicroInjectSpringPlugin.java From nh-micro with Apache License 2.0 | 5 votes |
public GroovyObject execPlugIn(String name, GroovyObject groovyObject, GroovyObject proxyObject) throws Exception { ApplicationContext context=MicroContextHolder.getContext(); AutowireCapableBeanFactory autowireCapableBeanFactory=context.getAutowireCapableBeanFactory(); autowireCapableBeanFactory.autowireBeanProperties(groovyObject, AutowireCapableBeanFactory.AUTOWIRE_BY_NAME, false); return proxyObject; }
Example 12
Source File: AbstractSpringManagedBeanFactory.java From dolphin-platform with Apache License 2.0 | 5 votes |
@Override public <T> T createDependentInstance(Class<T> cls) { Assert.requireNonNull(cls, "cls"); ApplicationContext context = getContext(); AutowireCapableBeanFactory beanFactory = context.getAutowireCapableBeanFactory(); return beanFactory.createBean(cls); }
Example 13
Source File: AbstractEntityService.java From OpERP with MIT License | 5 votes |
@Override public void registerClient(String clientAddress) { System.out.println("Client from " + clientAddress); ApplicationContext context = ServerApp.getApplicationContext(); AutowireCapableBeanFactory factory = context .getAutowireCapableBeanFactory(); BeanDefinitionRegistry registry = (BeanDefinitionRegistry) factory; GenericBeanDefinition beanDefinition = new GenericBeanDefinition(); beanDefinition.setBeanClass(RmiProxyFactoryBean.class); beanDefinition.setAutowireCandidate(true); Class<EM> entityModelInterfaceClass = getEntityModelInterfaceClass(); MutablePropertyValues propertyValues = new MutablePropertyValues(); propertyValues.addPropertyValue("serviceInterface", entityModelInterfaceClass); propertyValues.addPropertyValue("serviceUrl", "rmi://" + clientAddress + ":1099/" + entityModelInterfaceClass.getCanonicalName()); beanDefinition.setPropertyValues(propertyValues); registry.registerBeanDefinition( entityModelInterfaceClass.getCanonicalName(), beanDefinition); EM entityModel = context.getBean(entityModelInterfaceClass); registerEntityModel(entityModel); System.out.println(entityModel); }
Example 14
Source File: AutowiringQuartzSpringBeanJobFactory.java From herd with Apache License 2.0 | 4 votes |
@Override public void setApplicationContext(final ApplicationContext context) { beanFactory = context.getAutowireCapableBeanFactory(); }
Example 15
Source File: AutowiringSpringBeanJobFactory.java From molgenis with GNU Lesser General Public License v3.0 | 4 votes |
@Override public void setApplicationContext(final ApplicationContext context) { beanFactory = context.getAutowireCapableBeanFactory(); }
Example 16
Source File: AutowiringSpringBeanJobFactory.java From multiapps-controller with Apache License 2.0 | 4 votes |
@Override public void setApplicationContext(ApplicationContext context) { beanFactory = context.getAutowireCapableBeanFactory(); }
Example 17
Source File: AutowiringSpringBeanJobFactory.java From quartz-manager with MIT License | 4 votes |
@Override public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { beanFactory = applicationContext.getAutowireCapableBeanFactory(); }
Example 18
Source File: BasicBeanProcessor.java From springboot-plugin-framework-parent with Apache License 2.0 | 4 votes |
public BasicBeanProcessor(ApplicationContext applicationContext){ Objects.requireNonNull(applicationContext); this.springBeanRegister = new SpringBeanRegister(applicationContext); this.helper = new BeanFactoryAdvisorRetrievalHelper( (ConfigurableListableBeanFactory)applicationContext.getAutowireCapableBeanFactory()); }
Example 19
Source File: AutoWiringSpringBeanJobFactory.java From WeEvent with Apache License 2.0 | 2 votes |
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { beanFactory = applicationContext.getAutowireCapableBeanFactory(); }
Example 20
Source File: AutoWiringSpringBeanJobFactory.java From tutorials with MIT License | 2 votes |
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { beanFactory = applicationContext.getAutowireCapableBeanFactory(); }