Question

My project structure looks like

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 looks like

@Component
public interface IFSClient {

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

MockIFSClient and RestIFSClient has details about how this method will return

InventorySummaryManager looks like

@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 has dependency on ifs as

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

integration/pom.xml has dependency as

<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>

and services/pom.xml has dependency as

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

when I start my integration tests using maven-cargo-plugin, I see errors in logs as

[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)}

I am not sure why this bean dependency can not be resolved, can someone please try to correct me?

Was it helpful?

Solution

I figured that out

My application-context.xml was scanning only inventory module before

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

I changed it to

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

and the error was gone

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top