1
votes
public class PartnershipMaintenanceFunction
{
    final Logger logger = LoggerFactory.getLogger( PartnershipMaintenanceFunction.class );

    @Autowired
    PartnershipMaintenanceController partnershipMaintenanceServiceController;

    public RetrievePartnershipResponse retrievePartnership( Message<RetrievePartnershipRequest> messageRequest )
    {
        RetrievePartnershipRequest retrievePartnershipRequest = messageRequest.getPayload();

        MessageHeaders header = messageRequest.getHeaders();

        return partnershipMaintenanceServiceController.retrievePartnership( retrievePartnershipRequest );

    }

}

controller class

@RestController
@Api( "Partnership Maintainence" )
public class PartnershipMaintenanceController
{
    final Logger logger = LoggerFactory.getLogger( PartnershipMaintenanceController.class );

    @Autowired
    PartnershipService partnershipService;

    public void setPartnershipService( PartnershipService partnershipService )
    {
        this.partnershipService = partnershipService;
    }


    @GET
    @Path( "/retrievePartnershipRequest" )
    @ApiOperation( "Retrieve Partnership" )
    public RetrievePartnershipResponse retrievePartnership( RetrievePartnershipRequest request )
    {
        return partnershipService.retrievePartnership( request );

    }
}



public class PartnershipMaintenanceFunction
{
    final Logger logger = LoggerFactory.getLogger( PartnershipMaintenanceFunction.class );

    @Autowired
    PartnershipMaintenanceController partnershipMaintenanceServiceController;


}

controller class

@RestController
@Api( "Partnership Maintainence" )
public class PartnershipMaintenanceController
{
    final Logger logger = LoggerFactory.getLogger( PartnershipMaintenanceController.class );

    @Autowired
    PartnershipService partnershipService;

    public void setPartnershipService( PartnershipService partnershipService )
    {
        this.partnershipService = partnershipService;
    }

Error creating bean with name 'partnershipMaintenanceController': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: com.cgi.bkifs.bso.prime.partnership.maintainence.service.PartnershipService com.cgi.bkifs.rest.service.controller.PartnershipMaintenanceController.partnershipService; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.cgi.bkifs.bso.prime.partnership.maintainence.service.PartnershipService] 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)}

3
Can anyoone please guide me.....Tushar Sharma
Is there PartnershipService class in your classpath?Marcin Piotrowski
There is no Spring bean of type PartnershipService. That's what the error is telling you. Show us why you think there is one.JB Nizet
Ensure you have a PartnershipService class that's Spring managed. Also your PartnershipMaintenanceFunction should be annotated with @Component or @ServiceKihats

3 Answers

1
votes

Probably you forgot to making PartnershipService as Spring Bean.

   @Component
   public class PartnershipService{}
1
votes

If the bean ( PartnershipService ) is Normal bean then you can use @Component
If the bean (PartnershipService ) is service bean ( Service layer ) then you can use @service

Information about @Component, @Service, @Controller, and @Repository annotation do in Spring Framework:
@Component is a generic stereotype for any Spring-managed component or bean.
@Repository is a stereotype for the persistence layer.
@Service is a stereotype for the service layer.
@Controller is a stereotype for the presentation layer (spring-MVC).

0
votes

The error messages says:

Could not autowire field: com.cgi.bkifs.bso.prime.partnership.maintainence.service.PartnershipService

Assuming that you already declared a class PartnershipService and it has the @Service annotation it is likely that you did not define the component scan.

Either add

@ComponentScan(basePackages = "com.cgi.bkifs.bso.prime.partnership") or in older versions use the xml file to define the scope of component scan:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:context="http://www.springframework.org/schema/context"
       xsi:schemaLocation="http://www.springframework.org/schema/beans 
           http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
           http://www.springframework.org/schema/context
           http://www.springframework.org/schema/context/spring-context-3.0.xsd">

     <context:component-scan base-package="com.cgi.bkifs.bso.prime.partnership"/>

</beans>