当前位置: 首页>>代码示例>>Java>>正文


Java DefaultListableBeanFactory类代码示例

本文整理汇总了Java中org.springframework.beans.factory.support.DefaultListableBeanFactory的典型用法代码示例。如果您正苦于以下问题:Java DefaultListableBeanFactory类的具体用法?Java DefaultListableBeanFactory怎么用?Java DefaultListableBeanFactory使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


DefaultListableBeanFactory类属于org.springframework.beans.factory.support包,在下文中一共展示了DefaultListableBeanFactory类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getMangoConfig

import org.springframework.beans.factory.support.DefaultListableBeanFactory; //导入依赖的package包/类
public static MangoConfig getMangoConfig(DefaultListableBeanFactory beanFactory,String prefix){
    MangoConfig target = new MangoConfig();
    PropertiesConfigurationFactory<Object> factory = new PropertiesConfigurationFactory<Object>(target);
    factory.setPropertySources(deducePropertySources(beanFactory));
    factory.setConversionService(new DefaultConversionService());
    factory.setIgnoreInvalidFields(false);
    factory.setIgnoreUnknownFields(true);
    factory.setIgnoreNestedProperties(false);
    factory.setTargetName(prefix);
    try {
        factory.bindPropertiesToTarget();
    }
    catch (Exception ex) {
        throw new MangoAutoConfigException(ex);
    }
    return target;
}
 
开发者ID:jfaster,项目名称:mango-spring-boot-starter,代码行数:18,代码来源:MangoConfigFactory.java

示例2: setUp

