想要进行spring+springMVC+Hibernate整合,启动tomcat的时候发生了错误

警告: Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'studentController': Unsatisfied dependency expressed through field 'studentService'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'studentService': Unsatisfied dependency expressed through field 'studentDAO'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'studentDAO': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in class path resource [applicationContext.xml]: Cannot resolve reference to bean 'dataSource' while setting bean property 'dataSource'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [applicationContext.xml]: Error setting property values; nested exception is org.springframework.beans.PropertyBatchUpdateException; nested PropertyAccessExceptions (1) are:
PropertyAccessException 1: org.springframework.beans.MethodInvocationException: Property 'driverClassName' threw exception; nested exception is java.lang.IllegalStateException: Could not load JDBC driver class [com.mysql.jdbc.Driver]

3个回答

下面说Could not load JDBC driver class [com.mysql.jdbc.Driver]
可能是你的mysql连接的包没有导进来

1.在项目properties->buildPath 的library中看看有没有mysql-connector-java-x.x.x-bin.jar

2.如果没有就下载mysql-connector-java-x.x.x-bin.jar

3. properties->buildPath 的library,在“库”选项卡中,选择“添加外部JAR”,找到下载的mysql-connector-java-5.1.22-bin.jar文件,将其添加进项目。

注意 Error creating bean with name 'studentController': Unsatisfied dependency expressed through field 'studentService'

意思是 通过现场的studentdao表示不满的依赖 由于Struts2+Spring+Hibernate,利用Spring注解进行注入,但是需要扫描基本包下面的接口
和类,**applicationContext.xml** 文件中没有配置 ,另外Dao中的属性没有设置好 依赖注入也没有成功,可以看看配置的地方,希望能給你帮助

数据库驱动类找不到,导致注入datasource数据源失败,
导致dao层注入失败,
导致service层失败,
导致controller层失败,
导致Spring容器注入Bean过程失败。
完毕!!!

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