gpt4 book ai didi

java - Jersey 服务 + PrettyFaces 冲突

转载 作者:行者123 更新时间:2023-11-29 05:15:18 25 4
gpt4 key购买 nike

我的应用程序有一个正在运行的 RESTFul Web 服务

<servlet>
<servlet-name>jersey-servlet</servlet-name>
<servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>com.sun.jersey.config.property.packages</param-name>
<param-value>org.okkam.sameauthor.api</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>jersey-servlet</servlet-name>
<url-pattern>/rest/*</url-pattern>
</servlet-mapping>

PrettyFaces 也做了一些 URL 重写,使用以下规则(来自 pretty-config.xml 配置文件)

<url-mapping id="home">
<pattern value="/" />
<view-id value="/index.xhtml" />
</url-mapping>

<url-mapping id="demo">
<pattern value="/demo" />
<view-id value="/demo.xhtml" />
</url-mapping>

<url-mapping id="notfound">
<pattern value="/notfound" />
<view-id value="/notfound.xhtml" />
</url-mapping>

<url-mapping id="stop">
<pattern value="/stop" />
<view-id value="/stop.xhtml" />
</url-mapping>

请注意,规则不适用于 /rest/ 路径,但这不起作用。从我的浏览器到达其余路径时,抛出以下异常:

    SEVERE: Servlet.service() for servlet [jersey-servlet] in context with path [/sameauthor] threw exception [Servlet execution threw an exception] with root cause
java.lang.AbstractMethodError: javax.ws.rs.core.UriBuilder.uri(Ljava/lang/String;)Ljavax/ws/rs/core/UriBuilder;
at javax.ws.rs.core.UriBuilder.fromUri(UriBuilder.java:119)
at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:662)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.ocpsoft.rewrite.servlet.RewriteFilter.doFilter(RewriteFilter.java:205)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1040)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:607)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:316)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:745)

阅读异常我猜过滤器也适用于所有其他路径,而 Jersey 似乎不喜欢它。我该如何解决这个冲突?

最佳答案

如果您仔细查看异常,您会看到:

java.lang.AbstractMethodError:
javax.ws.rs.core.UriBuilder.uri(Ljava/lang/String;)Ljavax/ws/rs/core/UriBuilder;

这看起来像是类路径问题。可能的原因是:

  • 您的 WAR 中有 JAX-RS API 并将其部署到 Java EE 服务器。您应该从 WAR 中删除 API 或将范围更改为 provided
  • 您的类路径上有多个版本的 JAX-RS API,并且正在部署到 Tomcat 或 Jetty 等普通 servlet 容器。

希望对您有所帮助。

关于java - Jersey 服务 + PrettyFaces 冲突,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26778891/

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