【发布时间】:2016-03-28 19:30:39
【问题描述】:
我正在寻找将在 spring 上下文中定义的属性(由 propertiesFactoryBean 提供)注入检票口组件的可能性。我知道使用 @SpringBean-Annotation 将 bean 注入组件的方式,但是属性的对应方式是什么?
我的属性的定义方式:
<bean id="myPropertiesFactory" class="org.springframework.beans.factory.config.PropertiesFactoryBean">
<property name="properties">
<props>
<prop key="mySpringProperty">mySpringProperty</prop>
</property>
</bean>
我尝试过的事情。它的工作方式通常与自定义 bean 一起使用:
@Inject
@Value("${mySpringProperty}")
使用propertiesFactory的名字来访问属性值
@Inject
@Value("$myPropertiesFactory.properties.mySpringProperty")
使用值注解
@Value("#myPropertiesFactory['mySpringProperty']")
使用 SpringBean
@SpringBean(name="myPropertiesFactory.mySpringProperty")
这些解决方案都不起作用。因此,为了获得 mySpringProperty 注入,我使用解决方法来创建一个 String 类型的 bean,当我用 SpringBean 注释组件的相应成员时,该 bean 由 wicket 正确注入,但我认为必须有更好的解决方案。
<bean id="mySpringPropertyBean" class="java.lang.String">
<constructor-arg type="java.lang.String" value="https://foobar.com" />
</bean>
注释
@SpringBean
private String mySpringPropertyBean;
【问题讨论】:
标签: spring properties dependency-injection wicket