0

我是编写 Web 服务的新手,并且正在努力理解如何指定上下文根。

我的班级用

@Service 
@javax.jws.WebService(endpointInterface=  "com.domain.clientservices.lendingsimulation.model.v1.LendingSimulationServicePortType", targetNamespace="http://www.domain.com/ClientServices/LendingSimulation/V1.2", serviceName="LendingSimulationService", portName="LendingSimulationServicePort")

但我不确定如何为其配置上下文根/路径。我读到我可以将它配置为 web.xml 中的 servlet,但对于没有注释的 Web 服务似乎就是这种情况。我错了吗?我在 web.xml 中尝试了以下配置:

<servlet>
    <description>This is the description for the LendingSimulation Service</description>
    <display-name>Lending Simulation Service</display-name>
    <servlet-name>LendingSimulationService</servlet-name>
    <servlet-class>com.domain.clientservices.lendingsimulation.service.LendingSimulationServiceImpl</servlet-class>
</servlet>
<servlet-mapping>
    <servlet-name>LendingSimulationService</servlet-name>
    <url-pattern>/WebService</url-pattern>
</servlet-mapping>

但是,当我在 JBoss 中启动时,我收到一条错误消息:

17:39:33,710 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/LendingSimulationService].[LendingSimulationService]] (http--127.0.0.1-8080-2) Allocate exception for servlet LendingSimulationService: java.lang.ClassCastException: com.domain.clientservices.lendingsimulation.service.LendingSimulationServiceImpl incompatible with javax.servlet.Servlet
    at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1156) [jbossweb-7.0.1.Final.jar:7.0.2.Final]
    at org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:952) [jbossweb-7.0.1.Final.jar:7.0.2.Final]
... (omitted for brevity)

我读过我可以专门配置 jboss-web.xml,但我认为有一种更通用的方法可以应用于所有应用程序服务器 - 不是吗?或者我必须独立配置服务,具体取决于我要部署到的 AS(即:Tomcat 的一种方式,GlassFish 的一种方式,JBoss 的一种方式,WebSphere 的一种方式等......)。

是否有可以用来指定 Web 服务路径的注释?还是 web.xml 文件中的配置参数?

谢谢!

埃里克

4

1 回答 1

0

原来,我得到的 JBoss 错误是由于未启用 webservices 模块。在 JBoss7.0/7.1 中,您需要运行standalone-preview.xml 配置来获取 web 服务以进行开箱即用的下载:即:standalone.sh --server-config=standalone-preview.xml。这消除了 ClassCast/Servlet 异常。但是,如果没有比在 web.xml 中将其声明为 servlet 更好/其他方法来完成此操作(可能通过注释),我的问题仍然存在。

于 2012-08-15T20:33:46.740 回答