NoClassDefFoundError: org/springframework/beans/factory/SmartInitializingSingleton

11,272

Solution 1

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

  1. As M.Deinum explained, 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_init attribute is at least set to false (which should be the default behavior if I remember correctly).

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

Solution 2

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

Share:
11,272
pklndnst
Author by

pklndnst

Updated on June 15, 2022

Comments

  • pklndnst
    pklndnst almost 2 years

    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:

    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:

    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:

    <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!

  • Vinod Jayachandran
    Vinod Jayachandran over 8 years
    Did you upgrade Spring core ?
  • Anil
    Anil over 8 years
    I have added to the all spring jars that were there in my pom file. If you are not using maven, it will bit difficult to manage the dependencies. I suggest to use maven.
  • palimpsestor
    palimpsestor over 8 years
    Makes sense, looks like SmartInitializingSingleton was only introduced in version 4.1.0 of the spring-beans jar.