在工作中使用到spring的mvc框架,分为controller/service/dao三个层次。偶尔会用到servlet替换掉controller,这就遇到如何在servlet中使用注入到spring上下文中的service bean。
通过查询相关资料,可以在servlet的初始化方法中调用spring的方法进行注入
同时需要在当前的servlet中加上需要注入的类型实例对应的字段,如下所示
这样就可以在servlet的post或者get方法中使用testAppService实例了。
来源:
在工作中使用到spring的mvc框架,分为controller/service/dao三个层次。偶尔会用到servlet替换掉controller,这就遇到如何在servlet中使用注入到spring上下文中的service bean。
通过查询相关资料,可以在servlet的初始化方法中调用spring的方法进行注入
同时需要在当前的servlet中加上需要注入的类型实例对应的字段,如下所示
这样就可以在servlet的post或者get方法中使用testAppService实例了。
来源:http://blog.csdn.net/bestree007/article/details/52171004
参考:http://blog.csdn.net/l1028386804/article/details/45696707