整合 SpringMVC 3.2.5 和 Shiro 1.2.3

按着《SpringMVC整合Shiro》這篇博文來作便可。可是,在啓動時發現Spring的配置被載入兩次,很明顯SpringMVC 和 Shiro 所使用的不是同一個 Spring Application Context。在參考《ContextLoaderListener與DispatcherServlet所加載的applicationContext的區別》後,web.xml 配置改成:web

......
	<filter>
		<filter-name>shiroFilter</filter-name>
		<filter-class>
			org.springframework.web.filter.DelegatingFilterProxy
		</filter-class>
		<init-param>
			<param-name>targetFilterLifecycle</param-name>
			<param-value>true</param-value>
		</init-param>
		<init-param>
			<param-name>contextAttribute</param-name>
			<param-value>
				org.springframework.web.servlet.FrameworkServlet.CONTEXT.dispatch
			</param-value>
		</init-param>
	</filter>
	<filter-mapping>
		<filter-name>shiroFilter</filter-name>
		<url-pattern>/*</url-pattern>
	</filter-mapping>
......
	<servlet>
		<servlet-name>dispatch</servlet-name>
		<servlet-class>
			org.springframework.web.servlet.DispatcherServlet
		</servlet-class>
		<init-param>
			<param-name>contextConfigLocation</param-name>
			<param-value>classpath:dispatch-servlet.xml</param-value>
		</init-param>
		<load-on-startup>1</load-on-startup>
	</servlet>
	<servlet-mapping>
		<servlet-name>dispatch</servlet-name>
		<url-pattern>/</url-pattern>
	</servlet-mapping>
......
相關文章
相關標籤/搜索