Search code examples
javaspringjmxspring-jmx

Spring JMX Integration Issue


I am having a java class like below,

public class MyImportService {
    Logger m_logger = Logger.getLogger(MyImportService.class);
    @Autowired
    @Qualifier("tService")
    private TService m_tservice;
    public Integer import(String zipFilePath,String userName) {
        int result = 0;
        File file = new File(zipFilePath);
        try {
            FileInputStream fileInputStream = new FileInputStream(zipFilePath);
            ZipInputStream zipInputStream = new ZipInputStream(fileInputStream);
            m_taskservice.importT(zipInputStream, file.getName(), userName);
            m_logger.info("SuccessFully Imported"");
        }
        catch (IOException e){
            result =  1;
            m_logger.error("Error while importing the file :",e);
        }
        return result;
    }
}

In my application context I am having the configuration like below.

<bean id="myImportService" class="com.service.MyImportService " />
    <bean id="exporter"
          class="org.springframework.jmx.export.MBeanExporter">
        <property name="server" ref="mbeanServer" />
        <property name="beans">
            <map>
                <entry
                        key="application.MyApp:service=importTService"
                        value-ref="myImportService" />
            </map>
        </property>
    </bean>

In case of exception its working fine, am getting a return value as 1. But in case the file is present am getting a runtime exception like.

javax.management.MBeanException: RuntimeException thrown in RequiredModelMBean while trying to invoke operation

Please help me


Solution

  • Add a catch (RuntimeException e) catch block and print the stack trace so can you see what the underlying problem is.