aspectj

Spring - slf4J : how to automatically log errors and exceptions?

五迷三道 提交于 2019-12-04 07:41:17
We are using Spring with slf4j and hibernate, I'm trying to figure out a way to log exceptions and errors automatically (i.e without initiating an instance of the debugger in each class), so that it may catch any error or exception thrown and also get class and method name in the log, I read a very short note about using aspects & interceptors for this, so could you provide me with some detailed way to implement this, Regards, an exception aspect could look like this: @Aspect public class ExceptionAspect { private static final Logger log = LoggerFactory.getLogger(ExceptionAspect.class); public

Pointcut for methods with @Scheduled Spring annotation

时光总嘲笑我的痴心妄想 提交于 2019-12-04 07:24:55
I want to have a AspectJ pointcut for methods annotated with @Scheduled . Tried different approaches but nothing worked. 1.) @Pointcut("execution(@org.springframework.scheduling.annotation.Scheduled * * (..))") public void scheduledJobs() {} @Around("scheduledJobs()") public Object profileScheduledJobs(ProceedingJoinPoint joinPoint) throws Throwable { LOG.info("testing") } 2.) @Pointcut("within(@org.springframework.scheduling.annotation.Scheduled *)") public void scheduledJobs() {} @Pointcut("execution(public * *(..))") public void publicMethod() {} @Around("scheduledJobs() && publicMethod()")

IDEA 10.5.2 Aspectj compiler - can't determine superclass of missing type org.springframework.transaction.interceptor.TransactionAspectSupport

北战南征 提交于 2019-12-04 07:17:29
Trying to make a module with spring aspects gives me: can't determine superclass of missing type org.springframework.transaction.interceptor.TransactionAspectSupport Works in other modules, what's up with this one? Missing dep? /S You'll need to add the spring-tx dependency to clear this: http://mvnrepository.com/artifact/org.springframework/spring-tx <dependency> <groupId>org.springframework</groupId> <artifactId>spring-tx</artifactId> <version>${spring.version}</version> </dependency> this is unfortunately an error that occurs from time to time when developing with AspectJ. Often, in the

Ignoring Aspectj during junit tests

[亡魂溺海] 提交于 2019-12-04 06:36:32
Here is situation: We have class with defined aspect to it's methodA; We have JUnit test for this methodA; When I run JUnit test it activates Aspect as well. Any thoughts how to ignore Aspects during unit tests? I have separated tests for my Aspects and it works fine. So in my unit test I want to test only methodA without any attached aspects. I use spring 3.0 and its aspectj support. Thanks in advance. Regards, Max You can disable the compile-time weaving that I assume your IDE is doing and use load-time weaving in your separated AspectJ tests. To enable load-time weaving you have to provide

Access a business method's local variable in a method which is in an ASPECT

和自甴很熟 提交于 2019-12-04 06:16:29
I want to access a local variable from a method in a business class, in a method which is in an aspect class. For instance class BusinessClass { public void simpleTest() { ... String localString = new String( "test" ); ... } } MyAspect { log() { // I WANT TO ACCESS THE VALUE OF LOCALSTRING HERE } } I want to access localString's value in log method of MyAspect. Please let me know if there is any way to accomplish this using Spring / AspectJ. Also, is there is a way to accomplish without changing simpleTest method signature? Thanks much in advance! As I understand them, aspects are intended to

Spring AOP Pointcut does not trigger

筅森魡賤 提交于 2019-12-04 05:53:15
问题 I am new to Spring and AOP. I am trying this simple thing where I have created a custom annotation which when placed before any method should execute some code. This is the annotation I created // Declares a custom annotation that validates json @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.METHOD) public @interface JsonSchemaAnnotation { } Next I created the Spring Aspect class which holds the logic @Aspect public class UpdateUIMetadataInterceptor { @Pointcut("execution(public *

Why my Aspect is not detected for Jersey controller (using custom annotation)?

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-04 05:41:02
I want to create an Aspect over a Jersey controller to measure how long the services take to be executed. I'm fighting against my pointcut since it isn't detected and my aspect never gets launched. I have tried using lots of pointcuts like: execution(@Monitor * *.*(..)) execution(public * *(..)) change the order of @Aspect and @Component Added a pointcut like this: @Pointcut("execution(@Monitor * *.*(..))") public void monitorRequestTargets(){} @Around("monitorRequestTargets()") Tried using AOP and CGLIB <aop:aspectj-autoproxy proxy-target-class="true"/> Also tried changing the order of

AspectJ load time weaving not working on Spring beans

天大地大妈咪最大 提交于 2019-12-04 04:20:29
I'm working on a project that uses the Java (not xml) flavour of Spring configuration for wiring up dependencies. It also has profiling logic that should be weaved via AspectJ onto the desired methods (via annotations). The setup is working and I can see classes from my desired package being weaved and profiling information being logged out of them. The problem is that weaving does not work for @Bean classes. I've enabled debug in aop.xml via: <weaver options="-XnoInline -Xreweavable -verbose -debug -showWeaveInfo"> And I can see classes in my desired package being weaved, but not the beans in

AspectJ & Maven warning: “Advice defined in … has not been applied?”

≡放荡痞女 提交于 2019-12-04 03:45:10
I'm trying to weave some aspects at compile time into a project that becomes a WAR. The aspects advise classes that are within the same project (though in different packages). I get the warning: Advice not applied My aspect is not being executed. Here's my setup: annotation FooAnnotation.java: package a; @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.METHOD) public @interface FooAnnotation {} aspect FooAdvice.aj: package a; public aspect FooAdvice { private static final Log log = LogFactory.getLog(FooAdvice.class); Object around() : call( @FooAnnotation * *(..)) { log.info(String

How to swallow a exception at AfterThrowing in AspectJ

冷暖自知 提交于 2019-12-04 03:34:06
In AspectJ, I want to swallow a exception. @Aspect public class TestAspect { @Pointcut("execution(public * *Throwable(..))") void throwableMethod() {} @AfterThrowing(pointcut = "throwableMethod()", throwing = "e") public void swallowThrowable(Throwable e) throws Exception { logger.debug(e.toString()); } } public class TestClass { public void testThrowable() { throw new Exception(); } } Above, it didn't swallow exception. The testThrowable()'s caller still received the exception. I want caller not to receive exception. How can do this? Thanks. I think it can't be done in AfterThrowing . You