写了一个获取配置文件属性值的组件,spring boot启动报错信息如下:
@Component
@ConfigurationProperties(prefix = “student”)
public class Student {
// @Value("${student.s-name}")
private String sName;
private int sNo;
private Map<String,Object> maps;
private List lists;
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name ‘com.boke.studyboot20200707.Studyboot20200707ApplicationTests’: Unsatisfied dependency expressed through field ‘student’; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type ‘com.entity.Student’ available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
解决办法
在spring boot启动类加上@ComponentScan(“com.entity”)注解,运行成功。其中的ComponentScan里面的value值为我项目中组件的存放包名