I have a really difficult problem with application.properties
file because I can not read properly from this file with java spring. The simple source code is given below. Thank you in advance.
application.properties file
message.username=john12345
Messages.java
@Value("${message.username}")
private String username;
It throws a FileNotFoundException
and shows that the value is always null
.
您应该在Spring上下文中配置property-placeholder
:
<context:property-placeholder location="classpath*:my.properties"/
Your Messages class seems to be a POJO that is not managed by Spring. Only inside instances that are controlled by spring you can read application properties.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.