我有一个弹簧引导应用程序。在这个应用程序中,我已经配置了一个eCommerce系统作为弹性路径(在application.properties文件中配置弹性路径的端点url )。现在,我必须将我的spring引导应用程序交给其他一些人。将部署在tomcat服务器上。我不想给出源代码。所以我可以制作war文件,但是现在的问题是他们有自己的弹性路径eCommerce,他们想配置自己的eCommerce。
我想将一些将覆盖现有属性的属性具体化。
我的springboot应用程序有两个模块: 1)弹性路径模块,它具有弹性路径应用程序。2)销售人员-销售人员-应用程序。
现在,我必须对"C:\apache-tomcat-8.5.29\conf\ep-external.properties“文件进行外部化,这将覆盖现有的属性。现在的问题是@PropertySource正在最后一个位置加载。因此,我的外部文件无法覆盖该属性。
@SpringBootApplication
@PropertySource(value = {"classpath:application.properties", "classpath:elasticpath-application.properties", "classpath:salesforce-application.properties")
public class SpringBootDemo extends SpringBootServletInitializer implements CommandLineRunner {
private static final Logger LOG = LoggerFactory.getLogger(SpringBootDemo.class);
private ServletContext servletContext;
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
//application = application.properties("file:C:\\apache-tomcat-8.5.29\\conf\\ep-external.properties");
return application.sources(SpringBootDemo.class);
}
@Override
public void onStartup(ServletContext servletContext) throws ServletException {
this.servletContext = servletContext;
super.onStartup(servletContext);
}
public static void main(String[] args) {
SpringApplication.run(SpringBootDemo.class, args);
}
@Override
public void run(String... args) throws Exception {
}
}发布于 2018-11-14 09:53:39
是的绝对有可能。基本上,您需要的是根据需要更改属性值,而不更改jar/war。
传递jar的命令行args
将spring引导应用程序打包为jar,并将外部application.properties文件放置在任意位置,并传递与命令行参数相同的位置,如下所示:
java -jar app.jar --spring.config.location=file:<property_file_location>这将获取外部属性。
传递用于的命令行/动态args
@SpringBootApplication
class DemoApp extends SpringBootServletInitializer {
private ServletContext servletContext;
public static void main(String[] args){SpringApplication.run(DemoApp.class,args);}
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
builder = builder.properties("test.property:${test_property:defaultValue}");
return builder.sources(DemoApp.class)
}
@Override
public void onStartup(ServletContext servletContext) throws ServletException {
this.servletContext = servletContext;
super.onStartup(servletContext);
}
}此外:
如果要将完整的文件作为外部文件提供,也可以像下面这样传递属性。
.properties("spring.config.location:${config:null}")进一步解读外部化配置:https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-external-config.html
https://stackoverflow.com/questions/53297119
复制相似问题