在springboot中我们通过配置类来加载配置信息,而在配置类中是无法加载Bean的。我们有时候需要在项目启动时加载数据库数据,这就造成无法使用配置的数据源,而spring给我们提供了一个方法,就是实现CommandLineRunner。
@Component
@Order(value = 2)
public class DroolsAutoDbRule implements CommandLineRunner {
@Autowired
private RuleLoadService ruleLoadService;
@Override
public void run(String... strings) throws Exception {
ruleLoadService.addRule();
}