是否有通用方法来指定 WebService 的上下文根?

发布于 2024-12-27 18:57:12 字数 2051 浏览 7 评论 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 文件中的配置参数?

谢谢!

埃里克

I'm new to writing web services, and am struggling with understanding how to specify the context root.

I've got my class annotated with

@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")

but I am not sure how to configure the context-root/path for it. I read that I could configure it as a servlet in web.xml, but that seems to be the case for a web service that is not annotate. Am I wrong? I have tried the following configuration in 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>

however, when I launch in JBoss, I get an error msg:

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)

I've read that I can configure jboss-web.xml specifically, but I assume there is a more generic way of doing this that can be applied to all app servers - isn't there? Or must I configure the service independently, depending on the AS that I am deploying to (ie: one way for Tomcat, one way for GlassFish, one way for JBoss, one way for WebSphere, etc...).

Is there an annotation I can use to specify my path for the web-service? Or a config param in the web.xml file?

Thanks!

Eric

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

从﹋此江山别 2025-01-03 18:57:12

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

Turns out that the JBoss error I was getting was due to the webservices module not being enabled. In JBoss7.0/7.1, you need to run the standalone-preview.xml config to get webservices for an out-of-box download: ie: standalone.sh --server-config=standalone-preview.xml. That eliminated the ClassCast/Servlet exception. However my question still remains if there is not a better/other way to accomplish this (perhaps via annotations) than declaring it as a servlet in web.xml.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文