如何在Spring bean中注入String属性
问题描述:
我们注入具有以下配置的简单属性:
We inject simple property with configuration as shown below :
<bean id="myService" class="com.aaa.bbb.ccc.MyServiceImpl">
<property name="myProp" value=""/>
</bean>
您将如何使用注释?
答
使用 @Value
批注。它还支持SpEL,这意味着您可以加载属性文件并具有 @Value( $ {someConfigurationProperty})
Using the @Value
annotation. It supports SpEL as well, which means you can load a properties file and have @Value("${someConfigurationProperty}")