Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/spring-mvc/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring mvc 如何使用spring设置属性?_Spring Mvc - Fatal编程技术网

Spring mvc 如何使用spring设置属性?

Spring mvc 如何使用spring设置属性?,spring-mvc,Spring Mvc,我正在学习spring框架,但我被困在属性设置中 我尝试用属性设置一些测试值,但值总是默认值 这是我的密码 message.properties name=James applicationContext.xml(还添加了util文件) 它不会产生任何错误消息,我可以运行,但当我打印该名称时,它总是空的,我想它不会因为某种原因连接,我不知道 我也尝试了@Value(“#{msgProperties['name']}”),但结果是一样的 我错过了什么吗?解决它 因为我赶时间,所以我用new关键字

我正在学习spring框架,但我被困在属性设置中

我尝试用属性设置一些测试值,但值总是默认值

这是我的密码

message.properties

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;
    }
}