CXF:java.lang.ClassNotFoundException:org.apache.cxf.transport.servlet.CXFServlet

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/22372741/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-13 15:20:53  来源:igfitidea点击:

CXF : java.lang.ClassNotFoundException: org.apache.cxf.transport.servlet.CXFServlet

javacxfwebsphere-8

提问by Vicky

I am trying to deploy a rest web service in WAS 8.0

我正在尝试在 WAS 8.0 中部署一个休息 Web 服务

The application EAR is getting installed successfully.

应用程序 EAR 安装成功。

However, both on publishing as well as on hitting the service from web browser after publishing, I am getting below error:

但是,无论是在发布时还是在发布后从 Web 浏览器点击服务时,我都收到以下错误:

[3/13/14 13:42:20:652 IST] 00000024 servlet       E com.ibm.ws.webcontainer.servlet.ServletWrapper run SRVE8052E: Logging ClassNotFoundException
                             java.lang.ClassNotFoundException: class java.lang.ClassNotFoundException: org.apache.cxf.transport.servlet.CXFServlet
at java.beans.Beans.instantiate(Beans.java:190)
at java.beans.Beans.instantiate(Beans.java:75)
at com.ibm.ws.webcontainer.servlet.ServletWrapper.run(ServletWrapper.java:1471)
at com.ibm.ws.security.util.AccessController.doPrivileged(AccessController.java:118)
at com.ibm.ws.webcontainer.servlet.ServletWrapper.loadServlet(ServletWrapper.java:1460)
at com.ibm.ws.webcontainer.servlet.ServletWrapper.load(ServletWrapper.java:1358)
at com.ibm.ws.webcontainer.filter.WebAppFilterManager.invokeFilters(WebAppFilterManager.java:982)
at com.ibm.ws.webcontainer.webapp.WebApp.handleRequest(WebApp.java:3751)
at com.ibm.ws.webcontainer.webapp.WebGroup.handleRequest(WebGroup.java:304)
at com.ibm.ws.webcontainer.WebContainer.handleRequest(WebContainer.java:962)
at com.ibm.ws.webcontainer.WSWebContainer.handleRequest(WSWebContainer.java:1662)
at com.ibm.ws.webcontainer.channel.WCChannelLink.ready(WCChannelLink.java:195)
at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleDiscrimination(HttpInboundLink.java:452)
at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleNewRequest(HttpInboundLink.java:511)
at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.processRequest(HttpInboundLink.java:305)
at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.ready(HttpInboundLink.java:276)
at com.ibm.ws.tcp.channel.impl.NewConnectionInitialReadCallback.sendToDiscriminators(NewConnectionInitialReadCallback.java:214)
at com.ibm.ws.tcp.channel.impl.NewConnectionInitialReadCallback.complete(NewConnectionInitialReadCallback.java:113)
at com.ibm.ws.tcp.channel.impl.AioReadCompletionListener.futureCompleted(AioReadCompletionListener.java:165)
at com.ibm.io.async.AbstractAsyncFuture.invokeCallback(AbstractAsyncFuture.java:217)
at com.ibm.io.async.AsyncChannelFuture.fireCompletionActions(AsyncChannelFuture.java:161)
at com.ibm.io.async.AsyncFuture.completed(AsyncFuture.java:138)
at com.ibm.io.async.ResultHandler.complete(ResultHandler.java:204)
at com.ibm.io.async.ResultHandler.runEventProcessingLoop(ResultHandler.java:775)
at com.ibm.io.async.ResultHandler.run(ResultHandler.java:905)
at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:1690)

However, the jar containing the class viz. cxf-rt-transports-http-2.7.4.jar is present inside lib directory of the WAR inside the EAR installed.

但是,包含类 viz 的 jar。cxf-rt-transports-http-2.7.4.jar 存在于安装的 EAR 内 WAR 的 lib 目录中。

What is the cause of the issue ?

问题的原因是什么?

How can I resolve it ?

我该如何解决?

Update: My web.xml is as below:

更新:我的 web.xml 如下:

<web-app>
<display-name>MyService</display-name>

<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>classpath:applicationContext.xml</param-value>
</context-param>
<listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

<servlet>
    <servlet-name>CXFServlet</servlet-name>
    <display-name>CXF Servlet</display-name>
    <servlet-class>
        org.apache.cxf.transport.servlet.CXFServlet
    </servlet-class>
    <load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
    <servlet-name>CXFServlet</servlet-name>
    <url-pattern>/rest/*</url-pattern>
</servlet-mapping>

</web-app>

采纳答案by Chris Harris

I see that you mentioned the word "publish", which hints that you might be using Eclipse, or possibly IBM's RAD or even MyEclipse Blue.

我看到您提到了“发布”这个词,这暗示您可能正在使用 Eclipse,或者可能是 IBM 的 RAD 甚至 MyEclipse Blue。

In case that's true, read on...

如果这是真的,请继续阅读...

While your .ear, generated by m2e/Maven, may have the .jar file present in the .war file, there's a chance that the .ear and .war file, generated by m2e-wtp, is missing the .jar file. m2e-wtp's generated .ear file is what's used when you publish/republish your application to WAS from within Eclipse/RAD/MyEclipse Blue.

虽然由 m2e/Maven 生成的 .ear 可能在 .war 文件中存在 .jar 文件,但由 m2e-wtp 生成的 .ear 和 .war 文件有可能缺少 .jar 文件。当您从 Eclipse/RAD/MyEclipse Blue 中将应用程序发布/重新发布到 WAS 时,会使用 m2e-wtp 生成的 .ear 文件。

Try removing the app from your local WAS, finding the location of that m2e-wtp-generated .ear file, and deleting it. From there, m2e-wtp should automatically generate a fresh .ear file if you clean your project (all associated pom, ear, war, etc.)

尝试从本地 WAS 中删除该应用程序,找到该 m2e-wtp 生成的 .ear 文件的位置,然后将其删除。从那里,如果您清理项目(所有相关的 pom、ear、war 等),m2e-wtp 应该自动生成一个新的 .ear 文件。

When you publish your app, it should find the class. I've had the same problem happen to me in the past. My suggestion has fixed the problem.

当您发布应用程序时,它应该会找到该类。过去我也遇到过同样的问题。我的建议解决了这个问题。

Other than that, you may need to set the Classloader Policy to PARENT_LAST and check that you're using a single classloader for the entire app (the 2nd set of radio buttons below the Classloader Policy radio buttons) within the WAS admin console. However, I doubt that the Classloader Policy is the issue.

除此之外,您可能需要将 Classloader Policy 设置为 PARENT_LAST 并检查您是否在 WAS 管理控制台中为整个应用程序使用单个类加载器(Classloader Policy 单选按钮下方的第二组单选按钮)。但是,我怀疑类加载器策略是问题所在。