本文整理匯總了Java中org.springframework.beans.factory.config.AutowireCapableBeanFactory類的典型用法代碼示例。如果您正苦於以下問題:Java AutowireCapableBeanFactory類的具體用法?Java AutowireCapableBeanFactory怎麽用?Java AutowireCapableBeanFactory使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
AutowireCapableBeanFactory類屬於org.springframework.beans.factory.config包,在下文中一共展示了AutowireCapableBeanFactory類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: init
import org.springframework.beans.factory.config.AutowireCapableBeanFactory; //導入依賴的package包/類
public void init(ServletConfig config) throws ServletException {
try {
WebApplicationContext springContext = WebApplicationContextUtils.getRequiredWebApplicationContext(config.getServletContext());
final AutowireCapableBeanFactory beanFactory = springContext.getAutowireCapableBeanFactory();
beanFactory.autowireBean(this);
}
catch (Exception e) {
logger.error("Error initializing ShibbolethExtAuthnHandler", e);
}
}
示例2: buildCommandHandlersRegistry
import org.springframework.beans.factory.config.AutowireCapableBeanFactory; //導入依賴的package包/類
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;
}
示例3: testAutowireWithSatisfiedJavaBeanDependency
import org.springframework.beans.factory.config.AutowireCapableBeanFactory; //導入依賴的package包/類
@Test
public void testAutowireWithSatisfiedJavaBeanDependency() {
DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
MutablePropertyValues pvs = new MutablePropertyValues();
pvs.add("name", "Rod");
RootBeanDefinition bd = new RootBeanDefinition(TestBean.class);
bd.setPropertyValues(pvs);
lbf.registerBeanDefinition("rod", bd);
assertEquals(1, lbf.getBeanDefinitionCount());
// Depends on age, name and spouse (TestBean)
Object registered = lbf.autowire(DependenciesBean.class, AutowireCapableBeanFactory.AUTOWIRE_BY_TYPE, true);
assertEquals(1, lbf.getBeanDefinitionCount());
DependenciesBean kerry = (DependenciesBean) registered;
TestBean rod = (TestBean) lbf.getBean("rod");
assertSame(rod, kerry.getSpouse());
}
示例4: testAutowireWithTwoMatchesForConstructorDependency
import org.springframework.beans.factory.config.AutowireCapableBeanFactory; //導入依賴的package包/類
@Test
public void testAutowireWithTwoMatchesForConstructorDependency() {
DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
RootBeanDefinition bd = new RootBeanDefinition(TestBean.class);
lbf.registerBeanDefinition("rod", bd);
RootBeanDefinition bd2 = new RootBeanDefinition(TestBean.class);
lbf.registerBeanDefinition("rod2", bd2);
try {
lbf.autowire(ConstructorDependency.class, AutowireCapableBeanFactory.AUTOWIRE_CONSTRUCTOR, false);
fail("Should have thrown UnsatisfiedDependencyException");
}
catch (UnsatisfiedDependencyException ex) {
// expected
assertTrue(ex.getMessage().contains("rod"));
assertTrue(ex.getMessage().contains("rod2"));
}
}
示例5: testAutowireWithUnsatisfiedConstructorDependency
import org.springframework.beans.factory.config.AutowireCapableBeanFactory; //導入依賴的package包/類
@Test
public void testAutowireWithUnsatisfiedConstructorDependency() {
DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
MutablePropertyValues pvs = new MutablePropertyValues();
pvs.addPropertyValue(new PropertyValue("name", "Rod"));
RootBeanDefinition bd = new RootBeanDefinition(TestBean.class);
bd.setPropertyValues(pvs);
lbf.registerBeanDefinition("rod", bd);
assertEquals(1, lbf.getBeanDefinitionCount());
try {
lbf.autowire(UnsatisfiedConstructorDependency.class, AutowireCapableBeanFactory.AUTOWIRE_CONSTRUCTOR, true);
fail("Should have unsatisfied constructor dependency on SideEffectBean");
}
catch (UnsatisfiedDependencyException ex) {
// expected
}
}
示例6: testAutowireBeanByTypeWithTwoMatches
import org.springframework.beans.factory.config.AutowireCapableBeanFactory; //導入依賴的package包/類
@Test
public void testAutowireBeanByTypeWithTwoMatches() {
DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
RootBeanDefinition bd = new RootBeanDefinition(TestBean.class);
RootBeanDefinition bd2 = new RootBeanDefinition(TestBean.class);
lbf.registerBeanDefinition("test", bd);
lbf.registerBeanDefinition("spouse", bd2);
try {
lbf.autowire(DependenciesBean.class, AutowireCapableBeanFactory.AUTOWIRE_BY_TYPE, true);
fail("Should have thrown UnsatisfiedDependencyException");
}
catch (UnsatisfiedDependencyException ex) {
// expected
assertTrue(ex.getMessage().contains("test"));
assertTrue(ex.getMessage().contains("spouse"));
}
}
示例7: testAutowireBeanByTypeWithTwoMatchesAndParameterNameDiscovery
import org.springframework.beans.factory.config.AutowireCapableBeanFactory; //導入依賴的package包/類
@Test
public void testAutowireBeanByTypeWithTwoMatchesAndParameterNameDiscovery() {
DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
RootBeanDefinition bd = new RootBeanDefinition(TestBean.class);
RootBeanDefinition bd2 = new RootBeanDefinition(TestBean.class);
lbf.registerBeanDefinition("test", bd);
lbf.registerBeanDefinition("spouse", bd2);
try {
lbf.autowire(DependenciesBean.class, AutowireCapableBeanFactory.AUTOWIRE_BY_TYPE, true);
fail("Should have thrown UnsatisfiedDependencyException");
}
catch (UnsatisfiedDependencyException ex) {
// expected
assertTrue(ex.getMessage().contains("test"));
assertTrue(ex.getMessage().contains("spouse"));
}
}
示例8: testAutowireBeanByTypeWithTwoPrimaryCandidates
import org.springframework.beans.factory.config.AutowireCapableBeanFactory; //導入依賴的package包/類
@Test
public void testAutowireBeanByTypeWithTwoPrimaryCandidates() {
DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
RootBeanDefinition bd = new RootBeanDefinition(TestBean.class);
bd.setPrimary(true);
RootBeanDefinition bd2 = new RootBeanDefinition(TestBean.class);
bd2.setPrimary(true);
lbf.registerBeanDefinition("test", bd);
lbf.registerBeanDefinition("spouse", bd2);
try {
lbf.autowire(DependenciesBean.class, AutowireCapableBeanFactory.AUTOWIRE_BY_TYPE, true);
fail("Should have thrown UnsatisfiedDependencyException");
}
catch (UnsatisfiedDependencyException ex) {
// expected
assertNotNull("Exception should have cause", ex.getCause());
assertEquals("Wrong cause type", NoUniqueBeanDefinitionException.class, ex.getCause().getClass());
}
}
示例9: testAutowireBeanByTypeWithIdenticalPriorityCandidates
import org.springframework.beans.factory.config.AutowireCapableBeanFactory; //導入依賴的package包/類
@Test
public void testAutowireBeanByTypeWithIdenticalPriorityCandidates() {
DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
lbf.setDependencyComparator(AnnotationAwareOrderComparator.INSTANCE);
RootBeanDefinition bd = new RootBeanDefinition(HighPriorityTestBean.class);
RootBeanDefinition bd2 = new RootBeanDefinition(HighPriorityTestBean.class);
lbf.registerBeanDefinition("test", bd);
lbf.registerBeanDefinition("spouse", bd2);
try {
lbf.autowire(DependenciesBean.class, AutowireCapableBeanFactory.AUTOWIRE_BY_TYPE, true);
fail("Should have thrown UnsatisfiedDependencyException");
}
catch (UnsatisfiedDependencyException ex) {
// expected
assertNotNull("Exception should have cause", ex.getCause());
assertEquals("Wrong cause type", NoUniqueBeanDefinitionException.class, ex.getCause().getClass());
assertTrue(ex.getMessage().contains("5")); // conflicting priority
}
}
示例10: getInstance
import org.springframework.beans.factory.config.AutowireCapableBeanFactory; //導入依賴的package包/類
public LdapUserManager getInstance(final LdapUserManager.Provider provider) {
LdapUserManager ldapUserManager;
if (provider == LdapUserManager.Provider.MICROSOFTAD) {
ldapUserManager = ldapUserManagerMap.get(LdapUserManager.Provider.MICROSOFTAD);
if (ldapUserManager == null) {
ldapUserManager = new ADLdapUserManagerImpl();
applicationCtx.getAutowireCapableBeanFactory().autowireBeanProperties(ldapUserManager, AutowireCapableBeanFactory.AUTOWIRE_BY_TYPE, true);
ldapUserManagerMap.put(LdapUserManager.Provider.MICROSOFTAD, ldapUserManager);
}
} else {
//defaults to openldap
ldapUserManager = ldapUserManagerMap.get(LdapUserManager.Provider.OPENLDAP);
if (ldapUserManager == null) {
ldapUserManager = new OpenLdapUserManagerImpl();
applicationCtx.getAutowireCapableBeanFactory().autowireBeanProperties(ldapUserManager, AutowireCapableBeanFactory.AUTOWIRE_BY_TYPE, true);
ldapUserManagerMap.put(LdapUserManager.Provider.OPENLDAP, ldapUserManager);
}
}
return ldapUserManager;
}
示例11: buildCommandHandlersRegistry
import org.springframework.beans.factory.config.AutowireCapableBeanFactory; //導入依賴的package包/類
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().getName(), currentHandler);
}
return registry;
}
示例12: buildEventHandlersRegistry
import org.springframework.beans.factory.config.AutowireCapableBeanFactory; //導入依賴的package包/類
public static Map<String, EventHandler> buildEventHandlersRegistry(final String basePackage,
final ApplicationContext context) {
final Map<String, EventHandler> registry = new HashMap<>();
final ClassPathScanningCandidateComponentProvider scanner = new ClassPathScanningCandidateComponentProvider(false);
final AutowireCapableBeanFactory beanFactory = context.getAutowireCapableBeanFactory();
scanner.addIncludeFilter(new AssignableTypeFilter(EventHandler.class));
EventHandler currentHandler = null;
for (BeanDefinition bean : scanner.findCandidateComponents(basePackage)) {
currentHandler = (EventHandler) beanFactory.createBean(ClassUtils.resolveClassName(bean.getBeanClassName(), context.getClassLoader()),
AutowireCapableBeanFactory.AUTOWIRE_BY_TYPE, true);
registry.put(currentHandler.getInterest(), currentHandler);
}
return registry;
}
示例13: installGenerator
import org.springframework.beans.factory.config.AutowireCapableBeanFactory; //導入依賴的package包/類
private void installGenerator(final URI pluginId, final Version version, final PluginVO plugin,
final ClassPathXmlApplicationContext cax,
final Generator<GeneratorConfiguration, GeneratorStatistics> generator) {
cax.getAutowireCapableBeanFactory()
.autowireBeanProperties(generator, AutowireCapableBeanFactory.AUTOWIRE_BY_NAME, false);
if (generator.getConfiguration() == null) {
GeneratorConfiguration generatorConfiguration = generator.newConfiguration();
generator.setConfiguration(generatorConfiguration);
}
if (LifecyclePhase.NOT_INSTALLED.toString().equals(plugin.getState()))
generator.install(true);
else
generator.install(false);
pluginDAO.updatePluginState(pluginId, version, LifecyclePhase.INSTALLED.toString());
generator.initialize();
generators.put(generator.getId(), generator);
contexts.put(generator.getId(), cax);
logger.info("registered plugin " + generator.getSourceType());
pluginDAO.updatePluginState(pluginId, version, LifecyclePhase.INITIALIZED.toString());
}
示例14: testContextConfiguration
import org.springframework.beans.factory.config.AutowireCapableBeanFactory; //導入依賴的package包/類
private void testContextConfiguration(String profile, String springProfile) {
GenericXmlApplicationContext context = createContext(profile, springProfile);
AutowireCapableBeanFactory factory = context.getAutowireCapableBeanFactory();
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
ResourceLoader resourceLoader = new MultiLoader(classLoader);
ClassFinder classFinder = new ResourceLoaderClassFinder(resourceLoader, classLoader);
Collection<Class<?>> descendants = classFinder.getDescendants(Object.class, "com.hotwire.test.steps");
List<Throwable> throwables = new ArrayList<>();
for (Class<?> clazz : descendants) {
if (Utils.isInstantiable(clazz) & !clazz.isEnum()) {
context.registerBeanDefinition(clazz.getName(),
BeanDefinitionBuilder.genericBeanDefinition(clazz).getBeanDefinition());
try {
factory.getBean(clazz.getName());
}
catch (Throwable t) {
while (t.getCause() != null) {
t = t.getCause();
}
System.err.println(t.getMessage());
throwables.add(t);
}
}
}
assertThat(throwables)
.as("List of throwables should be empty!")
.isEmpty();
}
示例15: doGet
import org.springframework.beans.factory.config.AutowireCapableBeanFactory; //導入依賴的package包/類
private synchronized Object doGet(final String className) {
// Check again for the cache here, inside the sync method
Object bean = beans.get(className);
if (bean != null) {
return bean;
}
try {
AutowireCapableBeanFactory factory = applicationContext.getAutowireCapableBeanFactory();
Class<?> beanClass = Class.forName(className);
bean = factory.createBean(beanClass, AutowireCapableBeanFactory.AUTOWIRE_BY_TYPE, false);
factory.initializeBean(bean, beanClass.getSimpleName() + "#" + System.identityHashCode(bean));
beans.put(className, bean);
return bean;
} catch (Exception e) {
throw new IllegalArgumentException("Couldn't instantiate class " + className, e);
}
}