Spring configuration in multi-module project

后端 未结 2 837
青春惊慌失措
青春惊慌失措 2021-02-05 22:13

I\'m new to Spring and got a situation that single project with multiple modules including one web module. Web module uses Spring MVC, but I was wondering if I can have main Spr

2条回答
  •  忘了有多久
    2021-02-05 22:59

    The build layout and runtime CLASSPATH are two different things. Even if you define separate applicationContext.xml files or @Configuration classes in different modules, they might get merged into a single CLASSPATH.

    That being said module1 and module2 might declare their own contexts, but since the CLASSPATH is merged at runtime, only a single main context will be created. Also if you choose to use CLASSPATH scanning in one module, it might pick-up classes (beans) annotated with @Service in other modules.

    In web module, which should also have dependencies on Spring core libraries, will also depend on spring-web, MVC and spring-security. This module will create child web context, that has access to main context but not the other way around.

    Obviously you should have only a single copy of each library in your uber-JAR (ear?)

提交回复
热议问题