Java Code Examples for org.springframework.beans.factory.support.GenericBeanDefinition#setLazyInit()

The following examples show how to use org.springframework.beans.factory.support.GenericBeanDefinition#setLazyInit() . 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: EmbeddedCassandraContextCustomizer.java    From embedded-cassandra with Apache License 2.0 5 votes vote down vote up
private static void registerCassandraBeanDefinition(boolean exposeProperties,
		ConfigurableApplicationContext context,
		BeanDefinitionRegistry registry) {
	GenericBeanDefinition bd = new GenericBeanDefinition();
	bd.setBeanClass(Cassandra.class);
	bd.setDestroyMethodName("stop");
	bd.setLazyInit(false);
	bd.setScope(BeanDefinition.SCOPE_SINGLETON);
	bd.setInstanceSupplier(new CassandraSupplier(exposeProperties, context));
	registry.registerBeanDefinition(Cassandra.class.getName(), bd);
}
 
Example 2
Source File: EmbeddedCassandraContextCustomizer.java    From embedded-cassandra with Apache License 2.0 5 votes vote down vote up
private static void registerCassandraConnectionBeanDefinition(ConfigurableApplicationContext context,
		BeanDefinitionRegistry registry) {
	GenericBeanDefinition bd = new GenericBeanDefinition();
	bd.setBeanClass(CassandraConnection.class);
	bd.setDestroyMethodName("close");
	bd.setLazyInit(true);
	bd.setDependsOn(Cassandra.class.getName());
	bd.setScope(BeanDefinition.SCOPE_SINGLETON);
	bd.setInstanceSupplier(new CassandraConnectionSupplier(context));
	registry.registerBeanDefinition(CassandraConnection.class.getName(), bd);
}
 
Example 3
Source File: EmbeddedCassandraContextCustomizer.java    From embedded-cassandra with Apache License 2.0 5 votes vote down vote up
private static void registerCassandraInitializerBeanDefinition(CqlDataSet dataSet,
		ConfigurableApplicationContext context,
		BeanDefinitionRegistry registry) {
	GenericBeanDefinition bd = new GenericBeanDefinition();
	bd.setBeanClass(CassandraInitializer.class);
	bd.setLazyInit(false);
	bd.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
	bd.setScope(BeanDefinition.SCOPE_SINGLETON);
	bd.setInstanceSupplier(() -> new CassandraInitializer(context, dataSet));
	registry.registerBeanDefinition(CassandraInitializer.class.getName(), bd);
}
 
Example 4
Source File: ColaMockController.java    From COLA with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
    ColaMockController.beanFactory = beanFactory;
    ColaMockito.g().setBeanFactory(beanFactory);
    String[] beanDefinitionNames = registry.getBeanDefinitionNames();
    Map<String, String> index = Arrays.stream(beanDefinitionNames).collect(Collectors.toMap(key->key, v->v));
    for(String name : serviceList){
        String[] meta = name.split(Constants.SERVICE_LIST_DELIMITER);
        String beanName = meta[0];
        String beanClass = meta[1];
        if(index.get(meta[0]) == null){
            try {
                Class type = Thread.currentThread().getContextClassLoader().loadClass(beanClass);
                //if("fileserverClient".equals(beanName)){
                //    System.out.println("============");
                //}
                if(!mockFilterManager.match(type)){
                    continue;
                }
                GenericBeanDefinition definition = new GenericBeanDefinition();
                definition.getConstructorArgumentValues().addGenericArgumentValue(beanName);
                definition.getConstructorArgumentValues().addGenericArgumentValue(type);
                definition.setAutowireMode(AbstractBeanDefinition.AUTOWIRE_BY_TYPE);
                definition.setBeanClass(AutoMockFactoryBean.class);
                definition.setScope("singleton");
                definition.setLazyInit(true);
                definition.setAutowireCandidate(true);
                registry.registerBeanDefinition(beanName, definition);
            } catch (ClassNotFoundException e) {
                e.printStackTrace();
            }
        }
    }
}
 
Example 5
Source File: MangoDaoAutoCreator.java    From mango-spring-boot-starter with Apache License 2.0 5 votes vote down vote up
/**
 * 向spring中注入dao代理
 * @param beanFactory
 */
private void registryMangoDao(DefaultListableBeanFactory beanFactory){
    for (Class<?> daoClass : findMangoDaoClasses(config.getScanPackage())) {
        GenericBeanDefinition bf = new GenericBeanDefinition();
        bf.setBeanClassName(daoClass.getName());
        MutablePropertyValues pvs = bf.getPropertyValues();
        pvs.addPropertyValue("daoClass", daoClass);
        bf.setBeanClass(factoryBeanClass);
        bf.setPropertyValues(pvs);
        bf.setLazyInit(false);
        beanFactory.registerBeanDefinition(daoClass.getName(), bf);
    }
}
 
Example 6
Source File: DisconfMgrBean.java    From disconf with Apache License 2.0 5 votes vote down vote up
/**
 * register aspectJ for disconf get request
 *
 * @param registry
 */
private void registerAspect(BeanDefinitionRegistry registry) {

    GenericBeanDefinition beanDefinition = new GenericBeanDefinition();
    beanDefinition.setBeanClass(DisconfAspectJ.class);
    beanDefinition.setLazyInit(false);
    beanDefinition.setAbstract(false);
    beanDefinition.setAutowireCandidate(true);
    beanDefinition.setScope("singleton");

    registry.registerBeanDefinition("disconfAspectJ", beanDefinition);
}
 
Example 7
Source File: DisconfMgrBean.java    From disconf with Apache License 2.0 5 votes vote down vote up
/**
 * register aspectJ for disconf get request
 *
 * @param registry
 */
private void registerAspect(BeanDefinitionRegistry registry) {

    GenericBeanDefinition beanDefinition = new GenericBeanDefinition();
    beanDefinition.setBeanClass(DisconfAspectJ.class);
    beanDefinition.setLazyInit(false);
    beanDefinition.setAbstract(false);
    beanDefinition.setAutowireCandidate(true);
    beanDefinition.setScope("singleton");

    registry.registerBeanDefinition("disconfAspectJ", beanDefinition);
}
 
Example 8
Source File: MangoDaoScanner.java    From mango with Apache License 2.0 5 votes vote down vote up
@Override
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
  DefaultListableBeanFactory dlbf = (DefaultListableBeanFactory) beanFactory;
  for (Class<?> daoClass : findMangoDaoClasses()) {
    GenericBeanDefinition bf = new GenericBeanDefinition();
    bf.setBeanClassName(daoClass.getName());
    MutablePropertyValues pvs = bf.getPropertyValues();
    pvs.addPropertyValue("daoClass", daoClass);
    bf.setBeanClass(factoryBeanClass);
    bf.setPropertyValues(pvs);
    bf.setLazyInit(false);
    dlbf.registerBeanDefinition(daoClass.getName(), bf);
  }
}