Need help setting up a multilevel Maven/Spring project
I'm relatively new to IntelliJ but excited about how it can potentially help my team manage a large project which uses Spring. I tried to read over the IntelliJ Spring documentation here https://www.jetbrains.com/help/idea/spring.html Even though I've been working with Spring for several years, I found the documentation confusing and had a hard time applying it to my use case.
Our project consists of about 30 grandchild Maven projects and over 10 years of code. As I am only one member of the team, I am limited in my influence to restructure it. We've divided the project so that Freemarker templates go into one Maven project/jar file, Spring config files might be in another, a Spring web app with the web.xml file might be in yet another, and bean definitions might be in a fourth. There are other jars shared throughout our organization, under the same grandparent Maven project but under a different parent project, which contain additional Spring beans and config files. The webapp can see all of these, because the jars are all visible on the classpath. However when I try to navigate the Spring structure in IntelliJ, it cannot find the config files and beans I'm looking for.
I have just spent several hours putting together a smaller sample project that illustrates what I'm seeing and what I think is the essential issue I need help with. It is still a Maven project with a child and grandchild level, but the children are very small. I have not attempted to configure the IntelliJ settings for Spring at all, so as not to confuse anyone with non-default settings that might take a look at it.
https://github.com/kden/maven-multilevel-spring-example
What I'm asking is, for a project like this, how would I set up IntelliJ to find the definitions for the classes and objects referenced in myproject-beans.xml, and how would I set up IntelliJ to find the autowiring for the objects in ExampleController.java. Is it possible?


Please sign in to leave a comment.
The main problem I see with your setup is that beans and bean sources/classes are packaged in different modules *without* having necessary dependencies between them. So now in organization-config bean definitions in organization-beans.xml refer to "unresolved" classes (org.example.Person) from organization-code module.Similar for myproject-config vs myproject-code.
When I add dependency on corresponding "code" module in each "config" module, @Autowired Dog in ExampleController is correctly resolved.
If you don't want to add compile-dependency, runtime will work as well. But I'd highly, highly recommend to put configs in same module as beans.
Thank you very much for looking at this project. You say you are adding dependencies, are you adding dependencies in the pom files or in the Spring config files? I am guessing in the pom files since you mention compile/runtime dependencies. Could you be specific with what code you added?
Keep in mind this is a model for an issue in a much larger project, evolved over many years, and moving config sections around will be a time consuming process and is not something I can do as easily as in this example project.
What it may come down to is, is there a way to get IntelliJ to find Spring dependencies on the classpath?
By adding dependencies, I mean adding compile/runtime dependencies between these modules, so they will need to be modelled in Maven.
Basically, your spring.xml must not contain any unresolved references to any classes, otherwise Spring support will always lead to wrong/missing beans.