Spring MVC Security XML 配置

最近又倒騰回去XML方式配置Spring了

基本上項目都需要Spring + Spring Security + Spring MVC, 問題就在於這些在web.xml怎麼去配置。試了半天,如果把MVC的配置文件放到context-param中去的話會導致bean被初始化兩遍。 最後發現應該是spring和security的配置放到context-param中,mvc相關的(比如controller)都放到servlet的init-param中,示例如下:

<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/spring/applicationContext.xml
/WEB-INF/spring/security.xml
</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<servlet>
<servlet-name>appServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring/app-servlet-context.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>appServlet</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章