How to solve springboot app start and shutdown immediately problem
When we develop multi-module springboot application,the layout is as follows:
1. The project layout
As you can see , module1 has a package named com.example.module1, and module2 has a package named com.example.module2, and module2 has reference to module1
2. The problem
Now in the module2, we want to use module1’s domain class, we autowire the class object like this:
MyTest.java in module2:
add add this to module2’s Application class to expand the module2 to component scan range.
3. Run the app
Now run the module2, we got this exception
The module2 application start and exit without any exception. why?
4. The reason
Because we add componentscan range to @SpringBootApplication ,but the range is not right, the range now:
the range com.example.module1 is not right,because it must include the com.example.module2 package. It should be :
we change the package from com.example.module1 to com.example, so it include module1 and module2 packages.
Now run test again, the exception disappeared.
You can find detail documents about the springboot here: