发表于: 2019-11-28 19:15:37

1 1095


今天完成的事情:


Spring整合Mybatis


编写实体类


编写持久层接口


编写service层接口


编写service层实现类


Spring 配置文件



测试类

明天计划的事情:

学会使用Junit


遇到的问题:

错误信息: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'accountService'

解决

无法创建service实体类,因为在spring容器中id已经存在了,所以报这个错


错误信息:

org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.exceptions.PersistenceException: 

### Error querying database.  Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Failed to obtain JDBC Connection; nested exception is java.sql.SQLException: Connections could not be acquired from the underlying database!

### The error may exist in com/xiuzhen/dao/AccountDao.java (best guess)

### The error may involve com.xiuzhen.dao.AccountDao.findAll

### The error occurred while executing a query

### Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Failed to obtain JDBC Connection; nested exception is java.sql.SQLException: Connections could not be acquired from the underlying database!


解决

修改前


修改后


  • @RunWith就是一个运行器

  • @RunWith(JUnit4.class)就是指用JUnit4来运行

  • @RunWith(SpringJUnit4ClassRunner.class),让测试运行于Spring测试环境

  • @RunWith(Suite.class)的话就是一套测试集合

  • @ContextConfiguration Spring整合JUnit4测试时,使用注解引入多个配置文件

  • 单个文件
    @ContextConfiguration(Locations="classpath:applicationContext.xml")
    @ContextConfiguration(classes = SimpleConfiguration.class)

  • 多个文件时,可用
    @ContextConfiguration(locations = { "classpath:spring1.xml", "classpath:spring2.xml" })


错误信息:java.lang.IllegalStateException: Failed to load ApplicationContext

解决

sql语句编写,应该是因为预编译的问题


收获:

学会了Spring整合Mybatis


返回列表 返回列表
评论

    分享到