Http 请求上的 javax.ws.rs.WebApplicationException

发布于 2024-12-10 19:20:36 字数 8944 浏览 0 评论 0原文

我已经尝试解决这个错误有一段时间了。这是一个 CXF、Spring Web 项目,maven 支持。提前致谢,如果您需要更多信息,请告诉我。基本上,当我卷曲/浏览到 cxf 目标时,就会出现问题。即使在调试模式下,Maven 编译也不会抛出任何错误,tomcat 也不会抛出任何错误,除了调用时出现以下错误之外。

来自 Tomcat

    Oct 18, 2011 2:38:20 PM org.apache.cxf.phase.PhaseInterceptorChain doDefaultLogging
    WARNING: Interceptor for {http://restful.prototype.com/}RestfulUserServiceImpl has thrown exception, unwinding now
    javax.ws.rs.WebApplicationException
       at org.apache.cxf.jaxrs.utils.InjectionUtils.invokeLifeCycleMethod(InjectionUtils.java:1090)
       at org.apache.cxf.jaxrs.lifecycle.PerRequestResourceProvider.createInstance(PerRequestResourceProvider.java:71)
       at org.apache.cxf.jaxrs.lifecycle.PerRequestResourceProvider.getInstance(PerRequestResourceProvider.java:63)
       at org.apache.cxf.jaxrs.JAXRSInvoker.getServiceObject(JAXRSInvoker.java:300)
       at org.apache.cxf.jaxrs.JAXRSInvoker.invoke(JAXRSInvoker.java:87)
       at org.apache.cxf.interceptor.ServiceInvokerInterceptor$1.run(ServiceInvokerInterceptor.java:58)
       at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:441)
       at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
       at java.util.concurrent.FutureTask.run(FutureTask.java:138)
       at org.apache.cxf.workqueue.SynchronousExecutor.execute(SynchronousExecutor.java:37)
       at org.apache.cxf.interceptor.ServiceInvokerInterceptor.handleMessage(ServiceInvokerInterceptor.java:106)
       at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:263)
       at org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiationObserver.java:121)
       at org.apache.cxf.transport.http.AbstractHTTPDestination.invoke(AbstractHTTPDestination.java:206)
       at org.apache.cxf.transport.servlet.ServletController.invokeDestination(ServletController.java:218)
       at org.apache.cxf.transport.servlet.ServletController.invoke(ServletController.java:200)
       at org.apache.cxf.transport.servlet.CXFNonSpringServlet.invoke(CXFNonSpringServlet.java:114)
       at org.apache.cxf.transport.servlet.AbstractHTTPServlet.handleRequest(AbstractHTTPServlet.java:184)
       at org.apache.cxf.transport.servlet.AbstractHTTPServlet.doGet(AbstractHTTPServlet.java:112)
       at javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
       at org.apache.cxf.transport.servlet.AbstractHTTPServlet.service(AbstractHTTPServlet.java:163)
       at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:304)
       at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
       at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:224)
       at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:169)
       at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
       at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
       at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
       at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:929)
       at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
       at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:405)
       at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:964)
       at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:515)
       at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:304)
       at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
       at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
       at java.lang.Thread.run(Thread.java:680)

bean.xml

    <bean
    ...... 
    http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
    http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
    http://cxf.apache.org/jaxrs http://cxf.apache.org/schemas/jaxrs.xsd
    http://cxf.apache.org/core http://cxf.apache.org/schemas/core.xsd"
    default-autowire="byName">

    <!-- Annotation scan -->
    <context:annotation-config />
    <context:component-scan base-package="com.prototype.core" />
    <!-- Reference Module from another project -->
    <import resource="classpath:META-INF/spring/app-jpa-config.xml"/>

    <!-- Load CXF modules from cxf.jar -->
    <import resource="classpath:META-INF/cxf/cxf.xml"/>
    <import resource="classpath:META-INF/cxf/cxf-extension-soap.xml"/>
    <import resource="classpath:META-INF/cxf/cxf-servlet.xml"/>
    <!-- <import resource="classpath:META-INF/cxf/cxf-extension-jaxrs-binding.xml"/> -->

    <bean id="restfulUser" class="com.prototype.restful.RestfulUserServiceImpl">
    </bean>

    <jaxrs:server id="restfuluserService"
            serviceClass="com.prototype.restful.RestfulUserServiceImpl" address="/user">
            <jaxrs:serviceBeans>
                    <ref bean="restfulUser" />
            </jaxrs:serviceBeans>
    </jaxrs:server>

    <cxf:bus>
            <cxf:features>
                    <cxf:logging />
            </cxf:features>
    </cxf:bus>
    </beans>

