Error in applicationContext-security.xml

Asked

Viewed 457 times

1

My first xml file applicationContext-security.xml:

<?xml version="1.0" encoding="UTF-8"?>
<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 auto-config="true">

    <intercept-url pattern="/admin/*" access="ROLE_ADMINISTRADOR" />
    <intercept-url pattern="/restrito/*" access="ROLE_USUARIO" />
    <form-login login-page="/publico/login.jsf"
        always-use-default-target="true" default-target-url="/restrito/principal.jsf"
        authentication-failure-url="/publico/login.jsf?login_error=1" />
    <logout/>
    <remember-me />
</http>

<authentication-manager>
    <authentication-provider>
        <jdbc-user-service data-source-ref="financeiroDataSource"
            authorities-by-username-query="SELECT u.login, p.permissao 
                                         FROM usuario u, usuario_permissao p 
                                        WHERE u.codigo = p.usuario 
                                          AND u.login = ?"
            users-by-username-query="SELECT login, senha, ativo 
                                   FROM usuario 
                                  WHERE login = ?" />
    </authentication-provider>
</authentication-manager>
</b:beans>

And there’s this other applicationContext.xml:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="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">
<bean id="financeiroDataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
    <property name="jndiName">
        <value>java:comp/env/jdbc/FinanceiroDB</value>
    </property>
</bean>     
</beans>

All are in the WEB-INFO folder.

Es are errors in Tomcat log:

first

GRAVE: 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]

2nd

Sep 09, 2014 9:47:18 PM org.apache.Catalina.core.Standardcontext listenerStart GRAVE: Exception sending context initialized Event to Listener instance of class org.springframework.web.context.Contextloaderlistener 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]

My libs:

spring-2.5.6.jar
spring-security-cas-3.1.0.RELEASE. jar
spring-security-core-3.1.0.RELEASE. jar
spring-security-openid-3.1.0.RELEASE. jar
spring-security-remoting-3.1.0.RELEASE. jar
spring-security-samples-Contacts-3.0.2.RELEASE-sources.jar
spring-security-samples-tutorial-3.0.2.RELEASE-sources.jar

  • It seems that the configuration XML is not in the required pattern. Depending on the IDE you can validate this XML before running the application. Which IDE you are using?

  • @I’m wearing the Eclipse

  • Post also your XML. It will help a lot in this case.

  • I changed the bug description and added my files. @Luíde

  • What version of Tomcat and Spring Security you are using?

  • One more thing, what libs are you using in the project?

  • @Luídne added to the description the libs I’m using from spring. And I updated the two errors that happen when starting Tomcat.

Show 2 more comments

1 answer

1

What is happening is the following, in XML the namespace handler http://www.springframework.org/schema/security is not being found. This is because a library is missing that contains this manipulative class.

And for that, the missing framework library is the: spring-security-config-3.1.0.RELEASE. jar If you see the files inside the folder META-INF of this . jar will see the files that define the class that will handle that namespace.

Therefore, just add the mentioned library that the error will no longer occur. However, it’s good to add all the other Spring Security libraries to the project if you want to reduce the size of the . War go removing one at a time to see which ones are not needed.

Other information: http://www.baeldung.com/unable-to-locate-spring-namespacehandler-for-xml-schema-namespace

Browser other questions tagged

You are not signed in. Login or sign up in order to post.