如何组合两个项目的两个application.yml配置?

时间:2017-08-02 11:49:07

标签: spring spring-boot

我有两个项目。一个是客户端,它向外部服务发出http请求。另一个是Rest API。

客户端¹读取在其自己的application.yml中配置的URL,但是当我在Rest API项目中向此客户端添加依赖项(通过pom.xml)时,它不再读取该属性(它为null)

我希望它从自己的application.yml中读取,以便我有一个默认值(如果需要可以稍后重写)。我怎么能这样做?

¹客户端的定义如下:

@Component
@ConfigurationProperties("app.client.notification")
public class NotificationClient { 
    private String url; // comes from application.yml.
                        // Works fine in the client project,
                        // and DOESN'T in the Rest project
}

1 个答案:

答案 0 :(得分:1)

您需要在代码a' la @PropertySource(" classpath:/application.yml")的某处明确定义该.yml文件的位置。我不知道命名冲突,你需要亲自试验。