Reputation: 768
I have a single Maven project that has the "core" and the "web" pieces in it. I'm attempting to convert it into multiple modules.
I've taken the "web" packages and put them into the new project. I've added the core project as a dependency and I can reference its classes within Eclipse. The "core" project correctly shows up in WEB-INF\lib
in the "web" project when I build it.
The problem comes when classes from the "core" project are @Autowired
in the "web" project.
In this particular case, I'm autowiring a service class from "core" into one of the web service classes in the "web" project. If I add the package that the core service is in to my context:component-scan
in my "web" application config, it finds that service, but then the service references a repository, which references an entity, which is looking for an entity manager factory that I've got configured in my application-context in my "core" project.
So it seems that maybe the context:component-scan
in the "core" project isn't happening maybe? Or maybe the classes that are picked up are not being made available to the "web" project?
I'm entirely new to multi-module projects, so if anyone can get me started in the right direction to resolve this, I'd greatly appreciate it.
I'm using m2e in Eclipse with the Run Jetty Run plugin if that matters; however, I seem to have the same issues when I do a mvn jetty:run
from the command line.
Upvotes: 4
Views: 4511
Reputation: 20386
You will need to load the core module application-context from your web module application context. Otherwise it will not be aware of beans defined in the core application context.
Take a look the answers for Application context from other maven module cannot be loaded and Spring import application context from another project for proper solutions.
You can also have a look at this post nicely describing how to create a multi-module Spring project using Maven.
Upvotes: 5