2016-11-29 153 views
0

我有多模塊彈簧引導應用程序。我組織它的方式是它包含web模塊,它具有@SpringBootApplication類以及web模塊(例如batch-jobs模塊)導入的其他幾個模塊。Spring引導:子模塊依賴關係

web模塊包含從春天啓動所有的依賴關係:

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的依賴就像這裏:

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配置採取的。哪種方法更好?你能在這裏提供建議嗎?

回答

1

我覺得這個職位將被標記爲輿論基礎,但無論如何:

我對這個話題的想法是(或曾經是,如果我看春季啓動)明確命名您積極利用依賴於你的代碼(和具體模塊)。但是在彈簧啓動時,你不能真的匹配模塊對'項目'中啓動器的依賴。當然你也許知道一個starter-web將會提供mvc來查看項目之外的依賴關係,但是我認爲如果項目 增長和維護它們,那麼其他人很難進入定義。

純粹的推測:如果一個初學者得到一個更新並且刪除一個依賴於另一個的依賴性會怎樣?舉個例子:vendorA提供的LibX現在切換到了vendorB。在模塊配置中,您仍然對vendorA具有JSON依賴關係,但vendorB也會進入您的類路徑。如果它們具有相同的完全限定名...(bam)

您可以提取幾個啓動程序,如持久性相關的持久性模塊和Web到Web等。

+0

是的。你對錯過依賴關係是正確的,但無論如何我會在更新Spring引導版本時檢查構建功能。 –