pom.xml的堆栈跟踪

    <build>
            <finalName>prototype-service</finalName>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <version>2.3.2</version>
                    <configuration>
                        <source>1.6</source>
                        <target>1.6</target>
                        <compilerArguments>
                            <endorseddirs>${endorsed.dir}</endorseddirs>
                        </compilerArguments>
                    </configuration>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-war-plugin</artifactId>
                    <version>2.1.1</version>
                    <configuration>
                        <failOnMissingWebXml>true</failOnMissingWebXml>
                    </configuration>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-dependency-plugin</artifactId>
                    <version>2.1</version>
                    <executions>
                        <execution>
                            <phase>validate</phase>
                            <goals>
                                <goal>copy</goal>
                            </goals>
                            <configuration>
                                <outputDirectory>${endorsed.dir}</outputDirectory>
                                <silent>true</silent>
                                <artifactItems>
                                    <artifactItem>
                                        <groupId>javax</groupId>
                                        <artifactId>javaee-endorsed-api</artifactId>
                                        <version>6.0</version>
                                        <type>jar</type>
                                    </artifactItem>
                                </artifactItems>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>
                <plugin>
                    <groupId>org.codehaus.mojo</groupId>
                    <artifactId>tomcat-maven-plugin</artifactId>
                    <version>1.1</version>
                    <configuration>
                        <url>http://localhost:8080/manager/html</url>
                        <server>development</server>
                        <path>/${project.name}</path>
                    </configuration>
                </plugin>
            </plugins>
        </build>

I have been trying to solve this bug for awhile now. It's a CXF, Spring web project, maven supported. Thanks in advance, and let me know if you need more information. Basically the problem occurs when I curl/browse to the cxf target. Maven compile didn't throw any error, even when in debug mode, nor did tomcat except for the following when a call is made.

Stacktrace from Tomcat

    Oct 18, 2011 2:38:20 PM org.apache.cxf.phase.PhaseInterceptorChain doDefaultLogging
    WARNING: Interceptor for {http://restful.prototype.com/}RestfulUserServiceImpl has thrown exception, unwinding now
    javax.ws.rs.WebApplicationException
       at org.apache.cxf.jaxrs.utils.InjectionUtils.invokeLifeCycleMethod(InjectionUtils.java:1090)
       at org.apache.cxf.jaxrs.lifecycle.PerRequestResourceProvider.createInstance(PerRequestResourceProvider.java:71)
       at org.apache.cxf.jaxrs.lifecycle.PerRequestResourceProvider.getInstance(PerRequestResourceProvider.java:63)
       at org.apache.cxf.jaxrs.JAXRSInvoker.getServiceObject(JAXRSInvoker.java:300)
       at org.apache.cxf.jaxrs.JAXRSInvoker.invoke(JAXRSInvoker.java:87)
       at org.apache.cxf.interceptor.ServiceInvokerInterceptor$1.run(ServiceInvokerInterceptor.java:58)
       at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:441)
       at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
       at java.util.concurrent.FutureTask.run(FutureTask.java:138)
       at org.apache.cxf.workqueue.SynchronousExecutor.execute(SynchronousExecutor.java:37)
       at org.apache.cxf.interceptor.ServiceInvokerInterceptor.handleMessage(ServiceInvokerInterceptor.java:106)
       at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:263)
       at org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiationObserver.java:121)
       at org.apache.cxf.transport.http.AbstractHTTPDestination.invoke(AbstractHTTPDestination.java:206)
       at org.apache.cxf.transport.servlet.ServletController.invokeDestination(ServletController.java:218)
       at org.apache.cxf.transport.servlet.ServletController.invoke(ServletController.java:200)
       at org.apache.cxf.transport.servlet.CXFNonSpringServlet.invoke(CXFNonSpringServlet.java:114)
       at org.apache.cxf.transport.servlet.AbstractHTTPServlet.handleRequest(AbstractHTTPServlet.java:184)
       at org.apache.cxf.transport.servlet.AbstractHTTPServlet.doGet(AbstractHTTPServlet.java:112)
       at javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
       at org.apache.cxf.transport.servlet.AbstractHTTPServlet.service(AbstractHTTPServlet.java:163)
       at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:304)
       at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
       at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:224)
       at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:169)
       at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
       at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
       at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
       at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:929)
       at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
       at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:405)
       at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:964)
       at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:515)
       at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:304)
       at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
       at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
       at java.lang.Thread.run(Thread.java:680)

