简体   繁体   中英

Loading properties.yaml files from file system in spring boot

I am facing troubles loading yaml files from the file system with spring boot.

I have placed my properties.yaml files in a folder

\config\source.properties
\config\config.yml

and I am calling the jar with the command

java -jar myjar.jar --spring.config.location=\config

I'm loading the properties file like this and it works fine.

@PropertySource("${spring.config.location}/source.properties")

But the below snippet does not load the yaml properties

@Configuration
@ConfigurationProperties(prefix = "test-data")
@EnableConfigurationProperties
@Data
public class TestData {

    private Map<String, MyObject1> object1Map = new HashMap<>();

    private Map<Integer, MyObject2> object2Map= new HashMap<>();
}

Any idea what could be wrong?

try giving a '/' at the end of location parameter as mentioned here .

the parameter you mentioned: --spring.config.location=\\config will look for properties file at this location, and it must end with'/' or you can specify complete path including the file name. or By Default, it will look for application.yml or application.properties.

In your case, it must be trying to find the file 'config'

In order to use a different name for properties, you need to specify that using name. Refer this ' boot-features-external-config'

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