昨天想整合下springmvc和mybatis,用junit写了个测试,测试过程中,mybatis的mapper无法注入,报BeanCreationException,相关信息大家看下,帮小弟解决下
1 错误堆栈信息
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'com.hft.dal.mapper.AccountMapperTest': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.hft.dal.mapper.AccountMapper com.hft.dal.mapper.AccountMapperTest.accountMapper; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [com.hft.dal.mapper.AccountMapper] 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)}
2 applicationContext.xml
<context:component-scan base-package="com.hft" />
<context:annotation-config />
<tx:annotation-driven />
<bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource"
destroy-method="close">
<property name="driverClassName" value="com.mysql.jdbc.Driver" />
<property name="url" value="jdbc:mysql://127.0.0.1:3306/test" />
<property name="username" value="root" />
<property name="password" value="root" />
</bean>
<bean id="transactionManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource" />
</bean>
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="mapperLocations">
<list>
<value>classpath*:com/hft/dal/mapper/*Mapper.xml</value>
</list>
</property>
</bean>
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="com.hft.dal.mapper" />
<property name="markerInterface" value="com.hft.dal.mapper.MarkerInterfaceMapper" />
</bean>
3 AccountMapper类,MarkerInterfaceMapper是个空接口
public interface AccountMapper extends MarkerInterfaceMapper {
public List<Account> getAllAccount();
public void addAccount(Account account);
}
4 junittest类
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations={"classpath*:applicationContext.xml"})
public class AccountMapperTest extends AbstractJUnit4SpringContextTests{
@Autowired
private AccountMapper accountMapper;
@Test
public void testGetAllAccount() {
System.out.println(accountMapper.getAllAccount().size());
}
5 所引入的的包
6 项目目录结构
相关推荐
spring/springmvc/mybatis所需jar包
Spring/SpringMVC/MyBatis整合,可事务回滚
spring_mybatis 整合jar包,基本常用jar包的整合,。。。。。。。。。。。。。。。
ssm框架脚手架java基础配置文件Spring/SpringMVC/MyBatis eclipse下。ssm框架脚手架java基础配置文件Spring/SpringMVC/MyBatis eclipse下。ssm框架脚手架java基础配置文件Spring/SpringMVC/MyBatis eclipse下。...
maven+spring+mybatis+junit实例
改代码是我的我的一个项目自己写完后自测所以就写了这个junit的单元测试类,以及可能会遇到的一些问题,以及其中的一些经验,项目用的是spring + mybatis。我写的这个测试类基本概括了单元测试的基本用法,只要按照...
spring-mybatis整合jar包spring-mybatis整合jar包spring-mybatis整合jar包
spring mvc mybatis 整合源码,带数据库脚本,带详细注释,适合初、中、高各级开发人员使用
全注解零配置Spring/SpringMVC/Mybatis/Swagger,工程里有初始化脚本。
Spring-Mybatis整合包含基本的增删改查简单易懂!
这是一个小型的项目,关于spring和mybatis整合的小项目,直接可运行,无错误
使用Spring框架和MyBatis框架整合时需要的所有jar包,
spring3 + mybatis3 + junit4 可运行项目示例 可进行单元测试,集成测试。。。
maven spring spring mvc mybatis 整合
spring和mybatis整合 jar包 spring和mybatis整合 jar包
Spring-Springmvc-Mybatis整合以及后续开发所需要的所有jar包
Spring与Mybatis整合,一个简单的demo,包括配置文件等
spring springmvc mybatis的整合jar包,以及mysql,Junit,fastJson等的jar包,导入这些jar包 搭一个SSM的环境,可以使用SSM框架做一个简单的能够实现增删改查的小项目,具体的jar包及其版本如下 : aopalliance-1.0....
spring整合Mybatis纯净项目,基础搭建,下载就用,包含整套源码,jar包
spring和mybatis整合.zip