无法初始化上下文,因为已存在根应用程序上下文

时间:2015-06-05 09:12:31

标签: spring spring-mvc spring-security



<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">

	<context-param>
		<param-name>contextConfigLocation</param-name>
		<param-value>classpath:/jpaContext.xml</param-value>
	</context-param>

	<listener>
		<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
	</listener>
	
	<filter>
		<filter-name>SpringOpenEntityManagerInViewFilter</filter-name>
		<filter-class>org.springframework.orm.jpa.support.OpenEntityManagerInViewFilter</filter-class>
	</filter>
	
	<filter-mapping>
		<filter-name>SpringOpenEntityManagerInViewFilter</filter-name>
		<url-pattern>/*</url-pattern>
	</filter-mapping>
	
	<servlet>
		<servlet-name>fitTrackerServlet</servlet-name>
		<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
		<init-param>
			<param-name>contextConfigLocation</param-name>
			<param-value>/WEB-INF/config/servlet-config.xml</param-value>
		</init-param>
	</servlet>
	
	<servlet-mapping>
		<servlet-name>fitTrackerServlet</servlet-name>
		<url-pattern>*.html</url-pattern>
	</servlet-mapping>
	
	<servlet-mapping>
		<servlet-name>fitTrackerServlet</servlet-name>
		<url-pattern>/pdfs/**</url-pattern>
	</servlet-mapping>
	
	<servlet-mapping>
		<servlet-name>fitTrackerServlet</servlet-name>
		<url-pattern>/images/**</url-pattern>
	</servlet-mapping>
	
	<servlet-mapping>
		<servlet-name>fitTrackerServlet</servlet-name>
		<url-pattern>*.json</url-pattern>
	</servlet-mapping>
	
	<display-name>Archetype Created Web Application</display-name>
</web-app>
&#13;
&#13;
&#13;

我使用:this tutorial为我的演示应用程序(用户登录)添加了安全性,我收到的错误为:Cannot initialize context because there is already a root application context present - check whether you have multiple ContextLoader* definitions in your web.xml!

我添加了我的web.xml,后来我找到this tutorial,然后出现错误:No bean named 'springSecurityFilterChain' is defined。他们在教程中解释了

  

MessageSecurityWebApplicationInitializer将自动为应用程序中的每个URL注册springSecurityFilterChain过滤器。如果在其他WebApplicationInitializer实例中添加了Filters,我们可以使用@Order来控制Filter实例的排序。   我没理解上面的消息请帮我解决这个问题

1 个答案:

答案 0 :(得分:0)

将您的fitTrackerServlet servlet编辑为:

<servlet>
        <servlet-name>fitTrackerServlet</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>/WEB-INF/config/servlet-config.xml</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
</servlet>