[英]Autowire placeholder property in prototype bean
In my application I have a property defined as below: 在我的应用程序中,我具有如下定义的属性:
<bean id="DD6Config"
class="org.springframework.beans.factory.config.PropertiesFactoryBean">
<property name="locations">
<list>
<value>file:${file_path}/DD6Config.properties
</value>
</list>
</property>
</bean>
I have a prototype bean (DMO_TranslationLabel) where I am autowiring this property (DD6Config). 我有一个原型bean(DMO_TranslationLabel),在其中自动装配此属性(DD6Config)。
@ANT_MapiTable(name = "TRANSLATION_LABEL")
@Component
@Scope(value = BeanDefinition.SCOPE_PROTOTYPE)
public class DMO_TranslationLabel
{
@Autowired
private Properties DD6Config;
/*
business logic here
*/
if(DD6Config.containsKey("enable_translation"))
{
// Business logic is property is found
}
}
But I am not able to get the bean. 但是我不能拿豆子。 DD6Config bean is
null
when accessed at if block. 在if块中访问时,DD6Config bean为
null
。
However, I can get the bean from the application context. 但是,我可以从应用程序上下文中获取bean。
ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
DD6Config = (Properties) context.getBeanStatic("DD6Config");
Why can't I autowire the property in prototype bean? 为什么不能在原型bean中自动装配属性? I am able to autowire the same when I change DMO_TranslationLabel to a singleton bean.
当我将DMO_TranslationLabel更改为单例bean时,可以自动进行接线。
I tried your example and it's working fine for both scopes. 我尝试了您的示例,并且在两个范围内都可以正常工作。
Are you using custom ApplicationContext? 您正在使用自定义ApplicationContext吗? For instance
getBeanStatic
is not a method of ApplicationContext . 例如,
getBeanStatic
不是ApplicationContext的方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.