1

我有一个像下面这样的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

请帮我

4

1 回答 1

1

添加一个catch (RuntimeException e)catch 块并打印堆栈跟踪,这样您就可以看到根本问题是什么。

于 2015-11-10T14:19:05.373 回答