java从@WebService获取对springbean的引用
我正在使用CXF从wsdl生成web服务。 生成的web服务具有注释@WebService 如何从web服务获取对Springbean的引用? 我所有的SpringBean都用@Service注释,我可以访问它们 在我的web应用程序中。如何从web服务访问它们
我尝试了以下方法:
public class TestWSImpl implements TestWSSoap{
@Resource
public WebServiceContext wsContext;
@Override
public String getTest() {
ServletContext servletContext= (ServletContext) wsContext.getMessageContext().get(MessageContext.SERVLET_CONTEXT);
ApplicationContext context = WebApplicationContextUtils.getWebApplicationContext(servletContext);
return "Test";
}
}
但是getWebApplicationContext方法返回null
当我用getRequiredWebApplicationContext替换getWebApplicationContext时 我收到一条错误消息:未找到WebApplicationContext:未注册ContextLoaderListener
有人有主意吗
谢谢 阿隆
# 1 楼答案
那是很久以前的事了。 我正在查看我的代码,我发现我使用了以下方法 这应该是春天的开始:
}
如果它能解决你的问题,请告诉我
# 2 楼答案
如果您使用的是JUnit4.4或更高版本,那么可以使用Spring2.5JUnit注释注入它。这里有一个例子
http://hamletdarcy.blogspot.com/2008/12/autowired-junit-tests-with-spring-25.html
当然,不用说,这种方法要求测试启动时web服务在web上下文中运行。你做到了吗
您还可能更喜欢使用SOAP UI.测试基于WSDL的服务