Spring mvc 如何使用spring设置属性?
我正在学习spring框架,但我被困在属性设置中 我尝试用属性设置一些测试值,但值总是默认值 这是我的密码 message.propertiesSpring mvc 如何使用spring设置属性?,spring-mvc,Spring Mvc,我正在学习spring框架,但我被困在属性设置中 我尝试用属性设置一些测试值,但值总是默认值 这是我的密码 message.properties name=James applicationContext.xml(还添加了util文件) 它不会产生任何错误消息,我可以运行,但当我打印该名称时,它总是空的,我想它不会因为某种原因连接,我不知道 我也尝试了@Value(“#{msgProperties['name']}”),但结果是一样的 我错过了什么吗?解决它 因为我赶时间,所以我用new关键字
name=James
applicationContext.xml(还添加了util文件)
它不会产生任何错误消息,我可以运行,但当我打印该名称时,它总是空的,我想它不会因为某种原因连接,我不知道
我也尝试了@Value(“#{msgProperties['name']}”),但结果是一样的
我错过了什么吗?解决它
因为我赶时间,所以我用new关键字创建MessageService实例。
通过bean factory获取实例使其正常工作:)添加您的项目结构截图图像
<util:properties id="msgProperties" location="classpath:config/properties/message.properties"/>
@Component
public class MessageService {
@Value("#{msgProperties.name}")
private String name;
public String getName() {
return this.name;
}
}