gpt4 book ai didi

cxf - 在 cxf Servlet 上找不到资源类

转载 作者:行者123 更新时间:2023-12-01 01:30:16 30 4
gpt4 key购买 nike

我创建了一个非常简单的基于 cxf 的非 spring Servlet,它加载了一个 javax.ws.rs.Application类型。

这是 web.xml:

<?xml version="1.0" encoding="UTF-8"?>

<web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
version="2.5">

<servlet>
<servlet-name>CXFServlet</servlet-name>
<servlet-class>
org.apache.cxf.jaxrs.servlet.CXFNonSpringJaxrsServlet
</servlet-class>
<init-param>
<param-name>javax.ws.rs.Application</param-name>
<param-value>
com.mycomp.cxf.TestApplication
</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
<servlet-name>CXFServlet</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>

</web-app>

这是应用程序:
public class TestApplication extends Application
{
private final Set<Class<?>> classes = new HashSet<Class<?>>();
private final Set<Object> singletons = new HashSet<Object>();

public TestApplication() throws ServletException
{

}

@Override
public Set<Class<?>> getClasses()
{
return classes;
}

@Override
public Set<Object> getSingletons()
{
return singletons;
}
}

Servlet 加载失败的原因是:“找不到资源类”,我不知道为什么,因为在 Application 中有一组空的类应该没问题。

