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