![](/img/trans.png)
[英]Spring Boot maven multimodule project - unit testing (application context)
[英]Spring Boot Multi Project Maven Application Context Error
我正在與Maven進行多項目安裝。 一切都使用Spring Boot和Annotations。
我正在使用一個項目進行數據訪問。 配置文件如下:
@Configuration
@EnableJpaRepositories(basePackages = { "de.bvk.infra.g_portal.dataaccess.Repository" })
@EntityScan
public class DataConfiguration {
}
存儲庫用於帶有@Autowired
測試中。 這運行良好,我可以在Eclipse中運行測試,也可以使用mvn clean install
運行測試。
我有第二個“服務”項目,該項目取決於“數據訪問”項目。 配置如下所示:
@Import({DataConfiguration.class})
@Configuration
public class ServiceTestConfiguration {
@Autowired
DataConfiguration dataConfiguration;
@Autowired
BenutzerRepository benutzerRepository;
....
我可以在Eclipse中運行服務項目的所有測試,並且工作正常。
當我嘗試使用Maven運行項目時,出現了ApplicationContextError
:
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException:
No qualifying bean of type [de.bvk.infra.g_portal.dataaccess.repository.BenutzerRepository]
found for dependency: expected at least 1 bean which qualifies as autowire
candidate for this dependency. Dependency annotations:
{@org.springframework.beans.factory.annotation.Autowired(required=true)}
at org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoSuchBeanDefinitionException(DefaultListableBeanFactory.java:1301)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1047)
...
您能告訴我為什么Maven的行為不同於Eclipse嗎?
Eclipse比Maven具有更多有限的依賴概念。 特別是,它不考慮作用域,因此您可以引用測試作用域中的類,例如,從您的普通類中引用。 我建議從使用mvn dependency:tree
,以確保您在適當的范圍內包含了您認為的內容,然后將org.springframework.data
日志記錄記錄到DEBUG
以查看正在注冊的存儲庫。
顯然,這是一個簡單的錯誤。
我不得不改變
@EnableJpaRepositories(basePackages = { "de.bvk.infra.g_portal.dataaccess.Repository" })
成
@EnableJpaRepositories(basePackages = { "de.bvk.infra.g_portal.dataaccess.repository" })
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.