The recent study of Shiro, the beginning of the encounter with great difficulties, commissioning for 3 hours.
The problem is described as follows: Shiro and spring MVC integration, Shiro custom realm.
The custom realm is not able to use the @autowired annotation tag to inject the relevant user service.
Baffled, a tracking, found that the original Shiro custom realm certification phase belongs to the filter, then the spring bean has not been read in.
Finally, by configuring the Web. xml file, a little higher priority is given to the spring MVC's XML to finally solve the problem.
1 <!--Configuring the Spring container listener - 2 <Context-param> 3 <Param-name>Contextconfiglocation</Param-name> 4 <Param-value> 5 /web-inf/classes/applicationcontext-shiro.xml,6 /web-inf/classes/spring-mvc.xml 7 </Param-value> 8 </Context-param> 9 <Listener> Ten <Listener-class>Org.springframework.web.context.ContextLoaderListener</Listener-class> One </Listener> A - lt;! --The first layer controller of the spring Web program, which handles the program request-- - <servlet> the <Servlet-name>Springdispatcherservlet</Servlet-name> - <Servlet-class>Org.springframework.web.servlet.DispatcherServlet</Servlet-class> - <Init-param> - <Param-name>Contextconfiglocation</Param-name> + <Param-value>Classpath:spring-mvc.xml</Param-value> - </Init-param> + <Load-on-startup>1</Load-on-startup> A </servlet> at - <servlet-mapping> - <Servlet-name>Springdispatcherservlet</Servlet-name> - <Url-pattern>/</Url-pattern> - </servlet-mapping>
Notice the red one, I put the SPRINGMVC configuration file up, put in the contextconfiglocation to load.
In this way, you can inject other registered beans in the filter phase.
Refer to this article for specific reference:
http://blog.csdn.net/godha/article/details/13025099
Springmvc and Shiro integration, Shiro realm does not automatically inject the problem