import org.springframework.beans.factory.support.DefaultListableBeanFactory; //导入依赖的package包/类
@Before
public void setUp() throws Exception {

	final ProtectionDomain empty = new ProtectionDomain(null,
			new Permissions());

	provider = new SecurityContextProvider() {
		private final AccessControlContext acc = new AccessControlContext(
				new ProtectionDomain[] { empty });

		@Override
		public AccessControlContext getAccessControlContext() {
			return acc;
		}
	};

	DefaultResourceLoader drl = new DefaultResourceLoader();
	Resource config = drl
			.getResource("/org/springframework/beans/factory/support/security/callbacks.xml");
	beanFactory = new DefaultListableBeanFactory();
	new XmlBeanDefinitionReader(beanFactory).loadBeanDefinitions(config);
	beanFactory.setSecurityContextProvider(provider);
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:24,代码来源:CallbacksSecurityTests.java

示例3: setSerializationId

import org.springframework.beans.factory.support.DefaultListableBeanFactory; //导入依赖的package包/类
/**
 * If the bean factory is a DefaultListableBeanFactory then it can serialize scoped
 * beans and deserialize them in another context (even in another JVM), as long as the
 * ids of the bean factories match. This method sets up the serialization id to be
 * either the id provided to the scope instance, or if that is null, a hash of all the
 * bean names.
 *
 * @param beanFactory the bean factory to configure
 */
private void setSerializationId(ConfigurableListableBeanFactory beanFactory) {

    if (beanFactory instanceof DefaultListableBeanFactory) {

        String id = this.id;
        if (id == null) {
            List<String> list = new ArrayList<>(
                    Arrays.asList(beanFactory.getBeanDefinitionNames()));
            Collections.sort(list);
            String names = list.toString();
            logger.debug("Generating bean factory id from names: " + names);
            id = UUID.nameUUIDFromBytes(names.getBytes()).toString();
        }

        logger.info("BeanFactory id=" + id);
        ((DefaultListableBeanFactory) beanFactory).setSerializationId(id);

    } else {
        logger.warn("BeanFactory was not a DefaultListableBeanFactory, so RefreshScope beans "
                + "cannot be serialized reliably and passed to a remote JVM.");
    }

}
 
开发者ID:zouzhirong,项目名称:configx,代码行数:33,代码来源:GenericScope.java

示例4: instantiateComponent

import org.springframework.beans.factory.support.DefaultListableBeanFactory; //导入依赖的package包/类
public static <T> T instantiateComponent(DefaultListableBeanFactory beanFactory, Class<T> cls, Annotation annotation) {
    T extractor;

    try {
        extractor = beanFactory.getBean(cls);
    } catch (BeansException e) {
        try {
            extractor = (T) beanFactory.getBean(cls.getName());
        } catch (BeansException e1) {
            BeanDefinitionBuilder beanDefinition = BeanDefinitionBuilder.genericBeanDefinition(cls.getName());
            beanFactory.registerBeanDefinition(cls.getName(), beanDefinition.getBeanDefinition());
            extractor = (T) beanFactory.getBean(cls.getName());
        }
    }
    return extractor;
}
 
开发者ID:onepiecex,项目名称:mq-aliyun,代码行数:17,代码来源:ArgumentExtractors.java

示例5: loadBeanDefinitions

import org.springframework.beans.factory.support.DefaultListableBeanFactory; //导入依赖的package包/类
/**
 * Loads the bean definitions via an XmlBeanDefinitionReader.
 * @see org.springframework.beans.factory.xml.XmlBeanDefinitionReader
 * @see #initBeanDefinitionReader
 * @see #loadBeanDefinitions
 */
@Override
protected void loadBeanDefinitions(DefaultListableBeanFactory beanFactory) throws BeansException, IOException {
	// Create a new XmlBeanDefinitionReader for the given BeanFactory.
	XmlBeanDefinitionReader beanDefinitionReader = new XmlBeanDefinitionReader(beanFactory);

	// Configure the bean definition reader with this context's
	// resource loading environment.
	beanDefinitionReader.setEnvironment(getEnvironment());
	beanDefinitionReader.setResourceLoader(this);
	beanDefinitionReader.setEntityResolver(new ResourceEntityResolver(this));

	// Allow a subclass to provide custom initialization of the reader,
	// then proceed with actually loading the bean definitions.
	initBeanDefinitionReader(beanDefinitionReader);
	loadBeanDefinitions(beanDefinitionReader);
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:23,代码来源:XmlWebApplicationContext.java

示例6: loadBeanDefinitions

import org.springframework.beans.factory.support.DefaultListableBeanFactory; //导入依赖的package包/类
/**
 * Loads the bean definitions via an XmlBeanDefinitionReader.
 * @see org.springframework.beans.factory.xml.XmlBeanDefinitionReader
 * @see #initBeanDefinitionReader
 * @see #loadBeanDefinitions
 */
@Override
protected void loadBeanDefinitions(DefaultListableBeanFactory beanFactory) throws BeansException, IOException {
	// Create a new XmlBeanDefinitionReader for the given BeanFactory.
	XmlBeanDefinitionReader beanDefinitionReader = new XmlBeanDefinitionReader(beanFactory);

	// Configure the bean definition reader with this context's
	// resource loading environment.
	beanDefinitionReader.setEnvironment(this.getEnvironment());
	beanDefinitionReader.setResourceLoader(this);
	beanDefinitionReader.setEntityResolver(new ResourceEntityResolver(this));

	// Allow a subclass to provide custom initialization of the reader,
	// then proceed with actually loading the bean definitions.
	initBeanDefinitionReader(beanDefinitionReader);
	loadBeanDefinitions(beanDefinitionReader);
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:23,代码来源:AbstractXmlApplicationContext.java

示例7: refreshBeanFactory

import org.springframework.beans.factory.support.DefaultListableBeanFactory; //导入依赖的package包/类
/**
 * This implementation performs an actual refresh of this context's underlying
 * bean factory, shutting down the previous bean factory (if any) and
 * initializing a fresh bean factory for the next phase of the context's lifecycle.
 */
@Override
protected final void refreshBeanFactory() throws BeansException {
	if (hasBeanFactory()) {
		destroyBeans();
		closeBeanFactory();
	}
	try {
		DefaultListableBeanFactory beanFactory = createBeanFactory();
		beanFactory.setSerializationId(getId());
		customizeBeanFactory(beanFactory);
		loadBeanDefinitions(beanFactory);
		synchronized (this.beanFactoryMonitor) {
			this.beanFactory = beanFactory;
		}
	}
	catch (IOException ex) {
		throw new ApplicationContextException("I/O error parsing bean definition source for " + getDisplayName(), ex);
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:25,代码来源:AbstractRefreshableApplicationContext.java

示例8: buildInternalBeanFactory

import org.springframework.beans.factory.support.DefaultListableBeanFactory; //导入依赖的package包/类
/**
 * Build an internal BeanFactory for resolving target beans.
 * @param containingFactory the containing BeanFactory that originally defines the beans
 * @return an independent internal BeanFactory to hold copies of some target beans
 */
protected DefaultListableBeanFactory buildInternalBeanFactory(ConfigurableBeanFactory containingFactory) {
	// Set parent so that references (up container hierarchies) are correctly resolved.
	DefaultListableBeanFactory internalBeanFactory = new DefaultListableBeanFactory(containingFactory);

	// Required so that all BeanPostProcessors, Scopes, etc become available.
	internalBeanFactory.copyConfigurationFrom(containingFactory);

	// Filter out BeanPostProcessors that are part of the AOP infrastructure,
	// since those are only meant to apply to beans defined in the original factory.
	for (Iterator<BeanPostProcessor> it = internalBeanFactory.getBeanPostProcessors().iterator(); it.hasNext();) {
		if (it.next() instanceof AopInfrastructureBean) {
			it.remove();
		}
	}

	return internalBeanFactory;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:23,代码来源:AbstractBeanFactoryBasedTargetSourceCreator.java

示例9: getApplicationContext

import org.springframework.beans.factory.support.DefaultListableBeanFactory; //导入依赖的package包/类
/**
 * Provides a static, single instance of the application context.  This method can be
 * called repeatedly.
 * <p/>
 * If the configuration requested differs from one used previously, then the previously-created
 * context is shut down.
 * 
 * @return Returns an application context for the given configuration
 */
public synchronized static ConfigurableApplicationContext getApplicationContext(ServletContext servletContext, String[] configLocations)
{
	AbstractApplicationContext ctx = (AbstractApplicationContext)BaseApplicationContextHelper.getApplicationContext(configLocations);
	
	CmisServiceFactory factory = (CmisServiceFactory)ctx.getBean("CMISServiceFactory");
	
	DefaultListableBeanFactory dlbf = new DefaultListableBeanFactory(ctx.getBeanFactory());
	GenericWebApplicationContext gwac = new GenericWebApplicationContext(dlbf);
	servletContext.setAttribute(GenericWebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, gwac);
       servletContext.setAttribute(CmisRepositoryContextListener.SERVICES_FACTORY, factory);
	gwac.setServletContext(servletContext);
	gwac.refresh();

	return gwac;
}
 
开发者ID:Alfresco,项目名称:alfresco-data-model,代码行数:25,代码来源:WebApplicationContextLoader.java

示例10: registerSchedulerTriggerBean

import org.springframework.beans.factory.support.DefaultListableBeanFactory; //导入依赖的package包/类
/**
 * 
 * @param acf
 * @param sch
 * @return
 */
private Trigger registerSchedulerTriggerBean(DefaultListableBeanFactory acf, AbstractJob sch) {
    //注册JobDetail
    String jobDetailBeanName = sch.getJobName() + "JobDetail";
    if (context.containsBean(jobDetailBeanName)) {
        throw new RuntimeException("duplicate jobName[" + sch.getJobName() + "] defined!!");
    }
    BeanDefinitionBuilder beanDefBuilder = BeanDefinitionBuilder
        .genericBeanDefinition(MethodInvokingJobDetailFactoryBean.class);
    beanDefBuilder.addPropertyValue("targetObject", sch);
    beanDefBuilder.addPropertyValue("targetMethod", "execute");
    beanDefBuilder.addPropertyValue("concurrent", false);
    acf.registerBeanDefinition(jobDetailBeanName, beanDefBuilder.getRawBeanDefinition());

    //注册Trigger
    String triggerBeanName = sch.getJobName() + "Trigger";
    beanDefBuilder = BeanDefinitionBuilder.genericBeanDefinition(CronTriggerFactoryBean.class);
    beanDefBuilder.addPropertyReference("jobDetail", jobDetailBeanName);
    beanDefBuilder.addPropertyValue("cronExpression", sch.getCronExpr());
    beanDefBuilder.addPropertyValue("group", groupName);
    acf.registerBeanDefinition(triggerBeanName, beanDefBuilder.getRawBeanDefinition());

    logger.info("register scheduler task [{}] ok!!", sch.getJobName());
    return (Trigger) context.getBean(triggerBeanName);

}
 
开发者ID:warlock-china,项目名称:azeroth,代码行数:32,代码来源:SchedulerFactoryBeanWrapper.java

示例11: makeMethodTrigger

import org.springframework.beans.factory.support.DefaultListableBeanFactory; //导入依赖的package包/类
public static BeanFactory makeMethodTrigger ( Object o, String method ) throws Exception {
    DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
    RootBeanDefinition caller = new RootBeanDefinition();

    caller.setFactoryBeanName("obj");
    caller.setFactoryMethodName(method);
    Reflections.setFieldValue(caller.getMethodOverrides(), "overrides", new HashSet<>());
    bf.registerBeanDefinition("caller", caller);

    Reflections.getField(DefaultListableBeanFactory.class, "beanClassLoader").set(bf, null);
    Reflections.getField(DefaultListableBeanFactory.class, "alreadyCreated").set(bf, new HashSet<>());
    Reflections.getField(DefaultListableBeanFactory.class, "singletonsCurrentlyInCreation").set(bf, new HashSet<>());
    Reflections.getField(DefaultListableBeanFactory.class, "inCreationCheckExclusions").set(bf, new HashSet<>());
    Reflections.getField(DefaultListableBeanFactory.class, "logger").set(bf, new NoOpLog());
    Reflections.getField(DefaultListableBeanFactory.class, "prototypesCurrentlyInCreation").set(bf, new ThreadLocal<>());

    @SuppressWarnings ( "unchecked" )
    Map<String, Object> objs = (Map<String, Object>) Reflections.getFieldValue(bf, "singletonObjects");
    objs.put("obj", o);
    return bf;
}
 
开发者ID:mbechler,项目名称:marshalsec,代码行数:22,代码来源:SpringUtil.java

示例12: buildAppContext

import org.springframework.beans.factory.support.DefaultListableBeanFactory; //导入依赖的package包/类
public static ApplicationContext buildAppContext(ApplicationContext parent, Stream<TestBean> beans, Collection<BeanFactoryPostProcessor> postProcessors) {
	final DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();
	final GenericApplicationContext applicationContext = new GenericApplicationContext(beanFactory, parent);

	postProcessors.forEach(applicationContext::addBeanFactoryPostProcessor);

	beans.forEach(entry -> {
		final String factoryBean = entry.getName() + "_factory";
		beanFactory.registerSingleton(factoryBean, (Supplier<Object>) entry::getBean);
		beanFactory.registerBeanDefinition(entry.getName(), BeanDefinitionBuilder
				.rootBeanDefinition(entry.getBean() != null ? entry.getBean().getClass() : Object.class)
				.setFactoryMethodOnBean("get", factoryBean)
				.getBeanDefinition());
	});

	applicationContext.refresh();

	return applicationContext;
}
 
开发者ID:pchudzik,项目名称:springmock,代码行数:20,代码来源:ApplicationContextCreator.java

示例13: should_register_mock_definitions_when_destination_bean_does_not_exists

import org.springframework.beans.factory.support.DefaultListableBeanFactory; //导入依赖的package包/类
@Test
public void should_register_mock_definitions_when_destination_bean_does_not_exists() {
	//given
	final DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();
	final DoubleDefinition mockDefinition = DoubleDefinitionTestFactory.doubleDefinition(Service.class);

	//when
	new DoubleContextBuilder()
			.withMock(mockDefinition)
			.doProcess(beanFactory);

	//then
	assertEquals(
			singleton(mockDefinition.getName()),
			allDefinitionNames(beanFactory));
	assertMockWillBeCreatedByDoubleFactory(beanFactory.getMergedBeanDefinition(mockDefinition.getName()));
}
 
开发者ID:pchudzik,项目名称:springmock,代码行数:18,代码来源:DoubleRegisteringProcessorTest.java

示例14: should_replace_bean_definition_with_mock_definition_when_destination_bean_exists_match_by_name

import org.springframework.beans.factory.support.DefaultListableBeanFactory; //导入依赖的package包/类
@Test
public void should_replace_bean_definition_with_mock_definition_when_destination_bean_exists_match_by_name() {
	//given
	final DoubleDefinition mockDefinition = DoubleDefinitionTestFactory.doubleDefinition(Service.class);
	final DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();
	beanFactory.registerBeanDefinition(mockDefinition.getName(), beanDefinition(Service.class));

	//when
	new DoubleContextBuilder()
			.withMock(mockDefinition)
			.doProcess(beanFactory);

	//then
	assertEquals(
			singleton(mockDefinition.getName()),
			allDefinitionNames(beanFactory));
	assertMockWillBeCreatedByDoubleFactory(beanFactory.getMergedBeanDefinition(mockDefinition.getName()));
}
 
开发者ID:pchudzik,项目名称:springmock,代码行数:19,代码来源:DoubleRegisteringProcessorTest.java

示例15: DefaultListableBeanFactory

import org.springframework.beans.factory.support.DefaultListableBeanFactory; //导入依赖的package包/类
@Test
public void should_replace_bean_definition_with_mock_definition_when_destination_bean_exists_in_parent_bean_factory_match_by_name() {
	//given
	final DoubleDefinition mockDefinition = DoubleDefinitionTestFactory.doubleDefinition(Service.class);
	final DefaultListableBeanFactory parentFactory = new DefaultListableBeanFactory();
	final DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory(parentFactory);
	parentFactory.registerBeanDefinition(mockDefinition.getName(), beanDefinition(Service.class));

	//when
	new DoubleContextBuilder()
			.withMock(mockDefinition)
			.doProcess(beanFactory);

	//then
	assertEquals(
			singleton(mockDefinition.getName()),
			allDefinitionNames(beanFactory));
	assertMockWillBeCreatedByDoubleFactory(beanFactory.getMergedBeanDefinition(mockDefinition.getName()));
}
 
开发者ID:pchudzik,项目名称:springmock,代码行数:20,代码来源:DoubleRegisteringProcessorTest.java


注:本文中的org.springframework.beans.factory.support.DefaultListableBeanFactory类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。