测试我的应用程序我决定关闭数据库。
public Object getEntityById(Class<?> clazz, Object _id) throws PersistenceServiceException {
Object o = null;
try {
o = entityManager.find(clazz, _id);
} catch (Exception e) {
throw new PersistenceServiceException(e);
}
return o;
}
因此,任何数据库异常都应该传递给调用者。
在控制器中我有
try {
template = (Template)persistenceService.getEntityById(Template.class, id);
} catch (PersistenceServiceException e) {
response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
response.setStatusMessage("INTERNAL SERVER ERROR");
response.setData(e);
return response;
}
调试时,我可以看到 DatabaseException 被抛出。
但是在servlet上下文中,一旦我有了这个......
<beans:bean id="exceptionResolver" class="org.springframework.web.servlet.handler.SimpleMappingExceptionResolver">
<beans:property name="defaultErrorView" value="core/error.uncatched" />
</beans:bean>
它一直将上述错误视为未处理。
我怎样才能在控制器上捕捉到它?为什么会这样?
例外
ERROR: org.springframework.transaction.interceptor.TransactionInterceptor - **Application exception overridden by commit exception**
com.company.exceptions.PersistenceServiceException: Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.6.0.v20130619-7d05127): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure