jpa error interceptor
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
package com.eactive.apim.portal.tools;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.aspectj.lang.annotation.AfterThrowing;
|
||||
import org.aspectj.lang.annotation.Aspect;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.PersistenceContext;
|
||||
|
||||
@Component
|
||||
@Aspect
|
||||
@Slf4j
|
||||
public class JpaErrorLoggingAspect {
|
||||
@PersistenceContext
|
||||
private EntityManager em;
|
||||
|
||||
@AfterThrowing(pointcut = "@annotation(org.springframework.transaction.annotation.Transactional)", throwing = "ex")
|
||||
public void onError(Exception ex) {
|
||||
try {
|
||||
String user = (String) em.createNativeQuery("select user from user").getSingleResult();
|
||||
log.error("DB USER = {}, SQL ERROR = {}", user, ex.getMessage() );
|
||||
} catch (Exception e) {
|
||||
log.error("Failed to fetch DB User", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -7,13 +7,13 @@
|
||||
<context-root>/</context-root>
|
||||
|
||||
<container-descriptor>
|
||||
<!-- <prefer-application-packages>-->
|
||||
<!-- <package-name>org.slf4j.*</package-name>-->
|
||||
<!-- <package-name>ch.qos.logback.*</package-name>-->
|
||||
<!-- <package-name>org.apache.log4j.*</package-name>-->
|
||||
<!-- <package-name>org.apache.commons.logging.*</package-name>-->
|
||||
<!-- </prefer-application-packages>-->
|
||||
<prefer-web-inf-classes>true</prefer-web-inf-classes>
|
||||
<prefer-application-packages>
|
||||
<package-name>org.slf4j.*</package-name>
|
||||
<package-name>ch.qos.logback.*</package-name>
|
||||
<package-name>org.apache.log4j.*</package-name>
|
||||
<package-name>org.apache.commons.logging.*</package-name>
|
||||
</prefer-application-packages>
|
||||
<!-- <prefer-web-inf-classes>true</prefer-web-inf-classes>-->
|
||||
</container-descriptor>
|
||||
|
||||
<session-descriptor>
|
||||
|
||||
Reference in New Issue
Block a user