将ContextLoaderListener添加到Spring MVC中的web.xml
我是Spring MVC的新手。 我有一个Web应用程序。 我有以下配置:
list.html spring org.springframework.web.servlet.DispatcherServlet 1 spring /
我是否需要将以下行添加到web.xml文件中?
org.springframework.web.context.ContextLoaderListener
是的,您需要在web.xml
添加ContextLoaderListener
,仅当您在加载应用程序时还要加载其他Spring上下文xml文件时,您可以将它们指定为
contextConfigLocation /WEB-INF/spring-security.xml
仅当您有两个config xml文件时。 一个是Services / DAO,另一个是Controller。 如果您在一个spring配置文件中配置了所有内容,则不需要ContextLoaderListener
,只需调度程序servlet即可。
建议将config拆分为两个,并使用ContextLoaderListener
创建根应用程序上下文和调度程序servlet以创建Web层应用程序上下文。
它是可选的,你真的不需要它只是为了Spring MVC( DispatcherServlet
会这样做)。 但是必须将Spring安全性添加到Spring MVC中
org.springframework.web.context.ContextLoaderListener
只需注意一句,如果使用ContextLoaderListener
,则必须添加DelegatingFilterProxy
:
org.springframework.web.context.ContextLoaderListener springSecurityFilterChain org.springframework.web.filter.DelegatingFilterProxy springSecurityFilterChain /admin contextConfigLocation /WEB-INF/spring-security.xml
在你的web.xml中也是如此。 抱歉四年太晚了。 干杯
spring org.springframework.web.servlet.DispatcherServlet contextConfigLocation classpath:applicationContext.xml,WEB-INF/spring-security.xml 1 spring UR_PATTERN
这对我来说很好。
- Spring Boot测试中的MockBean注释导致NoUniqueBeanDefinitionException
- 从JLabel中选择文本?
- ClassCastException将List 转换为Class
- 如果他再次在相同或不同的浏览器上登录,如何注销用户的上一个会话
- 如何在Spring Boot中模拟数据库连接以进行测试?
- 反向单链表Java
- 使用部分定义的模式映射文档
- Spring IoC – dependency injection – > NullPointerException
- 在尝试使用unboundid LDAP SDK更改scala中的密码时,如何解决“WILL_NOT_PERFORM”MS AD回复?