Java – the spring boot cannot parse placeholders in strings

I run spring boot on the embedded Tomcat server through Maven and MVN clean install spring boot: run But every time I run it, I get this error:

The error is related to these two lines of code:

@Value("${language}")
private String language;

That language sign is in my application Properties, as follows:

application. properties

language=java
logging.level.org.springframework=TRACE

This is a confusing part: when I run the build without the spring boot: run command, it is built correctly, and I can run the built jar without any problems I only encountered this problem when I tried to run on an embedded Tomcat server

I can bypass this by doing this in my code:

@Value("${language:java}")
private String language;

But this doesn't make sense to me because spring should automatically start from application Read the default value from the properties file

Edit: as people have pointed out, the application will not be read at all when running on the embedded Tomcat server properties. Is there any way to force it to read the file or why it may not read it? It works when deployed to an external application server instead of an embedded application server

Thank you for your help

Solution

Fix the section by adding these lines to POM under < Resources >

<resource>
     <directory>src/main/resources</directory>
     <filtering>true</filtering>
     <includes>
          <include>**/*.properties</include>
     </includes>
</resource>

What I don't fully understand is the need to do so

a) I can run it on an external application server without adding this line, and the application reads the application Just properties

b) I can run the application as a stand-alone Java application in eclipse (that is, I don't need to build the application through Maven) and it reads the application Just properties

c) Shouldn't spring start read it by default? (as shown in the above two cases?)

Thank you for your help I hope it will help others

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>