Spring boot could not resolve placeholder in string

后端 未结 9 1098
悲哀的现实
悲哀的现实 2020-12-16 14:28

I am running spring-boot on an embedded tomcat server through maven with mvn clean install spring-boot:run. But every time I run it I get this error:

         


        
相关标签:
9条回答
  • 2020-12-16 15:02

    Were you, by chance, running this from Eclipse?

    I had the same issue and noticed that the project did not have the Maven nature. Right-clicking on the project ->Configure->Convert to Maven Project. Then right-click on the project ->Maven->Update Project solved the issue.

    0 讨论(0)
  • 2020-12-16 15:07

    I too faced a similar issue when running from IntelliJ. This worked for me : Build -> Rebuild Project.

    0 讨论(0)
  • 2020-12-16 15:08

    Here I have simplest solution that worked in my case.

    Whether it be from Java command prompt, or VM options from IDE such as eclipse or IntelliJ, try supplying the following:

    -Dspring.profiles.active=<env>
    

    This is alternative to modifying/touching the pom file mentioned above.

    0 讨论(0)
  • 2020-12-16 15:18

    I have similar issue with you, I fixed it by going

    In your pom.xml if you have multiple profile or properties, select 1 profile to be default selected

    <profiles>
            <profile>
                <id>dev</id>
                <properties>
                    <activatedProperties>dev</activatedProperties>
                </properties>
                <activation>
                    <activeByDefault>true</activeByDefault>
                </activation>
            </profile>
            <profile>
                <id>prod</id>
                <properties>
                    <activatedProperties>prod</activatedProperties>
                </properties>
            </profile>
        </profiles>
    

    Then go to your application.properties then insert this code

    spring.profiles.active=@activatedProperties@
    
    0 讨论(0)
  • 2020-12-16 15:22

    Fixed by adding these lines to the pom under the <resources> section

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

    What I don't fully understand is the need for doing this.

    a) I can run this on an external app server without having to add this line and the app reads application.properties just fine.

    b) I can run the app as a standalone java application in eclipse (i.e., without having to build the app through maven) and it reads application.properties just fine

    c) isn't spring-boot supposed to read it by default regardless? (as shown by the two cases above?)

    Thanks everyone for their help. hopefully this will help others.

    0 讨论(0)
  • 2020-12-16 15:27

    If you have set the values properly, then check if your resources folder is acting as "resources" identified by the IDE. In intelliJ you can right click on resources and select "Mark as resources root".

    0 讨论(0)
提交回复
热议问题