java类org.springframework.beans.factory.config.AutowireCapableBeanFactory的实例源码

CustomObjectHandlerImpl.java 文件源码 项目:open-cyclos 阅读 23 收藏 0 点赞 0 评论 0
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);
    }
}
AbstractTestBase.java 文件源码 项目:projectforge-webapp 阅读 27 收藏 0 点赞 0 评论 0
protected static void preInit(final String... additionalContextFiles)
{
  TimeZone.setDefault(DateHelper.UTC);
  log.info("user.timezone is: " + System.getProperty("user.timezone"));
  TestConfiguration.initAsTestConfiguration(additionalContextFiles);
  testConfiguration = TestConfiguration.getConfiguration();
  final DaoRegistry daoRegistry = TestConfiguration.getConfiguration().getBean("daoRegistry", DaoRegistry.class);
  daoRegistry.init();
  initTestDB = testConfiguration.getBean("initTestDB", InitTestDB.class);
  testConfiguration.autowire(initTestDB, AutowireCapableBeanFactory.AUTOWIRE_BY_NAME);
  final File testDir = new File(TEST_DIR);
  if (testDir.exists() == false) {
    testDir.mkdir();
  }
  if (DatabaseSupport.getInstance() == null) {
    DatabaseSupport.setInstance(new DatabaseSupport(HibernateUtils.getDialect()));
  }
}
OntologyRepositoryCollectionTest.java 文件源码 项目:molgenis 阅读 28 收藏 0 点赞 0 评论 0
@BeforeMethod
public void beforeMethod() throws IOException, OWLOntologyCreationException, NoSuchMethodException
{

    // ontology repository collection is not spring managed, see FileRepositoryCollectionFactory
    File file = ResourceUtils.getFile("small_test_data_NGtest.owl.zip");
    OntologyRepositoryCollection ontologyRepoCollection = BeanUtils.instantiateClass(
            OntologyRepositoryCollection.class.getConstructor(File.class), file);
    autowireCapableBeanFactory.autowireBeanProperties(ontologyRepoCollection,
            AutowireCapableBeanFactory.AUTOWIRE_BY_TYPE, false);
    ontologyRepoCollection.init();

    ontologyRepository = ontologyRepoCollection.getRepository(ONTOLOGY);
    ontologyTermDynamicAnnotationRepository = ontologyRepoCollection.getRepository(
            ONTOLOGY_TERM_DYNAMIC_ANNOTATION);
    ontologyTermNodePathRepository = ontologyRepoCollection.getRepository(ONTOLOGY_TERM_NODE_PATH);
    ontologyTermSynonymRepository = ontologyRepoCollection.getRepository(ONTOLOGY_TERM_SYNONYM);
    ontologyTermRepository = ontologyRepoCollection.getRepository(ONTOLOGY_TERM);
}
BeanCreator.java 文件源码 项目:gen-sbconfigurator 阅读 33 收藏 0 点赞 0 评论 0
/**
 * Creates an instance of the bean.
 * 
 * @return the created instance
 * 
 * @throws Exception
 *             if the instance cannot be created
 */
protected Object createInstance() throws Exception {
    final Constructor<?> constructor = findMatchingConstructor();
    final Object object = constructor.newInstance(constArgs);

    // check if we have to apply properties
    if (properties != null && properties.size() > 0) {
        new BeanWrapperImpl(object).setPropertyValues(values);
    }

    // auto-wire everything if the factory supports that
    if (beanFactory instanceof AutowireCapableBeanFactory) {
        ((AutowireCapableBeanFactory) beanFactory).autowireBeanProperties(
                object, AutowireCapableBeanFactory.AUTOWIRE_NO, false);
    }

    return object;
}
AbstractEntityModel.java 文件源码 项目:OpERP 阅读 26 收藏 0 点赞 0 评论 0
@PostConstruct
public void registerWithServer() {
    AutowireCapableBeanFactory factory = context
            .getAutowireCapableBeanFactory();
    BeanDefinitionRegistry registry = (BeanDefinitionRegistry) factory;
    GenericBeanDefinition beanDefinition = new GenericBeanDefinition();
    beanDefinition.setBeanClass(RmiServiceExporter.class);
    beanDefinition.setAutowireCandidate(true);

    MutablePropertyValues propertyValues = new MutablePropertyValues();

    Class<?> serviceInterface = this.getClass().getInterfaces()[0];

    propertyValues.addPropertyValue("serviceInterface", serviceInterface);
    String serviceName = serviceInterface.getCanonicalName();
    propertyValues.addPropertyValue("serviceName", serviceName);
    propertyValues.addPropertyValue("service", this);
    propertyValues.addPropertyValue("registryPort", "1099");
    beanDefinition.setPropertyValues(propertyValues);

    registry.registerBeanDefinition(serviceName, beanDefinition);
    context.getBean(serviceName); // Need this else
                                    // NotBoundException
    getService().registerClient(getHostAddress());

}
CasSpringBeanJobFactory.java 文件源码 项目:springboot-shiro-cas-mybatis 阅读 22 收藏 0 点赞 0 评论 0
@Override
protected Object createJobInstance(final TriggerFiredBundle bundle) throws Exception {
    final AutowireCapableBeanFactory beanFactory = applicationContext.getAutowireCapableBeanFactory();
    final Object job = super.createJobInstance(bundle);
    logger.debug("Created job {} for bundle {}", job, bundle);
    beanFactory.autowireBean(job);
    logger.debug("Autowired job per the application context");
    return job;
}
BeanRegisterUtils.java 文件源码 项目:-artemis-disruptor-miaosha 阅读 34 收藏 0 点赞 0 评论 0
public static void registerSingleton(ApplicationContext applicationContext, String beanName, Object singletonObject) {

    AutowireCapableBeanFactory beanFactory = applicationContext.getAutowireCapableBeanFactory();
    if (!SingletonBeanRegistry.class.isAssignableFrom(beanFactory.getClass())) {
      throw new IllegalArgumentException(
          "ApplicationContext: " + applicationContext.getClass().toString()
              + " doesn't implements SingletonBeanRegistry, cannot register JMS connection at runtime");
    }

    SingletonBeanRegistry beanDefinitionRegistry = (SingletonBeanRegistry) beanFactory;
    beanDefinitionRegistry.registerSingleton(beanName, singletonObject);

  }
EventManagerConfiguration.java 文件源码 项目:martini-jmeter-extension 阅读 24 收藏 0 点赞 0 评论 0
@Bean
EventManager getEventManger(
    AutowireCapableBeanFactory beanFactory,
    @Value("${martini.event.manager.impl:#{null}}") Class<? extends EventManager> implementation
) {
    return null == implementation ?
        beanFactory.createBean(DefaultEventManager.class) : beanFactory.createBean(implementation);
}
MartiniResultMarshallerConfiguration.java 文件源码 项目:martini-jmeter-extension 阅读 23 收藏 0 点赞 0 评论 0
@Bean
MartiniResultMarshaller getMartiniResultMarshaller(
    AutowireCapableBeanFactory beanFactory,
    @Value("${martini.result.marshaller.implementation:#{null}}") Class<? extends MartiniResultMarshaller> implementation
) {
    return null == implementation ?
        beanFactory.createBean(DefaultMartiniResultMarshaller.class) :
        beanFactory.createBean(implementation);
}


问题


面经


文章

微信
公众号

扫码关注公众号