Springmvc and Shiro integration, Shiro realm does not automatically inject the problem

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.