SpringMvc+MyBatis+Shiro整合,shiro的realm不能注入Bean
2017-07-01 09:33
471 查看
springMvc+Mybatis和shiro整合,shiro的realm引入Autowire加入接口数据,但是一直无法成功注入,提示问题如下:
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.sxkj.service.inter.UserServerInter]
found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
碰到此问题,一开始以为是springmvc注入配置问题,但是controller注入又都正常,此时陷入百思不得解。一项项跟踪,发现原来shiro
自定义realm的认证阶段属于filter,当时的spring bean还没有读取进来。
最后通过配置web.xml文件,把spring mvc的xml提高一点优先级,才最终解决了这个问题。下面是web.xml完整配置:
红色为添加的部分,有碰到此问题的同学可以看看。
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.sxkj.service.inter.UserServerInter]
found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
碰到此问题,一开始以为是springmvc注入配置问题,但是controller注入又都正常,此时陷入百思不得解。一项项跟踪,发现原来shiro
自定义realm的认证阶段属于filter,当时的spring bean还没有读取进来。
最后通过配置web.xml文件,把spring mvc的xml提高一点优先级,才最终解决了这个问题。下面是web.xml完整配置:
<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" version="3.1"> <context-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:spring-mybatis.xml,classpath:dispatcher-servlet.xml,classpath:spring-shiro.xml</param-value> </context-param> <servlet> <servlet-name>dispatcher</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <init-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:dispatcher-servlet.xml</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <!-- 设置拦截 !--> <servlet-mapping> <servlet-name>dispatcher</servlet-name> <url-pattern>/</url-pattern> </servlet-mapping> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <context-param> <param-name>log4jContextName</param-name> <param-value>log4jContext</param-value> </context-param> <!-- 添加shiro的过滤器代理!--> <filter> <filter-name>shiroFilter</filter-name> <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class> <async-supported>true</async-supported> <init-param> <param-name>targetFilterLifecycle</param-name> <param-value>true</param-value> </init-param> </filter> <filter-mapping> <filter-name>shiroFilter</filter-name> <!-- 此处必需写成"/*",如果只写"/" ,过滤器没有作用--> <url-pattern>/*</url-pattern> </filter-mapping> </web-app>
红色为添加的部分,有碰到此问题的同学可以看看。
相关文章推荐
- spring mvc+Mybatis整合shiro 第二章Realm
- spring mvc+Mybatis整合shiro 第四章 SessionDAO
- Shiro+SpringMVC+MyBatis整合
- SpringMVC + Mybatis + Shiro 权限整合【转】
- SpringMVC + Mybatis + Shiro 权限整合【转】
- Spring + SpringMVC + Mybatis + Shiro 整合(下)
- spring mvc+Mybatis整合shiro 第五章 缓存
- SpringMVC + Mybatis + Shiro 权限整合【转】
- springboot与mybatis整合dao层不能注入的问题
- springMVC mybatis整合dao接口(mapper接口) spring注入失败
- ssm和shiro整合,shiro的自定义的realm不能自动注入的问题
- spring mvc+Mybatis整合shiro 第一章 整体配置
- springMvc和shiro整合,shiro的realm不能自动注入的问题
- shiro +spring + spring mvc+ mybatis整合【转】
- Spring+Spring MVC+Mybatis整合配置AOP不生效的解决方案以及Bean初始化重复加载两次(疑难杂症)
- Spring mvc + MyBatis 整合Shiro
- java框架整合Springmvc+mybatis+shiro+bootstrap
- shiro +spring + spring mvc+ mybatis整合
- springMvc和shiro整合,shiro的realm不能自动注入的问题
- SSM springmvc mybatis 整合 bootstrap maven shiro druid ehcache SSM