我使用springBootVersion ='1.5.2.RELEASE',奇怪的是它在执行测试JavaMainApplicationTests时为类PlainFileReader提供以下例外,它只是发生对于某些类。我将PlainFileReader重构到其他类正在工作的包中,并在JavaMainApplicationTests注释中添加了@componentScan,但奇怪的是,只有一些类不工作,原因可能是什么,以及如何排除故障。春季启动1.5.2不是加载一些类抛出不满意的依赖异常
@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时出错:通过字段'parsers'表示的不满意的依赖关系;嵌套的异常是org.springframework.beans.factory.NoSuchBeanDefinitionException:没有可用的'com.PlainFileReader'类型的合格bean可用:预计至少有1个bean有资格作为autowire候选者。依赖注释:{@ org.springframework.beans.factory.annotation.Autowired(required = true)}
Parsers类是用@Component注解还是正在为此创建一个bean? –
是的,我正在创建这个bean。 – Curious