java 无法解决 DataAccessException。它是从所需的 .class 文件间接引用的

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/47795169/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-03 09:48:38  来源:igfitidea点击:

DataAccessException cannot be resolved. It is indirectly referenced from required .class files

javahibernatespring-mvcorm

提问by odysseas

I'm usign Spring ORM with Hibernate, and when I write the command

我在 Hibernate 中使用 Spring ORM,当我编写命令时

hibernateTemplate.save(entityInstance);

(entityInstance is obviously an instance of a User entity)

(entityInstance 显然是一个 User 实体的实例)

I get this error:

我收到此错误:

The type org.springframework.dao.DataAccessException cannot be resolved. It is indirectly referenced from required .class files

Even though i followed a (working) tutorial step-by-step (and code-by-code) it doesn't work. This is my pom.xml

即使我一步一步地(和逐个代码)遵循(工作)教程,它也不起作用。这是我的 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 also suggests me as 'quick fix' to configure build path from the menu, but I don't know exactly what to do. As some people suggested for similar issues here on SO, I tried by removing and reloading both JRE System Library and Maven dependencies, but didn't work.

Eclipse 还建议我作为“快速修复”从菜单配置构建路径,但我不知道该怎么做。正如一些人在 SO 上针对类似问题建议的那样,我尝试删除并重新加载 JRE 系统库和 Maven 依赖项,但没有奏效。

采纳答案by Ritesh

Download jar from this link

从此链接下载jar

import into your project, it will resolve.

导入到您的项目中,它将解决。

Your HibernateTemplate class is importing org.springframework.dao.DataAccessExceptionclass which is not present in your classpath.

您的 HibernateTemplate 类正在导入org.springframework.dao.DataAccessException类路径中不存在的类。

回答by Ajay Kesarwani

Add in pom for Maven project

为 Maven 项目添加 pom

<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-tx</artifactId>
<version>3.1.1.RELEASE</version>
</dependency>

or add jar spring-tx

或添加 jar spring-tx

回答by Manoj

spring-tx.jar because I got this error:

spring-tx.jar 因为我收到了这个错误:

The type org.springframework.dao.DataAccessException cannot be resolved. It is indirectly referenced from required .class files TestSpring.java

无法解析 org.springframework.dao.DataAccessException 类型。它是从所需的 .class 文件 TestSpring.java 间接引用的

spring-core.jar because I got this error:

spring-core.jar 因为我收到了这个错误:

The type org.springframework.core.NestedRuntimeException cannot be resolved. It is indirectly referenced from required .class files TestSpring.java

无法解析 org.springframework.core.NestedRuntimeException 类型。它是从所需的 .class 文件 TestSpring.java 间接引用的

回答by Hazarath

The type org.springframework.dao.DataAccessExceptioncannot be resolved. for this error add the spring jar in classpath spring-tx-x.x.x.RELEASE.jar.

类型org.springframework.dao.DataAccessException无法解析。对于此错误,请在 classpath 中添加 spring jar spring-tx-x.x.x.RELEASE.jar