bean.xml

    <bean
    ...... 
    http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
    http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
    http://cxf.apache.org/jaxrs http://cxf.apache.org/schemas/jaxrs.xsd
    http://cxf.apache.org/core http://cxf.apache.org/schemas/core.xsd"
    default-autowire="byName">

    <!-- Annotation scan -->
    <context:annotation-config />
    <context:component-scan base-package="com.prototype.core" />
    <!-- Reference Module from another project -->
    <import resource="classpath:META-INF/spring/app-jpa-config.xml"/>

    <!-- Load CXF modules from cxf.jar -->
    <import resource="classpath:META-INF/cxf/cxf.xml"/>
    <import resource="classpath:META-INF/cxf/cxf-extension-soap.xml"/>
    <import resource="classpath:META-INF/cxf/cxf-servlet.xml"/>
    <!-- <import resource="classpath:META-INF/cxf/cxf-extension-jaxrs-binding.xml"/> -->

    <bean id="restfulUser" class="com.prototype.restful.RestfulUserServiceImpl">
    </bean>

    <jaxrs:server id="restfuluserService"
            serviceClass="com.prototype.restful.RestfulUserServiceImpl" address="/user">
            <jaxrs:serviceBeans>
                    <ref bean="restfulUser" />
            </jaxrs:serviceBeans>
    </jaxrs:server>

    <cxf:bus>
            <cxf:features>
                    <cxf:logging />
            </cxf:features>
    </cxf:bus>
    </beans>

pom.xml

    <build>
            <finalName>prototype-service</finalName>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <version>2.3.2</version>
                    <configuration>
                        <source>1.6</source>
                        <target>1.6</target>
                        <compilerArguments>
                            <endorseddirs>${endorsed.dir}</endorseddirs>
                        </compilerArguments>
                    </configuration>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-war-plugin</artifactId>
                    <version>2.1.1</version>
                    <configuration>
                        <failOnMissingWebXml>true</failOnMissingWebXml>
                    </configuration>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-dependency-plugin</artifactId>
                    <version>2.1</version>
                    <executions>
                        <execution>
                            <phase>validate</phase>
                            <goals>
                                <goal>copy</goal>
                            </goals>
                            <configuration>
                                <outputDirectory>${endorsed.dir}</outputDirectory>
                                <silent>true</silent>
                                <artifactItems>
                                    <artifactItem>
                                        <groupId>javax</groupId>
                                        <artifactId>javaee-endorsed-api</artifactId>
                                        <version>6.0</version>
                                        <type>jar</type>
                                    </artifactItem>
                                </artifactItems>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>
                <plugin>
                    <groupId>org.codehaus.mojo</groupId>
                    <artifactId>tomcat-maven-plugin</artifactId>
                    <version>1.1</version>
                    <configuration>
                        <url>http://localhost:8080/manager/html</url>
                        <server>development</server>
                        <path>/${project.name}</path>
                    </configuration>
                </plugin>
            </plugins>
        </build>

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

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

发布评论

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

评论(1

眼睛会笑 2024-12-17 19:20:36

我通过将scope="request" 添加到我的服务bean 来修复它,以防有人感兴趣。

    <bean id="restfulUser" class="com.prototype.restful.RestfulUserServiceImpl" scope="request" />

I fixed it by adding scope="request" to my service bean, incase anyone is interested.

    <bean id="restfulUser" class="com.prototype.restful.RestfulUserServiceImpl" scope="request" />
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文