首先在webservice指定发布的路径类中实现 ServletContextListener,
例如:
import javax.servlet.ServletContextEvent; import javax.servlet.ServletContextListener; public class ILockService implements ServletContextListener{
static IUserRecordService userRecordService; @Override public void contextInitialized(ServletContextEvent sce) { userRecordService = WebApplicationContextUtils.getWebApplicationContext(sce.getServletContext()).getBean(IUserRecordService.class); } @Override public void contextDestroyed(ServletContextEvent servletContextEvent) { } public String invoke(String xmlData) { //解决该处userRecordService为null的问题 UserRecord user = userRecordService.queryUserById(Id); } }
然后在web.xml中监听该类,添加如下:
<listener> <description>ILockService</description> <listener-class>com.cn.hnust.webservice.server.ILockService</listener-class> </listener>
好的,这样就可以搞定了!