Search code examples
dockerspring-bootdocker-composenetflix-feign

"org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean" Using docker


I am trying to get docker running on my AWS and using docker-compose. I run a maven build and everything builds successfully but when I do docker-compose up, I am getting this feign exception, saying my businessDelegate is not autowiring because my feign service is getting a parameter 0

Here is my delegate class

@Component
public class BusinessDelegateImpl implements BusinessDelegate{

  private ShippingService shippingService;

   @Autowired
   public void setShippingService(ShippingService shippingService) {this.shippingService = shippingService;}
/**More Methods below**/
}

Simple right? Everything is wired correctly as far as I can see. Here is my feign client class

@FeignClient("shipping")
public interface ShippingService {
    @RequestMapping(value = "/insert",
            method = RequestMethod.POST,
            produces = APPLICATION_JSON_VALUE,
            consumes = APPLICATION_JSON_VALUE)
    ResponseEntity<Shipping> insert(@RequestBody Shipping shipping);

    @RequestMapping(value = "/save",
            method = RequestMethod.PUT,
            produces = APPLICATION_JSON_VALUE,
            consumes = APPLICATION_JSON_VALUE)
    ResponseEntity<Shipping> save(@RequestBody Shipping shipping);

    @RequestMapping(value = "/cart/{cartId}",
            method = RequestMethod.GET,
            produces= MediaType.APPLICATION_JSON_VALUE)
    ResponseEntity<Shipping> findByCartId(@PathVariable("cartId") String cartId);

    @RequestMapping(value = "/invoice/{invoiceId}",
            method = RequestMethod.GET,
            produces= MediaType.APPLICATION_JSON_VALUE)
     ResponseEntity<Shipping> findByInvoiceId(@PathVariable("invoiceId") String invoiceId);

    @RequestMapping(value = "/delete/{id}",
            method = RequestMethod.DELETE)
    ResponseEntity delete(@PathVariable("id") String id);
}

I had this error locally but I fixed it by putting the variable next to the PathVariable @PathVariable("id"). Now i am getting this whenever i start up a docker in AWS. The mvn build runs too. Here is the complete Stack trace if you need it. Shopping is the name of the SprintBootApp

