报的错误是:
No qualifying bean of type [com.*.*.*.*.*.dao.UserDao] found for
dependency: expected at least 1 bean which qualifies as autowire
candidate for this dependency. Dependency annotations:
{@javax.annotation.Resource(shareable=true, mappedName=, description=, name=, type=class java.lang.Object, authenticationType=CONTAINER)}
错误描述:dao层的UserDao接口的对象不能注入
我的service是这样的
@Service("xxxService")
public class Hl7sysServiceImlp implements Hl7sysService {
@Resource
private Hl7SystemDao hl7sysdao;
@Override
public List<Hl7sys> searchHl7sys() throws Exception{
return hl7sysdao.selectAllSys();
}
}
可能的原因:
1、没有在上一层调用中加注解,如@Resource,可是我加了
2、配置文件不正确(路径要写对),但是我的是正确的
<!-- myBatis文件 -->
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="configLocation" value="classpath:spring/mybatis-config.xml"/>
<!-- 因为映射接口文件不放在同一个包下,所以需要配置xml的位置 -->
<property name="mapperLocations" value="classpath:mapping/*.xml" />
</bean>
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<!-- 配置接口包的位置 -->
<property name="basePackage" value="com.spring.dao"/>
<property name="sqlSessionFactoryBeanName" value="sqlSessionFactory" />
</bean>
3、没有写实现接口的xml文件,我写了
4、根本就木有加载spring-mybatis.xml文件!这个原因比较隐蔽!需要
在web.xml中添加上下文监听器
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:spring/spring-mybatis.xml</param-value>
</context-param>
<!-- 上下文监听器 -->
至此,问题解决!!感谢这篇博客
http://blog.csdn.net/u012385190/article/details/53186552