如何解決spring中同一個類裡面方法之間呼叫的時候註解失效的問題
阿新 • • 發佈:2018-12-15
參考部落格:https://blog.csdn.net/z55887/article/details/81073450 @RestController public class Test { @Autowired ApplicationContext context; private static final Logger log = LoggerFactory.getLogger(Test.class); @GetMapping("/1") public String myProperties1() { //為了讓非同步註解生效,重新獲取bean Test test = context.getBean(Test.class); test.printOut(); System.out.println(222222222); return "Hello World!!!!!!!!!!!!!!"; } //在同一個類中,一個方法呼叫另外一個有註解(比如@Async,@Transational)的方法,註解失效 @Async void printOut() { log.info("------------------------"); try { Thread.sleep(5000); } catch (InterruptedException e) { e.printStackTrace(); } System.out.println(11111111); } }