java NoClassDefFoundError: DataAccessException 使用 spring

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/32331520/
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-02 20:01:37  来源:igfitidea点击:

NoClassDefFoundError: DataAccessException using spring

javaspringmaven

提问by Wingie

I know this has been discussed a lot, but somehow none of the previously asked questions is applicable to my case. When loading my application I get the following stacktrace:

我知道这已经讨论了很多,但不知何故,以前提出的问题都不适用于我的情况。加载我的应用程序时,我得到以下堆栈跟踪:

Exception in thread "JavaFX Application Thread" java.lang.NoClassDefFoundError: org/springframework/dao/DataAccessException
at java.lang.Class.getDeclaredConstructors0(Native Method)
at java.lang.Class.privateGetDeclaredConstructors(Class.java:2663)
at java.lang.Class.getConstructor0(Class.java:3067)
at java.lang.Class.newInstance(Class.java:408)
at sun.reflect.misc.ReflectUtil.newInstance(ReflectUtil.java:51)
at javafx.fxml.FXMLLoader$ValueElement.processAttribute(FXMLLoader.java:923)
at javafx.fxml.FXMLLoader$InstanceDeclarationElement.processAttribute(FXMLLoader.java:967)
at javafx.fxml.FXMLLoader$Element.processStartElement(FXMLLoader.java:216)
at javafx.fxml.FXMLLoader$ValueElement.processStartElement(FXMLLoader.java:740)
at javafx.fxml.FXMLLoader.processStartElement(FXMLLoader.java:2701)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2521)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2435)
at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2403)
at de.festo.rs.windows.FXApplStarter.run(FXApplStarter.java:29)
at com.sun.javafx.application.PlatformImpl.lambda$null4(PlatformImpl.java:292)
at com.sun.javafx.application.PlatformImpl$$Lambda/29905907.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater5(PlatformImpl.java:291)
at com.sun.javafx.application.PlatformImpl$$Lambda/20965065.run(Unknown Source)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.lambda$null1(WinApplication.java:102)
at com.sun.glass.ui.win.WinApplication$$Lambda/6575340.run(Unknown Source)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.ClassNotFoundException: org.springframework.dao.DataAccessException
    at java.net.URLClassLoader.run(URLClassLoader.java:372)
    at java.net.URLClassLoader.run(URLClassLoader.java:361)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:360)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    ... 24 more

In most of the threads I read concerning similar errors people were indeed missing the spring-tx jar which I definately don′t. It is declared in my maven dependencies along with the other spring jars neededd like this:

在我读到的大多数关于类似错误的帖子中,人们确实错过了我绝对没有的 spring-tx jar。它在我的 Maven 依赖项中与其他需要的 spring jar 一起声明,如下所示:

        <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-tx</artifactId>
        <version>4.2.0.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-beans</artifactId>
        <version>4.2.0.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-jdbc</artifactId>
        <version>4.2.0.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-context</artifactId>
        <version>4.2.0.RELEASE</version>
    </dependency>

When investigating my deployed output the jars are there as well. Nevertheless the mentioned error is thrown. I am really desperate with this. Please note, that the application is not a WebApp but kind of a standalone application loaded from another program.

在调查我部署的输出时,罐子也在那里。尽管如此,还是抛出了提到的错误。我真的很绝望。请注意,该应用程序不是 WebApp,而是一种从另一个程序加载的独立应用程序。

Funny thing is that my colleague can′t reproduce the error. For that reason I guess it′s some kind of race condition between my JavaFX loader loading the result of the spring-jdbc query into its datamodel. I don′t have any proof for this, it′s just kind of a gut instinct. Any help or tipp would be really appreciated. If further information is needed please let me know.

有趣的是,我的同事无法重现该错误。出于这个原因,我猜这是我的 JavaFX 加载器将 spring-jdbc 查询的结果加载到其数据模型之间的某种竞争条件。我没有任何证据证明这一点,这只是一种直觉。任何帮助或提示将不胜感激。如果需要更多信息,请告诉我。

回答by Abhilash Ranjan

to fix this issue i have just moved the application.java under the base package like i have created groupid demo.test.activemqand created the same package name in srcfolder and then restarted. it works for me.

为了解决这个问题,我刚刚将 application.java 移动到基本包下,就像我创建了 groupiddemo.test.activemq并在src文件夹中创建了相同的包名,然后重新启动。这个对我有用。

回答by Garry

Class : org.springframework.dao.DataAccessExceptionis defined in Spring-DAO. Check if have below dependency.

类:org.springframework.dao.DataAccessException在 Spring-DAO 中定义。检查是否有以下依赖项。

<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-dao</artifactId>
    <version>2.0.8</version>
</dependency>

回答by Torsten

Another posibility is, that you hide some dependencies through a scopelike test:

另一种可能性是,您通过scope类似的测试隐藏了一些依赖项:

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-tx</artifactId>
        <scope>test</scope>
    </dependency>

Just remove the scope (or set the default: compile)

只需删除范围(或设置默认值:编译)