Welcome to OStack Knowledge Sharing 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 Answer

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...