Java spring does not read properly values from application.properties

787 views Asked by At

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.

2

There are 2 answers

1
SergeiK On

You should configure property-placeholder in your spring context:

<context:property-placeholder location="classpath*:my.properties"/
0
yamenk On

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.