我已按照this引用使用ServiceLocatorFactoryBean实现了工厂模式。
工作正常。
我正在使用swagger-springMVC(SpringFox),它也工作正常。
但是,当我尝试使用工厂模式和swagger时,它会抛出异常,
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)
我已经通过以下几种资源尝试了所有可能的方法但无法找到解决方案。有人可以帮我解决这个问题吗?
答案 0 :(得分:0)
您需要在ComponentScan路径中提供正确的根路径。我遇到过同样的问题;在我修复ComponentScan路径后,它现在按预期工作。