错因:
自定义配置类无法被springboot接管,扫描不到配置类
xxx即为你定义的包名
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
***************************
APPLICATION FAILED TO START
***************************
Description:
Field config in com.xxx.xxx.xxx required a bean of type 'com.xxx.xxx.xxx' that could not be found.
The injection point has the following annotations:
- @org.springframework.beans.factory.annotation.Autowired(required=true)
Action:
Consider defining a bean of type 'com.xxx.xxx.xxx' in your configuration.
解决:
在你自定义配置的类中打上注解@Component,即使用springboot来帮你接管此类,如果需要自启动项目后,springboot立即帮你配置,你还得去yaml或properties配置类中配置你需要的东西,这样你的配置类才能够被扫描到
/**
* 这是你自定义配置的类
*/
@Data
@NoArgsConstructor
@AllArgsConstructor
@Component
@ConfigurationProperties(prefix = "config")
public class CloopenConfig {
private String name;
private Integer age;
}
# 自定义类配置
config:
name: 张三
age: 20
SringBoot中yaml、自定义配置类配置好后,即可自启动项目后,不会出错,springboot自动帮你扫描配置