springmvc 执行@Test报错
来源:互联网 发布:spss数据显著性分析 编辑:程序博客网 时间:2024/06/08 12:26
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userDao' defined in class path resource [spring/bean.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.chen.ssm.dao.UserDao]: Specified class is an interface......Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.chen.ssm.dao.UserDao]: Specified class is an interface
问题描述:不能实例化[com.chen.ssm.dao.UserDao]这个对象
解决方法:
1、查看问题提示:主要注意Caused by: 后的信息提示
2、UserDao是个接口,UserDaoImpl是实现类
public interface UserDao { //根据id查询用户信息 public User findUserById(int id) throws Exception;}public class UserDaoImpl extends SqlSessionDaoSupport implements UserDao { public User findUserById(int id) throws Exception { // 继承SqlSessionDaoSupport,通过this.getSqlSession()得到sqlSession SqlSession sqlSession = this.getSqlSession(); User user = sqlSession.selectOne("test.findUserById",id); return user; }}
3、注意核心配置文件将两个类的连接
<?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:aop="http://www.springframework.org/schema/aop" xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.2.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.2.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.2.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.2.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.2.xsd"> <!-- 加载配置文件 --> <context:property-placeholder location="classpath:db.properties"/> <!-- 数据源,使用dbcp --> <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"> <property name="driverClassName" value="${jdbc.driver}"/> <property name="url" value="${jdbc.url}"/> <property name="username" value="${jdbc.username}"/> <property name="password" value="${jdbc.password}"/> <property name="maxActive" value="10"/> <property name="maxIdle" value="5"/> </bean> <!-- sqlSessionFactory --> <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"> <!-- 加载mybatis的配置文件 --> <property name="configLocation" value="mybatis/SqlMapConfig.xml"/> <!-- 数据源 --> <property name="dataSource" ref="dataSource"/> </bean> <!-- 原始dao接口 --> <bean id="userDao" class="com.chen.ssm.dao.UserDao"> <property name="sqlSessionFactory" ref="sqlSessionFactory"/> </bean> </beans>
忽然记得以前配置spring-hibernate核心配置文件时,好像将它们之间的路径写错过,最后发现
<!-- 原始dao接口 --> <bean id="userDao" class="com.chen.ssm.dao.UserDao"> <property name="sqlSessionFactory" ref="sqlSessionFactory"/> </bean>
里的class路径确实写错了,应该写成实现类的路径,修改如下
<bean id="userDao" class="com.chen.ssm.dao.UserDaoImpl"> <property name="sqlSessionFactory" ref="sqlSessionFactory"/> </bean>
阅读全文
0 0
- springmvc 执行@Test报错
- 执行test-framework报错error while loading shared libraries
- make test 报错
- eclipse安装testng后第一次执行maven clean成功,maven test也成功第二次执行maven clean报错解决方法:
- SpringMVC报错集中营
- 搭建springMVC报错
- springMVC+mybaties 报错
- springMVC报错NullPointerException
- SpringMVC报错
- springmvc启动报错
- springMVC test
- redis make test报错
- redis make test报错
- redis make test 报错
- springMVC ajax执行后端不报错 前端报state是404
- 执行脚本报错
- struts2 执行报错
- 执行java报错
- HDU 1272 小希的迷宫
- Interactive Data Visualization for the Web, 2nd Edition.pdf 英文原版 免费下载
- java日常学习:异常和finally块
- 【Unity】图形渲染优化、渲染管线优化、图形性能优化
- 三元表达式
- springmvc 执行@Test报错
- 二叉树的一系列基本操作
- Set集合TreeSet学习(Set集合学习二)
- 使用Gradle构建Android应用
- React菜鸟教程学习笔记
- 算法——背包问题 01背包+完全背包+多重背包
- 论「版本号」的正确使用方式
- Oracle之block能装多少行?以及dbms_rowid包讲解
- 初始R语言——决策树