【发布时间】:2018-05-27 11:16:10
【问题描述】:
我正在使用带有 Hibernate 的 Spring ORM,当我编写命令时
hibernateTemplate.save(entityInstance);
(entityInstance 显然是 User 实体的一个实例)
我收到此错误:
The type org.springframework.dao.DataAccessException cannot be resolved. It is indirectly referenced from required .class files
即使我按照(工作)教程一步一步(和逐个代码)进行操作,它也不起作用。 这是我的 pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.dsystems</groupId>
<artifactId>newtokenmanager</artifactId>
<packaging>war</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>newtokenmanager Maven Webapp</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>5.0.2.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-tx</artifactId>
<version>5.0.2.RELEASE</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>5.2.5.Final</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
<version>5.0.2.RELEASE</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.45</version>
</dependency>
</dependencies>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.2</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
Eclipse 还建议我作为“快速修复”从菜单中配置构建路径,但我不知道具体该怎么做。 正如一些人在 SO 上针对类似问题提出的建议,我尝试删除并重新加载 JRE 系统库和 Maven 依赖项,但没有奏效。
【问题讨论】:
-
你是如何将项目导入eclipse的?
-
我没有导入它。我从 Maven Archetype (web mvc) 创建它并按照教程进行操作。
-
如果你展开你的项目下的Maven Dependencies文件夹,你看到spring-tx jar了吗?
-
是的,版本 5.0.2.RELEASE
-
尝试在您的项目上执行 mvn clean install,因为看起来您正在尝试引用不在项目构建路径中的 spring jar 之一。还要在 Eclipse 中执行 Project->Clean & set enable Build Automatically。
标签: java hibernate spring-mvc orm