Я работаю над проектом, но я получаю сообщение об ошибке "Префикс" контекст "для элемента": компонент-сканирование "не связано" в стороне 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"xmlns:security="http://www.springframework.org/schema/security"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.0.xsd">
<!--Here is i am getting error "The prefix "context" for element "context:component-scan" is not bound."-->
<context:component-scan base-package="tudu.security"/>
<global-method-security secured-annotations="enabled" />
<HTTP>
<INTERCEPT-URL PATTERN="/AJAX/**" ACCESS="ROLE_USER" />
<INTERCEPT-URL PATTERN="/TUDU/WELCOME" ACCESS="ROLE_ANONYMOUS,ROLE_USER" />
<INTERCEPT-URL PATTERN="/TUDU/RECOVERPASSWORD" ACCESS="ROLE_ANONYMOUS,ROLE_USER" />
<INTERCEPT-URL PATTERN="/TUDU/REGISTER" ACCESS="ROLE_ANONYMOUS,ROLE_USER" />
<INTERCEPT-URL PATTERN="/TUDU/ADMIN" ACCESS="ROLE_ADMIN" />
<INTERCEPT-URL PATTERN="/TUDU/**" ACCESS="ROLE_USER" />
<INTERCEPT-URL PATTERN="/SERVLET/**" ACCESS="ROLE_USER" />
<FORM-LOGIN LOGIN-PROCESSING-URL="/TUDU/LOGIN" LOGIN-PAGE="/TUDU/WELCOME"
AUTHENTICATION-FAILURE-URL="/TUDU/WELCOME?AUTHENTICATION=FAILURE"
DEFAULT-TARGET-URL="/TUDU/LISTS" ALWAYS-USE-DEFAULT-TARGET="TRUE" />
<REMEMBER-ME KEY="TUDUROCKS" />
<LOGOUT LOGOUT-URL="/TUDU/LOGOUT" />
</HTTP>
<AUTHENTICATION-MANAGER ALIAS="AUTHENTICATIONMANAGER">
<AUTHENTICATION-PROVIDER USER-SERVICE-REF="USERDETAILSSERVICE" />
</AUTHENTICATION-MANAGER>
Пространство имен xml нуждается в некоторых изменениях
Это должно сработать.
<beans:beans xmlns="http://www.springframework.org/schema/security"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:beans="http://www.springframework.org/schema/beans"
xsi:schemaLocation="http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.0.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
<!--Here is i am getting error "The prefix "context" for element "context:component-scan"
is not bound." -->
<context:component-scan base-package="tudu.security" />
<global-method-security secured-annotations="enabled" />
<http>
<intercept-url pattern="/AJAX/**" access="ROLE_USER" />
<intercept-url pattern="/TUDU/WELCOME" access="ROLE_ANONYMOUS,ROLE_USER" />
<intercept-url pattern="/TUDU/RECOVERPASSWORD" access="ROLE_ANONYMOUS,ROLE_USER" />
<intercept-url pattern="/TUDU/REGISTER" access="ROLE_ANONYMOUS,ROLE_USER" />
<intercept-url pattern="/TUDU/ADMIN" access="ROLE_ADMIN" />
<intercept-url pattern="/TUDU/**" access="ROLE_USER" />
<intercept-url pattern="/SERVLET/**" access="ROLE_USER" />
<form-login login-processing-url="/TUDU/LOGIN" login-page="/TUDU/WELCOME"
authentication-failure-url="/TUDU/WELCOME?AUTHENTICATION=FAILURE"
default-target-url="/TUDU/LISTS" always-use-default-target="true" />
<remember-me key="TUDUROCKS" />
<logout logout-url="/TUDU/LOGOUT" />
</http>
<authentication-manager alias="AUTHENTICATIONMANAGER">
<authentication-provider user-service-ref="USERDETAILSSERVICE" />
</authentication-manager>
</beans:beans>
Я использую редактор конфигурации Spring, снабженный STS, который облегчает мою жизнь.
может возникнуть какая-то проблема с пространствами имен... то, что вы сделали до сих пор, правильно... но вам просто нужно изменить одну вещь, т.е.
поместите безопасность в пространство имен по умолчанию...
просто скопируйте эту строку:
<beans xmlns="http://www.springframework.org/schema/security"
и мимо него внутри тега открытия бобов
или вы также можете использовать префиксы для всех тегов безопасности, таких как:
<security:http>
это работает правильно..
<?xml version="1.0" encoding="UTF-8"?>
<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:security="http://www.springframework.org/schema/security"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd
http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.1.xsd">
<context:component-scan base-package="tudu.security" />
<security:global-method-security
secured-annotations="enabled" />
<security:http>
<security:intercept-url pattern="/AJAX/**"
access="ROLE_USER" />
<security:intercept-url pattern="/TUDU/WELCOME"
access="ROLE_ANONYMOUS,ROLE_USER" />
<security:intercept-url pattern="/TUDU/RECOVERPASSWORD"
access="ROLE_ANONYMOUS,ROLE_USER" />
<security:intercept-url pattern="/TUDU/REGISTER"
access="ROLE_ANONYMOUS,ROLE_USER" />
<security:intercept-url pattern="/TUDU/ADMIN"
access="ROLE_ADMIN" />
<security:intercept-url pattern="/TUDU/**"
access="ROLE_USER" />
<security:intercept-url pattern="/SERVLET/**"
access="ROLE_USER" />
<security:form-login login-processing-url="/TUDU/LOGIN"
login-page="/TUDU/WELCOME" authentication-failure-url="/TUDU/WELCOME?AUTHENTICATION=FAILURE"
default-target-url="/TUDU/LISTS" always-use-default-target="true" />
<security:remember-me key="TUDUROCKS" />
<security:logout logout-url="/TUDU/LOGOUT" />
</security:http>
<security:authentication-manager alias="AUTHENTICATIONMANAGER">
<security:authentication-provider user-service-ref="USERDETAILSSERVICE"/>
</security:authentication-manager>
</beans>