这是完整的堆栈跟踪:
org.apache.cxf.jaxrs.AbstractJAXRSFactoryBean                          - No resource classes found
org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/test] - StandardWrapper.Throwable
org.apache.cxf.service.factory.ServiceConstructionException
at org.apache.cxf.jaxrs.JAXRSServerFactoryBean.create(JAXRSServerFactoryBean.java:122)
at org.apache.cxf.jaxrs.servlet.CXFNonSpringJaxrsServlet.createServerFromApplication(CXFNonSpringJaxrsServlet.java:304)
at org.apache.cxf.jaxrs.servlet.CXFNonSpringJaxrsServlet.loadBus(CXFNonSpringJaxrsServlet.java:72)
at org.apache.cxf.transport.servlet.AbstractCXFServlet.init(AbstractCXFServlet.java:78)
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1172)
at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:992)
at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:4058)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4371)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:791)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:771)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:525)
at com.springsource.osgi.webcontainer.tomcat.TomcatServletContainer.startWebApplication(TomcatServletContainer.java:120)
at com.springsource.osgi.webcontainer.internal.StandardWebContainer$StandardWebApplication.start(StandardWebContainer.java:100)
at com.springsource.osgi.webcontainer.extender.WebContainerBundleCustomizer.addingBundle(WebContainerBundleCustomizer.java:25)
at org.osgi.util.tracker.BundleTracker$Tracked.customizerAdding(BundleTracker.java:440)
at org.osgi.util.tracker.AbstractTracked.trackAdding(AbstractTracked.java:261)
at org.osgi.util.tracker.AbstractTracked.track(AbstractTracked.java:233)
at org.osgi.util.tracker.BundleTracker$Tracked.bundleChanged(BundleTracker.java:413)
at org.eclipse.osgi.framework.internal.core.BundleContextImpl.dispatchEvent(BundleContextImpl.java:919)
at org.eclipse.osgi.framework.eventmgr.EventManager.dispatchEvent(EventManager.java:227)
at org.eclipse.osgi.framework.eventmgr.ListenerQueue.dispatchEventSynchronous(ListenerQueue.java:149)
at org.eclipse.osgi.framework.internal.core.Framework.publishBundleEventPrivileged(Framework.java:1349)
at org.eclipse.osgi.framework.internal.core.Framework.publishBundleEvent(Framework.java:1300)
at org.eclipse.osgi.framework.internal.core.BundleHost.startWorker(BundleHost.java:380)
at org.eclipse.osgi.framework.internal.core.AbstractBundle.start(AbstractBundle.java:284)
at org.eclipse.osgi.framework.internal.core.AbstractBundle.start(AbstractBundle.java:276)
at com.sap.core.js.deployer.watchservice.WARDeployer.deploy(WARDeployer.java:142)
at com.sap.core.js.deployer.watchservice.FileSystemEventsListener.onChange(FileSystemEventsListener.java:26)
at com.springsource.util.io.FileSystemChecker.notifyListeners(FileSystemChecker.java:182)
at com.springsource.util.io.FileSystemChecker.check(FileSystemChecker.java:145)
at com.sap.core.js.deployer.watchservice.WatchTask.run(WatchTask.java:29)
at java.lang.Thread.run(Thread.java:679)
Caused by: javax.ws.rs.WebApplicationException
at org.apache.cxf.jaxrs.AbstractJAXRSFactoryBean.checkResources(AbstractJAXRSFactoryBean.java:238)
at org.apache.cxf.jaxrs.JAXRSServerFactoryBean.create(JAXRSServerFactoryBean.java:85)
... 31 more
10:41:54,580 [ERROR] org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/test] - Servlet /test threw load() exception
javax.ws.rs.WebApplicationException
at org.apache.cxf.jaxrs.AbstractJAXRSFactoryBean.checkResources(AbstractJAXRSFactoryBean.java:238)
at org.apache.cxf.jaxrs.JAXRSServerFactoryBean.create(JAXRSServerFactoryBean.java:85)
at org.apache.cxf.jaxrs.servlet.CXFNonSpringJaxrsServlet.createServerFromApplication(CXFNonSpringJaxrsServlet.java:304)
at org.apache.cxf.jaxrs.servlet.CXFNonSpringJaxrsServlet.loadBus(CXFNonSpringJaxrsServlet.java:72)
at org.apache.cxf.transport.servlet.AbstractCXFServlet.init(AbstractCXFServlet.java:78)
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1172)
at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:992)
at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:4058)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4371)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:791)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:771)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:525)
at com.springsource.osgi.webcontainer.tomcat.TomcatServletContainer.startWebApplication(TomcatServletContainer.java:120)
at com.springsource.osgi.webcontainer.internal.StandardWebContainer$StandardWebApplication.start(StandardWebContainer.java:100)
at com.springsource.osgi.webcontainer.extender.WebContainerBundleCustomizer.addingBundle(WebContainerBundleCustomizer.java:25)
at org.osgi.util.tracker.BundleTracker$Tracked.customizerAdding(BundleTracker.java:440)
at org.osgi.util.tracker.AbstractTracked.trackAdding(AbstractTracked.java:261)
at org.osgi.util.tracker.AbstractTracked.track(AbstractTracked.java:233)
at org.osgi.util.tracker.BundleTracker$Tracked.bundleChanged(BundleTracker.java:413)
at org.eclipse.osgi.framework.internal.core.BundleContextImpl.dispatchEvent(BundleContextImpl.java:919)
at org.eclipse.osgi.framework.eventmgr.EventManager.dispatchEvent(EventManager.java:227)
at org.eclipse.osgi.framework.eventmgr.ListenerQueue.dispatchEventSynchronous(ListenerQueue.java:149)
at org.eclipse.osgi.framework.internal.core.Framework.publishBundleEventPrivileged(Framework.java:1349)
at org.eclipse.osgi.framework.internal.core.Framework.publishBundleEvent(Framework.java:1300)
at org.eclipse.osgi.framework.internal.core.BundleHost.startWorker(BundleHost.java:380)
at org.eclipse.osgi.framework.internal.core.AbstractBundle.start(AbstractBundle.java:284)
at org.eclipse.osgi.framework.internal.core.AbstractBundle.start(AbstractBundle.java:276)
at com.sap.core.js.deployer.watchservice.WARDeployer.deploy(WARDeployer.java:142)
at com.sap.core.js.deployer.watchservice.FileSystemEventsListener.onChange(FileSystemEventsListener.java:26)
at com.springsource.util.io.FileSystemChecker.notifyListeners(FileSystemChecker.java:182)
at com.springsource.util.io.FileSystemChecker.check(FileSystemChecker.java:145)
at com.sap.core.js.deployer.watchservice.WatchTask.run(WatchTask.java:29)
at java.lang.Thread.run(Thread.java:679)

最佳答案

您需要将您的服务类通知您的环境。首先需要添加服务类,否则只会在getSingletons()中返回null
因此,只需更改您现在为空的构造函数以添加服务类:

class TestApplication extends Application {
public TestApplication() throws ServletException
{
singletons.add( new com.example.MyService() )
}
....
}

关于cxf - 在 cxf Servlet 上找不到资源类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5244112/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com