Servlet中调用Spring bean报错
解决方法:
Service层
@Service(value="webuserManagerImpl")
public class WebuserManagerImpl implements WebuserManager {
...
}
在Servlet的doPost方法中加入
WebApplicationContext wc = WebApplicationContextUtils.getWebApplicationContext(request.getSession().getServletContext());
WebuserManager service = (WebuserManager) wc.getBean("webuserManagerImpl");
service.方法
解决方法:
Service层
@Service(value="webuserManagerImpl")
public class WebuserManagerImpl implements WebuserManager {
...
}
在Servlet的doPost方法中加入
WebApplicationContext wc = WebApplicationContextUtils.getWebApplicationContext(request.getSession().getServletContext());
WebuserManager service = (WebuserManager) wc.getBean("webuserManagerImpl");
service.方法
本文详细介绍了在Servlet中调用Springbean时遇到的问题及解决方法,通过实例展示了如何正确获取并使用WebApplicationContext来实现组件的注入。
1万+

被折叠的 条评论
为什么被折叠?



