2011-08-25 11 views
53

मैं वसंत सुरक्षा में अपना पहला एप्लिकेशन विकसित कर रहा हूं। मेरे applicationContext-security.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> 

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

स्वच्छ और आवेदन के निर्माण सफल होता है, लेकिन जब मैं आवेदन घाट को तैनात करने की कोशिश 7 मुझे निम्नलिखित त्रुटि देता है:

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)

सब कुछ कोशिश की लेकिन इस त्रुटि को हल नहीं कर सकता। किसी भी सहायता की सराहना की जाएगी।

संपादित मैंने कोशिश की वसंत-सुरक्षा के 3.0.2 संस्करण जोड़ा गया है और यह मिल गया:

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

उत्तर

87

आप अपने classpath पर एक spring-security-config.jar की जरूरत है।

अपवाद का अर्थ है कि security: एक्सएमएल नेमस्केप वसंत "पार्सर्स" द्वारा नियंत्रित नहीं किया जा सकता है। वे NamespaceHandler इंटरफ़ेस के कार्यान्वयन हैं, इसलिए आपको एक हैंडलर की आवश्यकता है जो <security: टैग को संसाधित करने के बारे में जानता है। SecurityNamespaceHandlerspring-security-config

+1

plz संपादित कोड देख ..... – aProgrammer

+0

कृपया 'वसंत-secuirty-config.jar' में लिखने में गलती पर ध्यान दें। मैंने इसे संपादित करने का प्रयास किया, लेकिन SO इस तरह के छोटे बदलावों की अनुमति नहीं देता है। (? WTH) – Paul

+1

Maven के लिए आप की जरूरत: \t \t \t \t \t org.springframework.security \t \t \t वसंत-सुरक्षा-config \t \t \t $ {spring.security.version} \t \t Justin

7

में स्थित एक ही समस्या थी। इसे हल करने वाली एकमात्र चीज मेटा-आईएनएफ/वसंत.handler और मेटा-आईएनएफ/spring.schemas की सामग्री प्रत्येक वसंत जार फ़ाइल की सामग्री को मेरे मेटा-आईएनएफ परियोजना के तहत समान फ़ाइल नामों में विलय कर रही थी।

+0

मेरे मेटा-आईएनएफ/spring.handler को अपने पहले लिंक में उद्धृत एक के साथ हल करके हल किया गया: http://blog.idm.fr/2009/09/maven-assembly-plugin-and-spring-namespace-handlers.html #स्रोत देखें –

0

मेरे मामले में, इस Maven-जार-प्लगइन द्वारा जोड़ा कस्टम प्रकट प्रविष्टियों की वजह से किया गया था:

यह दो धागे बेहतर समझाने।

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

को निकालने से निम्नलिखित प्रविष्टियों समस्या तय

<index>true</index> 
<manifest> 
    <addClasspath>true</addClasspath> 
</manifest> 
संबंधित मुद्दे

 संबंधित मुद्दे