shopping    | org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'businessDelegateImpl': Unsatisfied dependency expressed through method 'setShippingService' parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'com.revature.service.implementation.ShippingService': FactoryBean threw exception on object creation; nested exception is java.lang.IllegalStateException: PathVariable annotation was empty on param 0.
shopping    |   at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredMethodElement.inject(AutowiredAnnotationBeanPostProcessor.java:671) ~[spring-beans-4.3.4.RELEASE.jar!/:4.3.4.RELEASE]
shopping    |   at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88) ~[spring-beans-4.3.4.RELEASE.jar!/:4.3.4.RELEASE]
shopping    |   at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:370) ~[spring-beans-4.3.4.RELEASE.jar!/:4.3.4.RELEASE]
shopping    |   at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1219) ~[spring-beans-4.3.4.RELEASE.jar!/:4.3.4.RELEASE]
shopping    |   at org.springframework.b    eans.factory.support.    AbstractAutowireCapab    leBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:551) ~[spring-beans-4.3.4.RELEASE.jar!/:4.3.4.RELEASE]
shopping    |   at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482) ~[spring-beans-4.3.4.RELEASE.jar!/:4.3.4.RELEASE]
shopping    |   at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306) ~[spring-beans-4.3.4.RELEASE.jar!/:4.3.4.RELEASE]
shopping    |   at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) ~[spring-beans-4.3.4.RELEASE.jar!/:4.3.4.RELEASE]
shopping    |   at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302) ~[spring-beans-4.3.4.RELEASE.jar!/:4.3.4.RELEASE]
shopping    |   at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197) ~[spring-beans-4.3.4.RELEASE.jar!/:4.3.4.RELEASE]
shopping    |   at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:754) ~[spring-beans-4.3.4.RELEASE.jar!/:4.3.4.RELEASE]
shopping    |   at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:866) ~[spring-context-4.3.4.RELEASE.jar!/:4.3.4.RELEASE]
shopping    |   at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:542) ~[spring-context-4.3.4.RELEASE.jar!/:4.3.4.RELEASE]
shopping    |   at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122) ~[spring-boot-1.4.2.RELEASE.jar!/:1.4.2.RELEASE]
shopping    |   at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:761) [spring-boot-1.4.2.RELEASE.jar!/:1.4.2.RELEASE]
shopping    |   at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:371) [spring-boot-1.4.2.RELEASE.jar!/:1.4.2.RELEASE]
shopping    |   at org.springframework.boot.SpringApplication.run(SpringApplication.java:315) [spring-boot-1.4.2.RELEASE.jar!/:1.4.2.RELEASE]
shopping    |   at org.springframework.boot.SpringApplication.run(SpringApplication.java:1186) [spring-boot-1.4.2.RELEASE.jar!/:1.4.2.RELEASE]
shopping    |   at org.springframework.boot.SpringApplication.run(SpringApplication.java:1175) [spring-boot-1.4.2.RELEASE.jar!/:1.4.2.RELEASE]
shopping    |   at com.revature.ApigatewayApplication.main(ApigatewayApplication.java:15) [classes!/:0.0.1-SNAPSHOT]
shopping    |   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_111]
shopping    |   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_111]
shopping    |   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_111]
shopping    |   at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_111]
shopping    |   at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:48) [apigateway.jar:0.0.1-SNAPSHOT]
shopping    |   at org.springframework.boot.loader.Launcher.launch(Launcher.java:87) [apigateway.jar:0.0.1-SNAPSHOT]
shopping    |   at org.springframework.boot.loader.Launcher.launch(Launcher.java:50) [apigateway.jar:0.0.1-SNAPSHOT]
shopping    |   at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:58) [apigateway.jar:0.0.1-SNAPSHOT]
shopping    | Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'com.revature.service.implementation.ShippingService': FactoryBean threw exception on object creation; nested exception is java.lang.IllegalStateException: PathVariable annotation was empty on param 0.
shopping    |   at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.doGetObjectFromFactoryBean(FactoryBeanRegistrySupport.java:175) ~[spring-beans-4.3.4.RELEASE.jar!/:4.3.4.RELEASE]
shopping    |   at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.getObjectFromFactoryBean(FactoryBeanRegistrySupport.java:103) ~[spring-beans-4.3.4.RELEASE.jar!/:4.3.4.RELEASE]
shopping    |   at org.springframework.beans.factory.support.AbstractBeanFactory.getObjectForBeanInstance(AbstractBeanFactory.java:1606) ~[spring-beans-4.3.4.RELEASE.jar!/:4.3.4.RELEASE]
shopping    |   at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:254) ~[spring-beans-4.3.4.RELEASE.jar!/:4.3.4.RELEASE]
shopping    |   at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202) ~[spring-beans-4.3.4.RELEASE.jar!/:4.3.4.RELEASE]
shopping    |   at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:207) ~[spring-beans-4.3.4.RELEASE.jar!/:4.3.4.RELEASE]
shopping    |   at org.springframework.beans.factory.support.DefaultListableBeanFactory.addCandidateEntry(DefaultListableBeanFactory.java:1289) ~[spring-beans-4.3.4.RELEASE.jar!/:4.3.4.RELEASE]
shopping    |   at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:1258) ~[spring-beans-4.3.4.RELEASE.jar!/:4.3.4.RELEASE]
shopping    |   at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1094) ~[spring-beans-4.3.4.RELEASE.jar!/:4.3.4.RELEASE]
shopping    |   at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1059) ~[spring-beans-4.3.4.RELEASE.jar!/:4.3.4.RELEASE]
shopping    |   at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredMethodElement.inject(AutowiredAnnotationBeanPostProcessor.java:663) ~[spring-beans-4.3.4.RELEASE.jar!/:4.3.4.RELEASE]
shopping    |   ... 27 common frames omitted
shopping    | Caused by: java.lang.IllegalStateException: PathVariable annotation was empty on param 0.
shopping    |   at feign.Util.checkState(Util.java:128) ~[feign-core-9.3.1.jar!/:na]
shopping    |   at org.springframework.cloud.netflix.feign.annotation.PathVariableParameterProcessor.processArgument(PathVariableParameterProcessor.java:49) ~[spring-cloud-netflix-core-1.2.5.RELEASE.jar!/:1.2.5.RELEASE]
shopping    |   at org.springframework.cloud.netflix.feign.support.SpringMvcContract.processAnnotationsOnParameter(SpringMvcContract.java:237) ~[spring-cloud-netflix-core-1.2.5.RELEASE.jar!/:1.2.5.RELEASE]
shopping    |   at feign.Contract$BaseContract.parseAndValidateMetadata(Contract.java:107) ~[feign-core-9.3.1.jar!/:na]

