Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring 如何组合两个项目的两个application.yml配置?_Spring_Spring Boot - Fatal编程技术网

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

Spring 如何组合两个项目的两个application.yml配置?,spring,spring-boot,Spring,Spring Boot,我有两个项目。一个只是对外部服务执行http请求的客户端。另一个是RESTAPI 客户端“”读取在其自己的应用程序.yml中配置的url,但当我在Rest API项目中向该客户端添加依赖项(通过pom.xml)时,它不再读取该属性(它为null) 我希望它从自己的application.yml中读取,这样我就有了一个默认值(如果需要,可以稍后重写)。我该怎么做 客户机的定义如下: @Component @ConfigurationProperties("app.client.notificat

我有两个项目。一个只是对外部服务执行http请求的客户端。另一个是RESTAPI

客户端“”读取在其自己的
应用程序.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
}

您需要在代码a'la@PropertySource(“classpath:/application.yml”)中明确定义该.yml文件的位置。不过,我不知道命名冲突,您需要自己进行试验。

客户端的
应用程序。在rest API应用程序中,spring boot不会根据默认值加载yml
。您需要专门加载它。@JeremyGrand我该怎么做?我认为您可以使用spring.config.location实现某些功能,但我没有时间尝试编写合适的解决方案。我希望你能应付somehow@Fabricio您需要在代码a'la@PropertySource(“classpath:/application.yml”)的某个地方显式定义该.yml文件的位置。不过,我不知道命名冲突,你需要自己尝试一下。@rorschach成功了,我只需要使用另一个名称,比如
myprojname.yml
。请你回信好让我接受吗?