2012-07-03 3 views
1

Я пытаюсь внедрить Spring безопасности для моего приложения GAE однако я получаю эту ошибку:Весна безопасности с GAE

No bean named 'springSecurityFilterChain' is defined 

Я добавил эту конфигурацию в моей web.xml:

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

И в контексте приложения:

<!-- Configure security --> 
<security:http auto-config="true"> 
    <security:intercept-url pattern="/**" access="ROLE_USER" /> 
</security:http> 

<security:authentication-manager alias="authenticationManager"> 
    <security:authentication-provider> 
     <security:user-service> 
      <security:user name="jimi" password="jimi" authorities="ROLE_USER, ROLE_ADMIN" /> 
      <security:user name="bob" password="bob" authorities="ROLE_USER" /> 
     </security:user-service> 
    </security:authentication-provider> 
</security:authentication-manager> 

Что может быть причиной ошибки?

ответ

1

Даже если вы не указали contextConfigLocation в своем web.xml, реализация контекста использует местоположение по умолчанию (с XmlWebApplicationContext: "/WEB-INF/applicationContext.xml").

Так что, я думаю, у вас уже есть одно applicationContext.xml, но не указано в вашем web.xml, но Spring смог загрузить его для вас. Но теперь у вас есть дополнительная конфигурация безопасности в отдельном файле. Таким образом, вы должны указать местоположение этого нового файла ApplicationContext-security.xml, как это в вашем web.xml:

Это будет заботиться о двух файлах:

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

или вы можете задать по отдельности запятая или пробел список также, как показано ниже:

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

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

Documentation: ContextLoader

+0

Я на самом деле помещен фильтр Весна безопасности в весенне-context.xml, который является applicationCon текст, определенный в web.xml, мне нужно поместить его в отдельный файл конфигурации пружины? – xybrek

+0

Нет, вам не обязательно иметь их в одном файле. – Ravi

+0

Вы добавили объявление схемы безопасности весны xmlns: security = "http://www.springframework.org/schema/security" и расположение к вашему spring-context.xml – Ravi