java.lang.ClassNotFoundException:javax.ws.rs.NotAuthorizedException

时间:2013-07-20 09:03:55

标签: spring maven spring-mvc cxf spring-ws

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"
             metadata-complete="true" version="2.5">

        <context-param>
            <param-name>oauth.data.provider-class</param-name>
            <param-value>demo.oauth.server.controllers.SampleOAuthDataProvider</param-value>
        </context-param>

        <filter>
            <filter-name>oauthFilter</filter-name>
            <filter-class>org.apache.cxf.rs.security.oauth.filters.OAuthServletFilter</filter-class>
        </filter>

        <filter-mapping>
            <filter-name>oauthFilter</filter-name>
            <url-pattern>/auth/resources/person/*</url-pattern>
        </filter-mapping>


        <filter>
            <filter-name>oauthSpringFilter</filter-name>
            <filter-class>demo.oauth.server.spring.SpringOAuthAuthenticationFilter
            </filter-class>
        </filter>
        <filter-mapping>
            <filter-name>oauthSpringFilter</filter-name>
            <url-pattern>/auth/resources/person/*</url-pattern>
        </filter-mapping>
        <!-- **************** Spring configuration *****************-->

        <context-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>/WEB-INF/*-beans.xml</param-value>
        </context-param>


        <listener>
            <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
        </listener>

        <filter>
            <filter-name>springSecurityFilterChain</filter-name>
            <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
        </filter>

        <filter-mapping>
            <filter-name>springSecurityFilterChain</filter-name>
            <url-pattern>/*</url-pattern>
        </filter-mapping>

        <servlet>
            <servlet-name>spring</servlet-name>
            <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
            <load-on-startup>1</load-on-startup>
        </servlet>

        <servlet-mapping>
            <servlet-name>spring</servlet-name>
            <url-pattern>/app/*</url-pattern>
        </servlet-mapping>

        <!-- **************** CXF configuration *****************-->
        <servlet>
            <servlet-name>CXFServlet</servlet-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>/auth/*</url-pattern>
        </servlet-mapping>

        <welcome-file-list>
            <welcome-file>index.jsp</welcome-file>
        </welcome-file-list>
    </web-app>

OathBean.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:beans="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:sec="http://cxf.apache.org/configuration/security"
       xmlns:http="http://cxf.apache.org/transports/http/configuration"
       xmlns:httpj="http://cxf.apache.org/transports/http-jetty/configuration"
       xmlns:jaxws="http://java.sun.com/xml/ns/jaxws" xmlns:jaxrs="http://cxf.apache.org/jaxrs"
       xsi:schemaLocation="http://cxf.apache.org/configuration/security
              http://cxf.apache.org/schemas/configuration/security.xsd
            http://cxf.apache.org/transports/http/configuration
            http://cxf.apache.org/schemas/configuration/http-conf.xsd
            http://cxf.apache.org/transports/http-jetty/configuration
            http://cxf.apache.org/schemas/configuration/http-jetty.xsd
            http://www.springframework.org/schema/beans
            http://www.springframework.org/schema/beans/spring-beans-2.0.xsd http://cxf.apache.org/jaxrs http://cxf.apache.org/schemas/jaxrs.xsd">

    <import resource="classpath:META-INF/cxf/cxf.xml"/>
    <import resource="classpath:META-INF/cxf/cxf-servlet.xml"/>


    <!-- Publish OAuth endpoints-->
    <jaxrs:server id="oauthServer" address="/oauth/">
        <jaxrs:serviceBeans>
            <ref bean="oauthServices"/>
        </jaxrs:serviceBeans>
        <jaxrs:providers>
            <ref bean="dispatchProvider"/>
        </jaxrs:providers>
    </jaxrs:server>

    <!--Definitions of OAuth module endpoints-->
    <bean id="oauthServices"
class="org.apache.cxf.rs.security.oauth.services.OAuthDefaultServices"/>

    <!--Redirects from Resource Owner Authorization Endpoint to sign in page-->
    <bean id="dispatchProvider" class="org.apache.cxf.jaxrs.provider.RequestDispatcherProvider">
        <property name="resourcePath" value="/oAuthLogin.jsp"/>
    </bean>


    <!-- Endpoint serves OAuth protected resource -->
    <jaxrs:server id="resourceServer" address="/resources/">
        <jaxrs:serviceBeans>
            <ref bean="resource"/>
        </jaxrs:serviceBeans>
        <jaxrs:providers>
            <ref bean="springSecurityExceptionMapper"/>
        </jaxrs:providers>
    </jaxrs:server>

    <bean id="springSecurityExceptionMapper"
          class="demo.oauth.server.spring.SpringSecurityExceptionMapper"/>
    <!-- Resource Provider -->
    <bean id="resource" class="demo.oauth.server.SampleResourceProvider"/>
</beans>

Security.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/security"
             xmlns:beans="http://www.springframework.org/schema/beans"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xmlns:context="http://www.springframework.org/schema/context"
             xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
                        http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.0.xsd
                        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">

    <beans:bean id="authenticationSuccHandler"
                class="demo.oauth.server.spring.AuthenticationSuccessfullHandler">
        <beans:property name="defaultTargetUrl" value="/app/newClientForm.jsp"/>
        <beans:property name="confirmationUrl" value="/auth/oauth/authorize/decision"/>
    </beans:bean>

    <beans:bean id="authenticationFailHandler"
                class="demo.oauth.server.spring.AuthenticationFailureHandler">
        <beans:property name="authorizeUrl" value="/auth/oauth/authorize"/>
    </beans:bean>

    <global-method-security secured-annotations="enabled" jsr250-annotations="enabled"/>

    <beans:bean id="entryPoint" class="demo.oauth.server.CustomAuth">
        <beans:property name="loginFormUrl" value="/index.jsp"/>
    </beans:bean>

    <http auto-config="false" entry-point-ref="entryPoint">
        <intercept-url pattern="/oAuthLogin.jsp" filters="none"/>
        <intercept-url pattern="/index.jsp" filters="none"/>
        <intercept-url pattern="/" filters="none"/>
        <intercept-url pattern="/favicon.ico" filters="none"/>
        <intercept-url pattern="/auth/oauth/**" filters="none"/>
        <intercept-url pattern="/auth/resources/**" filters="none"/>
        <intercept-url pattern="/**" access="ROLE_USER"/>

        <form-login authentication-success-handler-ref="authenticationSuccHandler"
                    authentication-failure-handler-ref="authenticationFailHandler" login-page="/index.jsp"
                    authentication-failure-url="/auth/oauth/authorize"
                    default-target-url="/app/newClientForm.jsp"/>

        <logout invalidate-session="true" logout-url="/logout.htm"
                logout-success-url="/login.jsp?loggedout=true"/>
    </http>


    <authentication-manager>
        <authentication-provider>
            <user-service>
                <user name="user1" password="1111" authorities="ROLE_USER"/>
                <user name="user2" password="2222" authorities="ROLE_USER"/>
            </user-service>
        </authentication-provider>
    </authentication-manager>

</beans:beans>

Spring-servlet.xml

<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:mvc="http://www.springframework.org/schema/mvc"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
       http://www.springframework.org/schema/beans/spring-beans-2.5.xsd http://www.springframework.org/schema/context
       http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd">

    <mvc:annotation-driven/>
    <context:annotation-config/>
    <context:component-scan base-package="demo.oauth.server.controllers"/>

    <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="prefix" value="/WEB-INF/views/"/>
        <property name="suffix" value=".jsp"/>
    </bean>

</beans>

错误日志

13:21:40,882 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/server]] (MSC service thread 1-2) Exception starting filter springSecuri
tyFilterChain: org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'springSecurityFilterChain' is defined
        at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanDefinition(DefaultListableBeanFactory.java:504) [spring-beans-3.0.0.RELEA
SE.jar:]
        at org.springframework.beans.factory.support.AbstractBeanFactory.getMergedLocalBeanDefinition(AbstractBeanFactory.java:1041) [spring-beans-3.0.0.RELEASE
.jar:]
        at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:273) [spring-beans-3.0.0.RELEASE.jar:]
        at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193) [spring-beans-3.0.0.RELEASE.jar:]
        at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1008) [spring-context-3.0.0.RELEASE.jar:]
        at org.springframework.web.filter.DelegatingFilterProxy.initDelegate(DelegatingFilterProxy.java:217) [spring-web-3.0.0.RELEASE.jar:]
        at org.springframework.web.filter.DelegatingFilterProxy.initFilterBean(DelegatingFilterProxy.java:145) [spring-web-3.0.0.RELEASE.jar:]
        at org.springframework.web.filter.GenericFilterBean.init(GenericFilterBean.java:179) [spring-web-3.0.0.RELEASE.jar:]
        at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:447) [jbossweb-7.0.1.Final.jar:7.0.2.Final]
        at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:3245) [jbossweb-7.0.1.Final.jar:7.0.2.Final]
        at org.apache.catalina.core.StandardContext.start(StandardContext.java:3836) [jbossweb-7.0.1.Final.jar:7.0.2.Final]
        at org.jboss.as.web.deployment.WebDeploymentService.start(WebDeploymentService.java:70) [jboss-as-web-7.0.2.Final.jar:7.0.2.Final]
        at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1824)
        at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1759)
        at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) [:1.6.0_18]
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) [:1.6.0_18]
        at java.lang.Thread.run(Thread.java:619) [:1.6.0_18]

13:21:40,929 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/server]] (MSC service thread 1-2) Exception starting filter oauthFilter:
 java.lang.NoClassDefFoundError: javax/ws/rs/NotAuthorizedException
        at org.apache.cxf.rs.security.oauth.filters.OAuthServletFilter.init(OAuthServletFilter.java:50) [cxf-rt-rs-security-oauth-2.7.4.jar:]
        at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:447) [jbossweb-7.0.1.Final.jar:7.0.2.Final]
        at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:3245) [jbossweb-7.0.1.Final.jar:7.0.2.Final]
        at org.apache.catalina.core.StandardContext.start(StandardContext.java:3836) [jbossweb-7.0.1.Final.jar:7.0.2.Final]
        at org.jboss.as.web.deployment.WebDeploymentService.start(WebDeploymentService.java:70) [jboss-as-web-7.0.2.Final.jar:7.0.2.Final]
        at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1824)
        at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1759)
        at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) [:1.6.0_18]
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) [:1.6.0_18]
        at java.lang.Thread.run(Thread.java:619) [:1.6.0_18]
Caused by: java.lang.ClassNotFoundException: javax.ws.rs.NotAuthorizedException from [Module "deployment.server.war:main" from Service Module Loader]
        at org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:191)
        at org.jboss.modules.ConcurrentClassLoader.performLoadClassChecked(ConcurrentClassLoader.java:361)
        at org.jboss.modules.ConcurrentClassLoader.performLoadClassChecked(ConcurrentClassLoader.java:333)
        at org.jboss.modules.ConcurrentClassLoader.performLoadClass(ConcurrentClassLoader.java:310)
        at org.jboss.modules.ConcurrentClassLoader.loadClass(ConcurrentClassLoader.java:103)
        ... 10 more

13:21:40,960 ERROR [org.apache.catalina.core.StandardContext] (MSC service thread 1-2) Error filterStart
13:21:40,976 ERROR [org.apache.catalina.core.StandardContext] (MSC service thread 1-2) Context [/server] startup failed due to previous errors
13:21:40,976 INFO  [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/server]] (MSC service thread 1-2) Closing Spring root WebApplicationCont
ext
13:21:40,992 INFO  [org.springframework.web.context.support.XmlWebApplicationContext] (MSC service thread 1-2) Closing Root WebApplicationContext: startup date
[Sat Jul 20 13:21:40 IST 2013]; root of context hierarchy
13:21:40,992 INFO  [org.springframework.beans.factory.support.DefaultListableBeanFactory] (MSC service thread 1-2) Destroying singletons in org.springframework.
beans.factory.support.DefaultListableBeanFactory@ccc96: defining beans []; root of factory hierarchy
13:21:40,992 INFO  [org.jboss.web] (MSC service thread 1-2) registering web context: /server
13:21:41,007 ERROR [org.jboss.as] (MSC service thread 1-3) JBoss AS 7.0.2.Final "Arc" started (with errors) in 5803ms - Started 337 of 397 services (3 services
failed or missing dependencies, 57 services are passive or on-demand)
13:21:41,038 INFO  [org.jboss.as.server.controller] (DeploymentScanner-threads - 2) Deployed "server.war"

我正在使用maven spring,并试图为此运行授权。它已成功构建,但是当我在服务器上部署它时,服务器jboss7会出现上述错误。有什么想法吗?

1 个答案:

答案 0 :(得分:1)

我首先解决NoClassDefFoundError,查看堆栈跟踪的底部:

java.lang.NoClassDefFoundError: javax/ws/rs/NotAuthorizedException

好像你错过了类路径中的库JAX-RS。通过Maven将其添加为依赖项,看看接下来会发生什么。