@Component // 注入为spring bean public class TestMsg{ private static final Logger logger = LoggerFactory.getLogger(TestMsg.class); @Autowired private TestService testService; private static TestMsg testMsg; // 保存初始化时注入到的testService public void handlerMessage(MessageVO message) { testMsg.testService.doSomething(); // 用testMsg里set的testService去执行service方法 } @PostConstruct public void init() { testMsg = this; testMsg.testService= this.testService; } }