简体   繁体   中英

Spring boot ignores “ignoreUnresolvablePlaceholders” = true

I'm having a problem with my Spring Boot application ignoring my ignoreUnresolvablePlaceHolders set to true in my config.xml file.

I have these options explicitly set:

<property name="ignoreUnresolvablePlaceholders" value="true" />
<!-- <property name="localOverride" value="false" /> -->
<property name="ignoreResourceNotFound" value="true" />

It works fine in a Junit but when I run my app as a Spring Boot it throws a Caused by: java.lang.IllegalArgumentException: Could not resolve placeholder on startup.

Everything started to fail when I added Spring Profiles like this:

<beans profile="default,dev">

Any help would be very much appreciated...

By default if SpringBoot is unable to read the properties file then it will throw error. In case you want it to ignore the unresolvable property sources and not throw any error then set attribute ignoreResourceNotFound to true or set attribute ignoreUnresolvablePlaceHolders to true as below.

@Configuration

@PropertySource(name="unknown",
value="classpath:${unresolvable}/unknown.properties",

                ignoreResourceNotFound=true)

public class SpringPropertySourceIgnoreUnresolvableErrorExample {

//....

}

For more information, you can refer below link https://www.javarticles.com/2016/01/spring-propertysources-annotation-example.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM