本文整理汇总了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;
}
示例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);
}
示例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.");
}
}
示例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;
}
示例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);
}
示例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);
}
示例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);
}
}
示例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;
}
示例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;
}
示例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);
}
示例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;
}
示例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;
}
示例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()));
}
示例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()));
}
示例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()));
}