【问题标题】:spring boot 1.5.2 is not loading some classes throwing Unsatisfied dependency exceptionspring boot 1.5.2 没有加载一些抛出 Unsatisfied 依赖异常的类
【发布时间】:2017-03-07 06:20:44
【问题描述】:

我正在使用 springBootVersion = '1.5.2.RELEASE',奇怪的是它在执行测试 JavaMainApplicationTests 时为类 PlainFileReader 提供了以下异常,它只发生在某些类中。我将 PlainFileReader 重构到其他类正在工作的包中,并在 JavaMainApplicationTests 注释中添加了@componentScan,但奇怪的是只有一些类不工作,可能是什么原因以及如何解决它。

@Component
public class Graph<T> {

    @Autowired
    private PlainFileReader pjr;

    private Vertex<T> root;

    private ArrayList<Vertex<T>> vertices = new ArrayList<>();

......

@RunWith(SpringRunner.class)
@SpringBootTest
@TestPropertySource(properties = "debug=true")
@ComponentScan("com.*")
public class JavaMainApplicationTests 

.......

@Component
public class PlainFileReader {

    @Autowired
    private Parsers parsers;

......

创建名称为“plainFileReader”的 bean 时出错:通过字段“解析器”表达的依赖关系不满足;嵌套异常是 org.springframework.beans.factory.NoSuchBeanDefinitionException:没有“com.PlainFileReader”类型的合格 bean 可用:预计至少有 1 个有资格作为自动装配候选者的 bean。依赖注解:{@org.springframework.beans.factory.annotation.Autowired(required=true)}

【问题讨论】:

  • Parsers 类是用 @Component 注释的,还是你正在为此创建一个 bean?
  • 是的,我正在创建 bean。

标签: java spring-boot


【解决方案1】:

我的问题得到了解决,但不确定确切的原因,在创建我使用 com.test1 包创建的 spring boot 项目时,如果我在 com.test1 中创建任何类都可以工作,但如果我在 com.test1 中创建。这些课程不起作用。

【讨论】:

    猜你喜欢
    • 2016-12-21
    • 2022-10-24
    • 2021-12-24
    • 2016-09-26
    • 2019-09-19
    • 1970-01-01
    • 2016-07-10
    • 2017-10-03
    • 2020-02-05
    相关资源
    最近更新 更多