Spring main方法中怎么調用Dao層和Service層的方法


在web環境中,一般serviceImpl中的dao之類的數據庫連接都由容器啟動的時候創建好了,不會報錯。但是在main中,沒有這個環境,所以需要獲取環境:

ApplicationContext ctx = new FileSystemXmlApplicationContext("src/applicationContext.xml");
        PianoServiceImpl pianoService = (PianoServiceImpl) ctx.getBean("pianoServiceImpl");
//然后再調用方法
        return pianoService.getPriceByBrand(brand);


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM