java NoClassDefFoundError: org/springframework/beans/factory/SmartInitializingSingleton

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

NoClassDefFoundError: org/springframework/beans/factory/SmartInitializingSingleton

javaspringjmxspring-jmx

提问by pklndnst

I was recently running into an issue using Spring JMX. The only thing I want to reach is to export a simple Spring Bean for monitoring with JConsole. My goal is to integrate Spring JMX into an existing Spring web application running on an embedded Jetty server. But every time I start the application having JMX configured im running into the following exception:

我最近在使用 Spring JMX 时遇到了一个问题。我唯一想要实现的是导出一个简单的 Spring Bean 以使用 JConsole 进行监控。我的目标是将 Spring JMX 集成到在嵌入式 Jetty 服务器上运行的现有 Spring Web 应用程序中。但是每次我启动配置了 JMX 的应用程序时,都会遇到以下异常:

org.springframework.beans.factory.CannotLoadBeanClassException: Error loading class [org.springframework.jmx.export.MBeanExporter] for bean with name 'exporter' defined in URL [file:/C:/Users/max.mustermann/workspace_intranetportal/my_webapp/target/classes/META-INF/appContext.xml]: problem with class file or dependent class; nested exception is java.lang.NoClassDefFoundError: org/springframework/beans/factory/SmartInitializingSingleton

Google couldn't help me so far.

到目前为止,谷歌帮不了我。

My Spring Bean looks like this:

我的 Spring Bean 看起来像这样:

public class JmxTestBean implements IJmxTestBean {

private String  name;
private int     age;
private boolean isTest;

@Override
public int add(int x, int y) {
    return x + y;
}

@Override
public long myOperation() {
    return 10L;
}

@Override
public int getAge() {
    return age;
}

@Override
public void setAge(int age) {
    this.age = age;
}

@Override
public String getName() {
    return name;
}

@Override
public void setName(String name) {
    this.name = name;
}

And these are the lines I added to Spring's appContext.xml:

这些是我添加到 Spring 的 appContext.xml 中的几行:

<bean id="exporter" class="org.springframework.jmx.export.MBeanExporter">
    <property name="beans">
        <map>
            <entry key="test:name=testBean" value-ref="testBean" />
        </map>
    </property>
</bean>

<bean id="testBean" class="com.big.intranet.test.JmxTestBean">
    <property name="name" value="TEST" />
    <property name="age" value="100" />
</bean>

Deleting the lines I just showed you, the application is running fine. Does anyone have an idea how to solve that problem? Thanks everyone!

删除我刚刚向您展示的行,应用程序运行良好。有谁知道如何解决这个问题?感谢大家!

采纳答案by pklndnst

As I already pointed out in my comment, there're two essential requirements that should be followed when working with Spring JMX:

正如我在评论中已经指出的那样,在使用 Spring JMX 时应遵循两个基本要求:

  1. As M.Deinumexplained, always make sure that your Spring dependencies share the same version and that - if possible - always the latest version is used.
  2. Be careful that the bean tag's lazy_initattribute is at least set to false(which should be the default behavior if I remember correctly).
  1. 正如M.Deinum解释的那样,始终确保您的 Spring 依赖项共享相同的版本,并且 - 如果可能 - 始终使用最新版本。
  2. 请注意 bean 标记的lazy_init属性至少设置为false(如果我没记错的话,这应该是默认行为)。

Following these rules, everything should work well. Thank you all for participating!

遵循这些规则,一切都应该运行良好。感谢大家的参与!

回答by Anil

I have update from spring 4.0.0.RELEASE to 4.1.5.RELEASE, this solved my problem.

我已经从 spring 4.0.0.RELEASE 更新到 4.1.5.RELEASE,这解决了我的问题。

回答by Abhiram

I had the same issue. I changed the validator dependency from springfox-bean-validators:2.6.1 to hibernate-validator:5.3.4.Final. Then it worked.

我遇到过同样的问题。我将验证器依赖项从 springfox-bean-validators:2.6.1 更改为 hibernate-validator:5.3.4.Final。然后它起作用了。