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!
I have update from spring 4.0.0.RELEASE to 4.1.5.RELEASE, this solved my problem.