Reputation: 4189
My question is regarding testing a multi-module Spring boot application.
I have a multi-module spring boot REST application. The application is structured as follows:
**SpringbootMainApplication
--src/main/java
--org.test
+Springbootapplicationinitializer.java //Annotated with @SpringBootApplication
--org.test.controller
--org.test.service
--org.test.dao
SpringbootModule
--src/main/java
--org.module
+SpringModuleInitializer.java //Annotated with @SpringBootApplication
--org.module.controller
--org.module.service
--org.module.dao**
The above is how my application is structured.
SpringBootMainApplication is the main project. SpringbootModule is the subproject inside SpringBootMainApplication. "SpringBootMainApplication.war" WAR will be built with "SpringbootModule.jar" inside the WAR.
I have separate test cases for both these projects. I want to make these projects individually testable. By this I mean, my test cases for SpringBootMainApplication while performing the test cases should use "Springbootapplicationinitializer.java" and my test cases for SpringBootModule while performing the test cases should use "SpringModuleinitializer.java". But when it is packaged as a WAR and the SpringModuleInitializer.java should not come into play or should have no bearing.
Is there any way by which I can achieve this? Or should I completely avoid SpringModuleInitializer.java, perform only unit tests in the module and do integration testing only using Springbootapplicationinitializer.java.
If it is of any help, I am using gradle for build and packaging.
Upvotes: 1
Views: 3076
Reputation: 357
if i understand you correctly there is no need to have the SpringModuleinitializer in src/main/java. As it is a jar dependency in your root project, you dont need it to be a spring app. I guess you want test the submodule independently,so move SpringModuleinitializer to src/main/test. It will never show up in your war then.
Upvotes: 2