靜態方法中調用spring容器中的對象

demo如下:

public class ControllerTest {
	@Autowired
    TestService testService ;
	//2 建一個靜態的本類
    private static ControllerTest controllerTest ;
    
	public ControllerTest () {
        controllerTest  = this;
        controllerTest.testService = this.testService ;
    }

 	@AfterClass
    public static void doAfter() {   
       	ControllerTest.testService.deleteByPrimaryKey(ID);
    }
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章