Complete partial error log:
:
Error creating bean with name 'shiroFilter' defined in class path resource [spring_mvc_shiro.xml]: Cannot resolve reference to bean 'securityManager' while setting bean property 'securityManager';
Could not autowire field: private ;
No qualifying bean of type [] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@(required=true)}
spring_mvc_shiro.xml
<bean id="credentialsMatcher" class="">
<property name="hashAlgorithmName" value="md5"></property>
<property name="hashIterations" value="2"></property>
<property name="storedCredentialsHexEncoded" value="true"></property>
</bean>
<!-- Cache Management -->
<bean id="cacheManager" class=""></bean>
<bean id="userRealm" class="">
<property name="credentialsMatcher" ref="credentialsMatcher"></property>
</bean>
<!-- Shiro Security Manager -->
<bean id="securityManager" class="">
<property name="realm" ref="userRealm"></property>
<!-- <property name="cacheManager" ref="cacheManager"></property> -->
</bean>
<!--
The Shiro main filter itself is very powerful, and its power is that it supports the execution of any custom filter based on URL path expressions.
In web applications, Shiro can control web requests must be intercepted by Shiro's main filter. Shiro provides perfect support for Spring-based web applications.
-->
<bean id="shiroFilter" class="">
<!-- Shiro's core security interface, this property is required -->
<property name="securityManager" ref="securityManager"></property>
<!-- The link when logging in (login page address), non-essential attributes, will automatically search for the "/" page in the root directory of the web project -->
<property name="loginUrl" value=""></property>
<!-- The connection to jump after login is successful (in this case this attribute cannot be used, because the processing logic after login is hard-coded in the LoginController) -->
<!-- <property name="successUrl" value="" ></property> -->
<!-- The connection displayed when a user accesses a resource that is not authorized to him -->
<!-- <property name="unauthorizedUrl" value=""></property> -->
<property name="filterChainDefinitions">
<value>
/user/**=anon
/js/**=anon
/css**/=anon
</value>
</property>
</bean>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
classpath:spring_mybatis.xml,
classpath:spring_mvc_shiro.xml
</param-value>
</context-param>
...
<servlet>
<servlet-name>spring</servlet-name>
<servlet-class></servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:spring_mvc.xml</param-value>
</init-param>
<!-- Set execution priority -->
<load-on-startup>1</load-on-startup>
</servlet>
UserRealm .java
public class UserRealm extends AuthorizingRealm {
@Autowired
private UserService userService;
@Override
protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals) {
...
Error analysis:
The program started normally before integrating shiro, but after integration, the problem occurred because when the project started and loaded.<context-param>
The execution order is in<servlet>
Previously, however, when loading the injection into UserRealm, injection failed when the UserService is injected again. The reason is that the annotation is turned on, and the configuration of the scanning package is written in spring_mvc.xml, which means that we are accessing a bean that we have not injected into the Spring container. So an exception occurred.
The solution is to configure the scan package and enable automatic annotation before or in the shiro configuration file.
Add the corresponding spring_mvc_shiro.xml file:
<mvc:annotation-driven />
<!-- Scanned package -->
<context:component-scan base-package=".*.service,.*.mapper" />
OK