shopping    |   at org.springframework.cloud.netflix.feign.support.SpringMvcContract.parseAndValidateMetadata(SpringMvcContract.java:133) ~[spring-cloud-netflix-core-1.2.5.RELEASE.jar!/:1.2.5.RELEASE]
shopping    |   at feign.Contract$BaseContract.parseAndValidatateMetadata(Contract.java:64) ~[feign-core-9.3.1.jar!/:na]
shopping    |   at feign.hystrix.HystrixDelegatingContract.parseAndValidatateMetadata(HystrixDelegatingContract.java:34) ~[feign-hystrix-9.3.1.jar!/:na]
shopping    |   at feign.ReflectiveFeign$ParseHandlersByName.apply(ReflectiveFeign.java:146) ~[feign-core-9.3.1.jar!/:na]
shopping    |   at feign.ReflectiveFeign.newInstance(ReflectiveFeign.java:53) ~[feign-core-9.3.1.jar!/:na]
shopping    |   at feign.Feign$Builder.target(Feign.java:209) ~[feign-core-9.3.1.jar!/:na]
shopping    |   at org.springframework.cloud.netflix.feign.HystrixTargeter.target(HystrixTargeter.java:48) ~[spring-cloud-netflix-core-1.2.5.RELEASE.jar!/:1.2.5.RELEASE]
shopping    |   at org.springframework.cloud.netflix.feign.FeignClientFactoryBean.loadBalance(FeignClientFactoryBean.java:146) ~[spring-cloud-netflix-core-1.2.5.RELEASE.jar!/:1.2.5.RELEASE]
shopping    |   at org.springframework.cloud.netflix.feign.FeignClientFactoryBean.getObject(FeignClientFactoryBean.java:167) ~[spring-cloud-netflix-core-1.2.5.RELEASE.jar!/:1.2.5.RELEASE]
shopping    |   at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.doGetObjectFromFactoryBean(FactoryBeanRegistrySupport.java:168) ~[spring-beans-4.3.4.RELEASE.jar!/:4.3.4.RELEASE]
shopping    |   ... 37 common frames omitted
shopping    |
shopping exited with code 1

If you need more information, please let me know. I have be stuck on this for hours


Solution

  • I found the issue. I needed to remove the images first and recreate it. For anyone that doesn't know how to delete images, first you need to delete the container such as

    docker rm <Container Id>

    or remove them all at once

    docker rm $(docker ps -a -q)

    then you can delete the images

    docker rmi <Image Id>

    or remove all at once

    docker rmi $(docker images -a -q)

    To get the Ids, enter docker ps -a for container Ids and docker images for image Ids

    Alternatively, if you have docker-compose installed, you can rebuild the images with the commands

    docker-compose up -d --build

    docker-compose pull

    docker-compose up