mattshma / bigdata

hadoop,hbase,storm,spark,etc..

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

springboot junit 读取 application.yml 时返回 null

mattshma opened this issue · comments

在执行 mvn clean package 时,发现对于 application.yml 中的自定义字段,返回的都是 null。google 查了下,Spring Boot properties in 'application.yml' not loading from JUnit Test,可能需要添加 ContextConfiguration,试了下,没用。

仔细查看了代码,发现 test 目录下的 application.yml 下没有自定义字段,从 main 下的 application-dev.yml 拷贝过来即可。

.
|  
`--  main
|        |
|        `-- resources
|                   |
|                   `-- config
|                           |
|                           |-- application.yml
|                           |-- application-dev.yml
|                           `-- application-prod.yml 
|
`-- test
          |
         `-- resources
                |
                `-- config
                         |
                         `-- application.yml