问题
I have a bean with injected field value. It works just fine. I use annotation to ask Spring
to inject value from properties
into the bean.
public class MyBean {
@Value("${app.settings.value}")
private String value;
}
How can I do the same via XML? I've tried to inject using value="#{}"
.
<bean id="myBean" class="com.test.MyBean">
<property name="value" value="{app.settings.value}"/>
</bean>
But my approach does not work.
回答1:
Try this:
<bean id="myBean" class="com.test.MyBean">
<property name="value" value="${app.settings.value}"/>
</bean>
The syntax is the same as for java config - prefixed with the $
sign.
来源:https://stackoverflow.com/questions/34882646/spring-how-to-inject-a-property-value-into-the-bean-via-xml