6

Learning Spring Boot as a replacement for some C/C++ daemons. My goal was to have a single project compiled to a single jar/war. Then use multiple shell scripts to simply start the one I want via command line. I'm using Eclipse Kepler to develop and test the individual Spring Boot applications, and noticed an unwanted behavior. With 4 Spring Boot application classes in the same package, if I start any one of them using an Eclipse launch configuration, all 4 start up in the same Spring Boot. I suspect because all of them have the @SpringBootApplication annotation, and starting one causes Spring Boot to "scan" the current package and sub-packages.

My question, is there a way to have multiple Spring Boot applications in the same package? Do I just create a ControllerApplication with a single @SpringBootApplication and pass in the daemon name I want to start and go from there? Or some other options? Or do I need to create a separate project for each daemon? tia, adym

1 Answer 1

13

You could annotate your Spring Boot Application with @ComponentScan's excludeFilters

@ComponentScan(basePackages = "your.package", 
               excludeFilters = @Filter(SpringBootApplication.class)) 

You may have many dependency issues from this point on, you can resolve them using the same principle.

However

This may work inside your IDE, but the generated spring boot jar will only have a single main class attribute. Because of this, even if you find workarounds, I believe you should either :

  • package each spring boot application in its own maven project;
  • OR have a single Spring Boot application with multiple Spring profiles.

Take a look at these other answers to launch your spring boot application with multiple spring profiles:

1
  • Thx Alex! I think in the interest of simplicity I'm just going to use separate projects per Spring Boot Application. Commented Sep 26, 2016 at 20:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.