@PostConstruct
如果需要初始化一些配置,但初始化过程中又依赖被注入的属性,可以选择用@PostConstruct。
根据指定路径,扫描被@TableName修饰的类: Demo
@ConfigurationProperties(prefix = "test.postConstruct")
public class PostConstructDemo {
/**
* 扫描路径
*/
private String scanPath;
private Set<Class<?>> classList;
@PostConstruct
private void scanClass(){
// 根据指定路径,被@TableName修饰的类
if (StringUtil.isNotBlank(scanPath)) {
classList = ClassUtil.getClass4Annotation(scanPath, TableName.class);
}
}
}