我有一个像下面这样的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
请帮助我
添加一个catch (RuntimeException e)
捕获块并打印堆栈跟踪,这样您就可以看到潜在的问题是什么了。