Failed to load ApplicationContext求大神帮助

Carmelo1 2017-03-06 11:42:03
package com.huashao.sm_test.test;

import java.util.Date;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import com.huashao.sm_test.bean.User;
import com.huashao.sm_test.mapper.UserMapper;


@RunWith(SpringJUnit4ClassRunner.class)//使用Spring的测试框架
@ContextConfiguration("/beans.xml")//加载spring的配置文件beans.xml
public class SMTest {

@Autowired
private UserMapper userMapper;
@Test
public void testAdd(){
User user = new User(-1,"huashao",new Date(),123456);
userMapper.save(user);

}
}




<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context" xmlns:util="http://www.springframework.org/schema/util"
xmlns:jee="http://www.springframework.org/schema/jee" xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:jpa="http://www.springframework.org/schema/data/jpa" xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.2.xsd
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.2.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.2.xsd
http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa-1.3.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd">

<!-- 1.数据源:DriverManagerDataSource -->
<bean id="ds" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="url" value="jdbc:mysql://localhost:3306/mybatis"></property>
<property name="driverClassName" value="com.mysql.jdbc.Driver"></property>
<property name="username" value="root"></property>
<property name="password" value="1234"></property>
</bean>

<!-- 2.mybatis的SqlSession的工厂:SqlSessionFactoryBean
dataSource:引用数据源
typeAliasesPackage:引用实体类的包名,自动将实体类名映射成别名
-->
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="ds"></property>
<!-- <property name="typeAliasesPackage" value="com.huashao.sm_test.bean"></property> -->
</bean>

<!-- 3. mybatis自动扫描加载Sql映射文件/接口:MapperScannerConfigurer
basePackage:指定Sql映射文件/接口所在的包(自动扫描)
sqlSessionFactory:引用上面定义的sqlSessionFactory
-->
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="com.huashao.sm_test.bean"></property>
<property name="sqlSessionFactory" ref="sqlSessionFactory"></property>
</bean>

<!-- 4. 事务管理:DataSourceTransactionManager
dataSource:引用上面定义的数据源
-->
<bean id="txManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="ds"></property>
</bean>

<!-- 使用声明式事务
transaction-manager:引用上面定义的事务管理
-->
<tx:annotation-driven transaction-manager="txManager"/>
</beans>





...全文
1170 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

13,100

社区成员

发帖
与我相关
我的任务
社区描述
Java J2ME
社区管理员
  • J2ME社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