Maven Multi Module insists on duplicating datasource application.properties in business module

自古美人都是妖i 提交于 2019-12-04 17:34:13
suomi-dev

According to this,

It is not advisable to put application.properties in a library because there might be a clash at runtime in the application that uses it (only one application.properties is ever loaded from the classpath)

To solve this and still maintain decoupled architecture, I created another file data.properties under resources folder of product-data module and specified @PropertySource annotation in the config file. Here is the config file of product-data module. The spring.datasource properties were defined in this file. Then there was no need for spring.datasource properties in other 2 modules.

@ComponentScan
@EnableAutoConfiguration
@SpringBootConfiguration
@PropertySource(value = "data.properties")
public class NopeastiDataConfig {
    // no main needed here as this is library consumed by business layer
}

Further read here: Externalized Configuration

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!