SPRING MVC - Use an external file as @PropertySource

拥有回忆 提交于 2019-12-06 05:47:48

I have a similar problem to solve some time back, what we did was that we provided the external directory path to properties file at time of server boot up, as follows:

import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import org.springframework.context.annotation.PropertySources;

@Configuration
@PropertySources({@PropertySource("${ext.properties.dir:classpath:}/db.properties") })
public class ApplicationConfig {

}

For XML based configuration:

<context:property-placeholder
        location="${ext.properties.dir:classpath:}/db.properties" order="-1"
        ignore-unresolvable="true" ignore-resource-not-found="true" />

And supplied ext.properties.dir value from application-server/jvm as per environment:

For instance, for DEV:

-Dext.properties.dir=file:/dev/Library/Tomcat/webapps/config/

and for PROD:

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