0

I have implemented factory pattern using ServiceLocatorFactoryBean by following this reference.

It is working fine.

I am using swagger-springMVC (SpringFox), It is also working fine.

But, when I am trying to use factory pattern along with swagger then It is throwing below exceptions,

Could not autowire field: org.test.MyProject.MyFactory org.test.MyProject.controller.MyController.myFactory; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [org.test.MyProject.MyFactory] 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)}
    org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:561)

I have tried in all possible ways by following several resources but unable to find a solution. Can anyone please help me resolve this issue?

Community
  • 1
  • 1
kumar
  • 481
  • 3
  • 7
  • 18

1 Answers1

0

You need to provide a proper root path in your ComponentScan path. I have faced same kind of issue; after I fixed the ComponentScan path, it is working now as expected.

elixenide
  • 44,308
  • 16
  • 74
  • 100
  • Thank you for your response. I have tried removing `@componentScan` but still didn't work. Do we need to add `@componentScan` along with `@Configuration`? – kumar Feb 01 '16 at 11:53
  • @Karthik - Don't remove componentScan, provide proper root path. – Mahesh Babu Feb 01 '16 at 11:55
  • Thank you its working after adding the `@componentScan` along the root path. May be it will scan for controllers inbuilt. – kumar Feb 01 '16 at 11:59