Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
3.8k views
in Technique[技术] by (71.8m points)

java - Use separate properties file for dependency jar and main war

I have 2 Spring Boot apps. AppA is a jar that primarily acts as a service (services, external api calls, etc). AppB is a war that has AppA as a dependency.

AppA (jar) currently does not have a MySvcApplication.java file @SpringBootApplication because it is never ran on it's own and I noticed that when running AppB, that file is never ran. AppB (war) has a MyMainApplication.java file with @SpringBootApplication with scanBasePackages property.

I would like AppA and AppB to have their own properties files, and if possible, a shared properties file (inside the svc) (i.e. svc.properties, main-app.properties, common.properties).

I have read on a few ways (in-app, command-line) to change the file name (via spring.config.name) but that applies for the war (in MyMainApplication.java), but not the dependency jar.

SpringApplicationBuilder()
  .properties("spring.config.name=myproject")
  .sources(MyApplication.class)
  .run(args);

Any ideas?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Create a new property file in AppB (example svc.properties) for shared properties and include the same in application.properties of AppB spring.profiles.include=svc It should work.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...