Spring JMX集成问题

时间:2015-11-10 09:13:16

标签: java spring jmx spring-jmx

我正在使用如下的java类,

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;
    }
}

在我的应用程序上下文中,我有如下配置。

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

如果异常工作正常,则返回值为1.但是如果文件存在则会出现运行时异常,例如。

javax.management.MBeanException:尝试调用操作时在RequiredModelMBean中抛出RuntimeException

请帮帮我

1 个答案:

答案 0 :(得分:1)

添加catch (RuntimeException e) catch块并打印堆栈跟踪,以便了解底层问题是什么。