Spring Integration Test:在依赖模块中找不到类的bean

时间:2014-05-12 00:43:20

标签: java spring maven spring-mvc

我的project结构看起来像

project/pom.xml
       /external_services/pom.xml
                         /ifs/pom.xml
                             /src/main/java/
                                           /IFSClient.java
                                           /RestIFSClient.java

                             /src/test/java/
                                           /MockIFSClient.java
       /inventory/pom.xml
                 /business/pom.xml
                             /src/main/java/InventorySummary.java
                 /services/pom.xml
                             /src/main/java/InventorySummaryResource.java
                 /integration/pom.xml
                             /src/main/java/InventoryIT.java

IFSClient 看起来像

@Component
public interface IFSClient {

    @Nonnull
    InventoryPriceDetail getInventoryAndPrice(@Nonnull final IFSRequestPresentation ifsRequestPresentation);
}

MockIFSClient RestIFSClient 详细了解此方法的返回方式

InventorySummaryManager 看起来像

@Component
public class InventorySummaryManager {
    private final IFSClient ifsClient;

    @Autowired
    public InventorySummaryManager(@Nonnull final IFSClient ifsClient) {
        this.ifsClient = ifsClient;
    }

    @Nonnull
    public InventorySummaryPresentation getSummary(@Nonnull final InventorySummaryPresentation inventorySummaryRequest) {
        final InventoryPriceRequest inventoryPriceRequest = new InventoryPriceRequest(inventorySummaryRequest.getStartDate(),
                inventorySummaryRequest.getEndDate(), inventorySummaryRequest.getNetworkId());

        final IFSRequestPresentation ifsRequestPresentation = getIfsRequestPresentation(inventoryPriceRequest);
        final InventoryPriceDetail inventoryPriceDetail = ifsClient.getInventoryAndPrice(ifsRequestPresentation);
        return getInventorySummaryResponse(inventorySummaryRequest, inventoryPriceDetail.getInvListPriceData().get(0));
    }

business / pom.xml 依赖于ifs

<dependency>
    <groupId>com.org.inventory_api.external_services</groupId>
    <artifactId>ifs</artifactId>
    <version>${project.version}</version>
</dependency>

integration / pom.xml 具有依赖性

<dependency>
    <groupId>com.org.inventory_api.external_services</groupId>
    <artifactId>ifs</artifactId>
    <version>${project.version}</version>
</dependency>
<dependency>
    <groupId>com.org.inventory_api.inventory</groupId>
    <artifactId>services</artifactId>
    <version>${project.version}</version>
    <type>war</type>
</dependency>

services / pom.xml 具有依赖性

<dependency>
    <groupId>com.org.inventory_api.inventory</groupId>
    <artifactId>business</artifactId>
    <version>${project.version}</version>
</dependency>

当我使用maven-cargo-plugin开始集成测试时,我将日志中的错误视为

[INFO] [talledLocalContainer] SEVERE: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
[INFO] [talledLocalContainer] org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'inventorySummaryManager' defined in URL [jar:file:/Users/harith/IdeaProjects/inventory_api/inventory/integration/target/cargo/configurations/tomcat7x/webapps/inventory/WEB-INF/lib/business-1.0-SNAPSHOT.jar!/com/org/inventory_api/inventory/business/InventorySummaryManager.class]: Unsatisfied dependency expressed through constructor argument with index 0 of type [com.org.inventory_api.external_services.ifs.IFSClient]: : No qualifying bean of type [com.org.inventory_api.external_services.ifs.IFSClient] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@javax.annotation.Nonnull(when=ALWAYS)}; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.org.inventory_api.external_services.ifs.IFSClient] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@javax.annotation.Nonnull(when=ALWAYS)}

我不确定为什么这个bean依赖无法解决,有人可以试着纠正我吗?

1 个答案:

答案 0 :(得分:1)

我想出了

我的application-context.xml仅在

之前扫描inventory模块
<context:component-scan base-package="com.org.project.inventory"/>

我把它改成了

<context:component-scan base-package="com.org.project"/>

并且错误消失了