spring shell component 无法使用 autowired 注入?-灵析社区

感觉对了

@ShellComponent public class SeederCommand extends Command { @Autowired private UserRepository userRepository; @ShellMethod(key = {"seed"}, value = "数据填充方法") public void run() { System.out.println(new Gson().toJson(this.userRepository.findAll())); } } 提示 `userRepository` 是 `null`。报错

阅读量:20

点赞量:0

问AI
喝一杯吧可以吗
内容没描述全,实际问题是有自动注入的类是自己通过反射进行的实例化,非spring管理,所以无法自动装配。