I am developing an application with Spring boot and deploying multiple WARs to an external tomcat. I want to register a shareable bean with these WARs when tomcat starts.
I use: Java8, Spring boot(2.5.5) and Tomcat9
Bean I want to be shared by Apps:
public class TestData {
private String username;
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
}
SampleApp(There are multiple apps that Autowire an instance of TestData in the same way):
@SpringBootApplication
@RestController
public class App extends SpringBootServletInitializer {
@Autowired
TestData testData;
public static void main(String[] args) {
SpringApplication.run(App.class, args);
}
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(App.class);
}
@RequestMapping(value = "SampleApp1", method = RequestMethod.GET)
public String getUsername() {
return testData.getUsername();
}
}