【问题标题】:Unable to integrate Factory Pattern along with Spring-Swagger无法将工厂模式与 Spring-Swagger 集成
【发布时间】:2015-12-09 08:22:57
【问题描述】:

我已经按照 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)

我已通过多种资源尝试了所有可能的方法,但无法找到解决方案。谁能帮我解决这个问题?

【问题讨论】:

  • 你能把你试过的代码贴出来吗?

标签: spring-mvc dependency-injection autowired swagger-ui springfox


【解决方案1】:

您需要在 ComponentScan 路径中提供正确的根路径。我遇到过同样的问题;在我修复了 ComponentScan 路径后,它现在按预期工作。

【讨论】:

  • 感谢您的回复。我试过删除@componentScan,但还是不行。我们是否需要将@componentScan@Configuration 一起添加?
  • @Karthik - 不要删除 componentScan,提供正确的根路径。
  • 感谢您在根路径上添加@componentScan 后的工作。可能会扫描内置控制器。
猜你喜欢
  • 1970-01-01
  • 2014-02-24
  • 2020-01-21
  • 1970-01-01
  • 1970-01-01
  • 2011-05-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多