Tomcat Not reading Spring-Boot Application Properties

前端 未结 4 1448
慢半拍i
慢半拍i 2020-12-05 18:02

I\'m fairly new to spring/java and have been checking out spring-boot for a project I have at work. I\'ve been following guides and finally have a (semi) working web app MVC

4条回答
  •  孤街浪徒
    2020-12-05 18:40

    The problem is that you attempt to use a @Value annotation inside your @Configuration class. From the JavaDoc of the @PropertySource:

    In order to resolve ${...} placeholders in definitions or @Value annotations using properties from a PropertySource, one must register a PropertySourcesPlaceholderConfigurer. This happens automatically when using in XML, but must be explicitly registered using a static @Bean method when using @Configuration classes.

    e.g. add the following lines to the @Configuration class:

    @Bean
    public static PropertySourcesPlaceholderConfigurer propertyPlaceholderConfigurer() {
        return new PropertySourcesPlaceholderConfigurer();
    }
    

    However, in your example, a more suitable approach is to move the @Configuration annotation from the GreetingController class (it does not contain any configuration) to the Application class. Since the Application class does not contain any @Value annotation it should work without the suggested addition of the static PropertySourcesPlaceholderConfigurer bean.

提交回复
热议问题