Scene:
Two configuration files: db.properties,application.properties
Referencing db.properties in the database configuration
class= "..." > <property name= "Locations" > <list> <value>classpath*:/ db.properties</value> <value>file:/etc/db.properties</value> </list> </ Property> </bean>
At this time, application.properties inside the property will not be loaded into the, if you use @value, will be reported could not resolve placeholder
@Controller Public class Firstcontroller { @Value ("${welcome.message}") private String test; @RequestMapping ("/GETW") public String Welcome (map<string, object> Model) { //model.put ("message", this.message); System.out.println (test); return "My"; }}
Such use will be reported could not resolve placeholder
Solve:
Put the contents of the db.properties into the application.properties, and then cite this side:
class= "..." > <property name= "Locations" > <list> <value>classpath*:/ application.properties</value> <value>file:/etc/application.properties</value> </ list> </property> </bean>
Or two of files are loaded
class= "..." > <property name= "Locations" > <list> <value>classpath* :/application.properties</value> <value>classpath*:/db.properties</value> < value>file:/etc/application.properties</value> </list> </property> </ Bean>
The reason is spring's loading mechanism: the spring container uses the discovery mechanism of reflection scanning, A bean that detects a org.springframework.beans.factory.config.PropertyPlaceholderConfigurer in the spring container stops the remaining propertyplaceholderconf Igurer Scan (Spring 3.1 already uses propertysourcesplaceholderconfigurer instead of propertyplaceholderconfigurer), so depending on the order of loading, The second property-placeholder configured is not loaded by spring, so the placeholder is not parsed when you use @value injection
Springboot annotation @value always reported could not resolve placeholder problem