Could not resolve placeholder ‘XXX‘ in string value “${XXX}

启动springboot项目时遇到Could not resolve placeholder XXX in string value "${XXX}";

错误一:target目录中没有springboot的核心配置文件

解决一:在pom.xml中写入<resource>标签,使配置文件能被解析。

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

错误二:配置文件中自定义属性无法被解析

解决二:在启动类中将PropertySourcesPlaceholderConfigurer放到IOC容器中

@Bean
    public static PropertySourcesPlaceholderConfigurer placeholderConfigurer() {

        PropertySourcesPlaceholderConfigurer c = new PropertySourcesPlaceholderConfigurer();

        c.setIgnoreUnresolvablePlaceholders(true);

        return c;
    }
然后我又发现以上问题出在,resources文件夹不知道怎么了变成了普通文件夹,改成资源文件夹就OK了
启动springboot项目时遇到Could not resolve placeholder XXX in string value "${XXX}"; 错误一:target目录中没有springboot的核心配置文件 解决一:在pom.xml中写入 标签,使配置文件能被解析。         src/main/resources **/*.yml true src/main/java **/*.yml true 错误二:配置文件中自定义属性无法被解析 解决二:在启动类中将PropertySourcesPlaceholderConfigurer放到IOC容器中 @Bean public static PropertySourcesPlaceholderConfigurer placeholderConfigurer() { PropertySourcesPlaceholderConfigurer c = new PropertySourcesPlaceholderConfigurer(); c.setIgnoreUnresolvablePlaceholders(true); return c; } 然后我又发现以上问题出在,resources文件夹不知道怎么了变成了普通文件夹,改成资源文件夹就OK了
经验分享 程序员 微信小程序 职场和发展