Spring 占位符不适用于自定义架构元素
我试图从占位符中获取一些值到自定义模式属性(cfg:merge elements'target)中,但它不起作用: somexml.xml:Spring 占位符不适用于自定义架构元素,spring,spring-mvc,dependency-injection,Spring,Spring Mvc,Dependency Injection,我试图从占位符中获取一些值到自定义模式属性(cfg:merge elements'target)中,但它不起作用: somexml.xml: <bean id="stateMachineNamingStrategy" class="com.mycompany.statemachine.hibernate.StateMachineNamingStrategy"> <property name="prefix" value="${statemachine.table_pre
<bean id="stateMachineNamingStrategy" class="com.mycompany.statemachine.hibernate.StateMachineNamingStrategy">
<property name="prefix" value="${statemachine.table_prefix}"/>
</bean>
<cfg:merge-elements id="packages-com.mycompany.statemachine" target="${session-factory-pkgs}">
<value>com.mycompany.statemachine.machine.impl</value>
</cfg:merge-elements>
为什么它不将占位符转换为它的值???以防有人遇到同样的问题: 事实证明,在我的
NamespaceHandler
中,我注册了一个新的BeanDefinition,它扩展了BeanDefinitionRegistryPostProcessor
。这些特殊的后处理器在正常的BeanFactoryPostProcessor
之前执行,以允许注册或删除BeanDefinitions。因此,无法在BeanDefinitionRegistryPostProcessor之前执行PropertyPlaceHolderConfigure(这是一个普通的BeanPostProcessor)
您可以在XmlWebApplicationContext(AbstractApplicationContext)中看到这一切。invokeBeanFactoryPostProcessors:
Map<String, BeanDefinitionRegistryPostProcessor> beanMap =
beanFactory.getBeansOfType(BeanDefinitionRegistryPostProcessor.class, true, false);
List<BeanDefinitionRegistryPostProcessor> registryPostProcessorBeans =
new ArrayList<BeanDefinitionRegistryPostProcessor>(beanMap.values());
OrderComparator.sort(registryPostProcessorBeans);
for (BeanDefinitionRegistryPostProcessor postProcessor : registryPostProcessorBeans) {
//!!!!! BeanDefinitionRegistryPostProcessors are excecuted!!!!!
postProcessor.postProcessBeanDefinitionRegistry(registry);
}
invokeBeanFactoryPostProcessors(registryPostProcessors, beanFactory);
invokeBeanFactoryPostProcessors(registryPostProcessorBeans, beanFactory);
invokeBeanFactoryPostProcessors(regularPostProcessors, beanFactory);
processedBeans.addAll(beanMap.keySet());
}
else {
// Invoke factory processors registered with the context instance.
invokeBeanFactoryPostProcessors(getBeanFactoryPostProcessors(), beanFactory);
}
// Do not initialize FactoryBeans here: We need to leave all regular beans
// uninitialized to let the bean factory post-processors apply to them!
String[] postProcessorNames =
beanFactory.getBeanNamesForType(BeanFactoryPostProcessor.class, true, false);
// Separate between BeanFactoryPostProcessors that implement PriorityOrdered,
// Ordered, and the rest.
List<BeanFactoryPostProcessor> priorityOrderedPostProcessors = new ArrayList<BeanFactoryPostProcessor>();
List<String> orderedPostProcessorNames = new ArrayList<String>();
List<String> nonOrderedPostProcessorNames = new ArrayList<String>();
for (String ppName : postProcessorNames) {
Map beanMap=
getBeansOfType(BeanDefinitionRegistryPostProcessor.class,true,false);
列出registryPostProcessorBeans=
新的ArrayList(beanMap.values());
排序(registryPostProcessorBeans);
for(BeanDefinitionRegistryPostProcessor后处理器:registryPostProcessorBeans){
//!!!!!BeanDefinitionRegistryPostProcessor已超出限制!!!!!
postProcessor.postProcessBeanDefinitionRegistry(注册表);
}
invokeBeanFactoryPostProcessors(registryPostProcessors,beanFactory);
invokeBeanFactoryPostProcessors(registryPostProcessorBeans,beanFactory);
invokeBeanFactoryPostProcessors(regularPostProcessors,beanFactory);
processedBeans.addAll(beanMap.keySet());
}
否则{
//调用在上下文实例中注册的工厂处理器。
调用BeanFactoryPostProcessors(getBeanFactoryPostProcessors(),beanFactory);
}
//不要在这里初始化FactoryBeans:我们需要保留所有常规Bean
//未初始化以使bean工厂后处理器应用于它们!
字符串[]后处理程序名称=
getBeanNamesForType(BeanFactoryPostProcessor.class,true,false);
//在实现PriorityOrdered的BeanFactory后处理器之间进行分离,
//命令,其余的。
List priorityOrderedPostProcessors=new ArrayList();
List orderedPostProcessorNames=new ArrayList();
List nonOrderedPostProcessorNames=new ArrayList();
for(字符串ppName:postProcessorNames){
Map<String, BeanDefinitionRegistryPostProcessor> beanMap =
beanFactory.getBeansOfType(BeanDefinitionRegistryPostProcessor.class, true, false);
List<BeanDefinitionRegistryPostProcessor> registryPostProcessorBeans =
new ArrayList<BeanDefinitionRegistryPostProcessor>(beanMap.values());
OrderComparator.sort(registryPostProcessorBeans);
for (BeanDefinitionRegistryPostProcessor postProcessor : registryPostProcessorBeans) {
//!!!!! BeanDefinitionRegistryPostProcessors are excecuted!!!!!
postProcessor.postProcessBeanDefinitionRegistry(registry);
}
invokeBeanFactoryPostProcessors(registryPostProcessors, beanFactory);
invokeBeanFactoryPostProcessors(registryPostProcessorBeans, beanFactory);
invokeBeanFactoryPostProcessors(regularPostProcessors, beanFactory);
processedBeans.addAll(beanMap.keySet());
}
else {
// Invoke factory processors registered with the context instance.
invokeBeanFactoryPostProcessors(getBeanFactoryPostProcessors(), beanFactory);
}
// Do not initialize FactoryBeans here: We need to leave all regular beans
// uninitialized to let the bean factory post-processors apply to them!
String[] postProcessorNames =
beanFactory.getBeanNamesForType(BeanFactoryPostProcessor.class, true, false);
// Separate between BeanFactoryPostProcessors that implement PriorityOrdered,
// Ordered, and the rest.
List<BeanFactoryPostProcessor> priorityOrderedPostProcessors = new ArrayList<BeanFactoryPostProcessor>();
List<String> orderedPostProcessorNames = new ArrayList<String>();
List<String> nonOrderedPostProcessorNames = new ArrayList<String>();
for (String ppName : postProcessorNames) {