2011-08-25 13 views
53

Sto sviluppando la mia prima applicazione in sicurezza di primavera. Il mio file applicationContext-security.xml assomiglia a questo:Impossibile trovare Spring NamespaceHandler per lo spazio dei nomi dello schema XML [http://www.springframework.org/schema/security]

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

<!-- 
    - Namespace-based OpenID configuration 
    --> 

<b:beans xmlns="http://www.springframework.org/schema/security" 
    xmlns:b="http://www.springframework.org/schema/beans" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    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> 
     <intercept-url pattern="/**" access="ROLE_USER"/> 
     <intercept-url pattern="/index.xhtml*" filters="none"/> 
     <logout/> 
     <openid-login login-page="/index.xhtml" authentication-failure-url="/index.xhtml?login_error=true"> 
      <attribute-exchange> 
       <openid-attribute name="email" type="http://schema.openid.net/contact/email" required="true" count="2"/> 
       <openid-attribute name="name" type="http://schema.openid.net/namePerson/friendly" /> 
      </attribute-exchange> 
     </openid-login> 
     <remember-me token-repository-ref="tokenRepo"/> 
    </http> 

    <b:bean id="tokenRepo" 
      class="org.springframework.security.web.authentication.rememberme.InMemoryTokenRepositoryImpl" /> 

    <authentication-manager alias="authenticationManager"/> 

    <user-service id="userService"> 
     <user name="http://user.myopenid.com/" authorities="ROLE_SUPERVISOR,ROLE_USER" /> 
    </user-service> 

</b:beans> 

e file web.xml è:

<?xml version="1.0" encoding="UTF-8"?> 
<web-app xmlns="http://java.sun.com/xml/ns/j2ee" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" version="2.4"> 

    <display-name>Spring Security OpenID Demo Application</display-name> 

    <context-param> 
     <param-name>contextConfigLocation</param-name> 
     <param-value> 
      /WEB-INF/applicationContext-security.xml 
     </param-value> 
    </context-param> 

    <context-param> 
     <param-name>log4jConfigLocation</param-name> 
     <param-value>/WEB-INF/classes/log4j.properties</param-value> 
    </context-param> 

    <context-param> 
     <param-name>webAppRootKey</param-name> 
     <param-value>openid.root</param-value> 
    </context-param> 

    <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> 

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

    <listener> 
     <listener-class>org.springframework.web.util.Log4jConfigListener</listener-class> 
    </listener> 
    <welcome-file-list> 
     <welcome-file>faces/index.xhtml</welcome-file> 
    </welcome-file-list> 
</web-app> 

Pulire e costruire la candidatura verrà accolta, ma quando provo a distribuire l'applicazione pontile 7 mi dà il seguente errore:

SEVERE: Context initialization failed
org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Unable to locate Spring NamespaceHandler for XML schema namespace [ http://www.springframework.org/schema/security]
Offending resource: ServletContext resource [/WEB-INF/applicationContext-security.xml]
at org.springframework.beans.factory.parsing.FailFastProblemReporter.error(FailFastProblemReporter.java:68)
at org.springframework.beans.factory.parsing.ReaderContext.error(ReaderContext.java:85)
at org.springframework.beans.factory.parsing.ReaderContext.error(ReaderContext.java:80)

Ho provato tutto ma non posso risolvere questo errore. Qualsiasi aiuto sarebbe apprezzato.

EDIT ho provato aggiunto 3.0.2 versione della primavera-Security e ha ottenuto questo:

Context initialization failed
org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: Line 13 in XML document from ServletContext resource [/WEB-INF/applicationContext-security.xml] is invalid;
nested exception is org.xml.sax.SAXParseException; lineNumber: 13; columnNumber: 11; cvc-complex-type.2.4.c: The matching wildcard is strict, but no declaration can be found for element 'http'. at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:396)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:334

risposta

87

Hai bisogno di un spring-security-config.jar sul classpath.

L'eccezione indica che il namescape security: xml non può essere gestito da "parser" di primavera. Sono implementazioni dell'interfaccia NamespaceHandler, quindi è necessario un gestore che sappia come elaborare i tag <security:. Quello è il SecurityNamespaceHandler situato in spring-security-config

+1

plz vedere il codice modificato ..... – aProgrammer

+0

Si prega di notare l'errore di battitura nella 'primavera-secuirty-config.jar'. Ho provato a modificare questo, ma SO non consente modifiche così brevi. (? WTH) – Paul

+1

per Maven è necessario: \t \t \t \t \t org.springframework.security \t \t \t primavera-sicurezza-config \t \t \t $ {} spring.security.version \t \t Justin

7

Ho avuto lo stesso problema. L'unica cosa che ha risolto è stato unire il contenuto di META-INF/spring.handler e META-INF/spring.schemas di ogni file jar di primavera negli stessi nomi di file sotto il mio progetto META-INF.

Questi due thread spiegano meglio:

+0

Risolto sostituendo il mio META-INF/spring.handler con quello citato nel tuo primo link: http://blog.idm.fr/2009/09/maven-assembly-plugin-and-spring-namespace-handlers.html #vedi la fonte –

0

Nel mio caso, questo è stato causato da voci manifesto personalizzato aggiunti dal Maven-jar-plugin.

<plugin> 
    <groupId>org.apache.maven.plugins</groupId> 
    <artifactId>maven-jar-plugin</artifactId> 
    <version>2.6</version> 
    <configuration> 
     <archive> 
      <index>true</index> 
      <manifest> 
       <addClasspath>true</addClasspath> 
      </manifest> 
      <manifestEntries> 
       <git>${buildNumber}</git> 
       <build-time>${timestamp}</build-time> 
      </manifestEntries> 
     </archive> 
    </configuration> 
</plugin> 

Rimozione le seguenti voci risolto il problema

<index>true</index> 
<manifest> 
    <addClasspath>true</addClasspath> 
</manifest> 
Problemi correlati