0
votes

I have exception: 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/spring/security.xml]

Few minutes in google, say me, I need to add dependence -- spring-security-config. I have this, the latest version 4.2.1, but exception there is.

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"
         xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.1.xsd
http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-4.0.xsd">

<beans:bean name="standartEncrypt"
            class="org.springframework.security.crypto.password.StandardPasswordEncoder" >
    <beans:constructor-arg name="secret" value="3u6gui" />
</beans:bean>

<http auto-config="true" >
    <intercept-url pattern="/notes/**" access="authenticated" />
    <intercept-url pattern="/register" requires-channel="https" />
    <intercept-url pattern="/" access="permitAll" />
    <intercept-url pattern="/accessDenied" access="permitAll" />
    <intercept-url pattern="/duplicate" access="permitAll" />
    <intercept-url pattern="/notExists" access="permitAll" />

    <access-denied-handler error-page="/accessDenied" />

    <logout
            logout-success-url="/index"
            logout-url="/notes/{username}/exit"
    />
    <form-login
            authentication-failure-url="/accessDenied"
            login-page="/register"
            login-processing-url="/register"
            password-parameter="password"
            username-parameter="username"
    />
    <remember-me data-source-ref="dataSource" />

    <session-management session-fixation-protection="newSession">
        <concurrency-control max-sessions="1" error-if-maximum-exceeded="true" />
    </session-management>
</http>

<authentication-manager >
    <authentication-provider>
        <password-encoder ref="standartEncrypt" />
        <jdbc-user-service data-source-ref="dataSource" users-by-username-query="SELECT username, password FROM Users WHERE username = ?"/>
    </authentication-provider>
</authentication-manager>

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

maven

<dependency>
    <groupId>org.springframework.security</groupId>
    <artifactId>spring-security-config</artifactId>
    <version>4.2.1.RELEASE</version>
</dependency>
1

1 Answers

0
votes

This is likely an unresolved dependency. Without seeing your Maven pom or project configuration, the bare minimum for Spring Security is:

<dependency>
    <groupId>org.springframework.security</groupId>
    <artifactId>spring-security-web</artifactId>
    <version>4.2.1.RELEASE</version>
</dependency>
<dependency>
    <groupId>org.springframework.security</groupId>
    <artifactId>spring-security-config</artifactId>
    <version>4.2.1.RELEASE</version>
</dependency>

If you are using Spring Tool Suite or Eclipse, be sure to right click your project, then select Maven -> Update Project and do a full clean install