我有多模块的弹簧引导应用程序。我组织它的方式是,它包含有web
类的@SpringBootApplication
模块和由web
模块导入的其他几个模块(例如,batch-jobs
模块)。
web
模块包含spring中的所有依赖项:
compile('org.springframework.boot:spring-boot-starter-batch')
compile('org.springframework.boot:spring-boot-starter-data-jpa')
compile('org.springframework.boot:spring-boot-starter-integration')
...
providedRuntime('org.springframework.boot:spring-boot-starter-tomcat')
testCompile('org.springframework.boot:spring-boot-starter-test')
etc...
我想知道我是否应该在这个模块中包含所有的spring启动依赖关系,还是最好是像下面这样的纯spring依赖关系:
dependencies {
compile 'org.springframework:spring-core'
compile 'org.springframework:spring-context'
compile 'org.springframework.integration:spring-integration-java-dsl'
compile 'org.springframework.batch:spring-batch-core'
...
testCompile 'org.springframework:spring-test'
testCompile 'org.springframework.integration:spring-integration-test'
}
这些依赖关系无论如何都是从高级dependency-management
配置中获取的。哪种方法更好?你能在这里提出建议吗?
发布于 2016-11-29 14:21:44
我认为这篇文章将被标记为基于意见的文章,但无论如何:
我在这个主题上的想法是(或者如果我看一下spring )来显式地命名您在代码中积极使用的依赖项(以及特定的模块)。但是,使用spring引导,您无法真正地将模块中的依赖项与“项目”中的启动程序相匹配。当然,您可能知道初学者web将通过查看项目之外的依赖关系来提供mvc,但我认为,如果项目增长并维护这些定义,其他人将很难进入定义。
纯粹的推测:如果一个初学者得到了一个更新,并放弃了一个依赖,而选择了另一个呢?举个例子: LibX由vendorA提供,现在切换到vendorB。您的模块配置中仍然有一个对vendorA的JSON依赖,但是类路径中也有vendorB获取。如果他们有相同的完全限定名.(Bam)
您可以提取多个启动程序,比如持久性相关的,持久性模块的,web到web的等等。
https://stackoverflow.com/questions/40866739
复制相似问题