springboot非controller类添加service

it2026-03-12  3

如下所示

@Component public class WeworkConfig { @Autowired IChatParameterService parameterService; public static WeworkConfig weworkConfig; @PostConstruct public void init() { weworkConfig = this; weworkConfig.parameterService = this.parameterService; }

在类上方加上@Component注解 然后在service下方加上public static Xxx xxx静态初使化当前类 然后再 @PostConstruct public void init() { weworkConfig = this; weworkConfig.parameterService = this.parameterService; } 将项目判定为空的service指向初始化类的service, 然后再在自己写的方法中调用weworkConfig.parameterService.getByAlias()即可

最新回复(0)