Questions tagged [spring-aop]

Spring AOP is the Spring Framework's version of AOP, implemented in pure Java and using the @AspectJ annotations from the AspectJ project. Spring AOP works through dynamic JDK or CGLib Proxies.

Spring AOP is explained in the

Spring 3.0.x Online Reference > 7. Aspect Oriented Programming with Spring

Note that there is an increasing tendency to replace Spring AOP with static AspectJ compilation. This Approach is explained in Section: 7.8 Using AspectJ with Spring applications

AspectJ in Action is an excellent reference for both Spring AOP and AspectJ

The pre-3.0 XML-based Spring AOP approach is explained in Appendix B. Classic Spring AOP Usage

2584 questions
0
votes
1 answer

@Before doesn't allow pointcut reference, why?

I can do @Pointcut("@annotation(com.learning.validation.Validate)") public void validatePointCut() { } @AfterReturning(pointcut = "validatePointCut()") public void validate(JoinPoint joinPoint) { // some code } but i…
0
votes
0 answers

(Spring Legacy) @Value returns null only in "Specific Config" even though PropertyPlaceholderConfigurer added

I'm in the process of migrating XML configuration to Java configuration in a legacy Spring project. To split configurations, I've added *Config.java files. @Configuration @Import({AConfig.class, BConfig.class}) public class RootConfig{ @Bean …
zzangs33
  • 197
  • 1
  • 15
0
votes
0 answers

Define and increment a prometheus custom counter whenever slf4j Logger error() is being called from my class method's execution(E2E) using AOP

I have a requirement where I want to count number of org.slf4j.Logger.error() calls within my method's execution (across multiple class like controller--service--repo etc). I am thinking to use AOP along with prometheus for this. Below is a sample…
0
votes
0 answers

Access MDC in aspect when uploading multipart in spring webflux

Hello Im using spring boot 3 and spring webflux and micrometer package for tracing in app my dependency for tracing using micrometer: implementation 'io.micrometer:micrometer-tracing-bridge-brave' implementation…
amir
  • 23
  • 4
0
votes
0 answers

spring aop invoke another method of controller

I want to mock authentication using spring aop. In our application we have authentication trough bank, backend redirects to bank, and then after user successfully authenticates via bank client we get a callback and user is authenticated in our…
Simas.B
  • 724
  • 1
  • 13
  • 31
0
votes
1 answer

Run @Before advice before @Around advice in Spring Boot AOP

I'm building a Spring Boot v3.1.1 application and I want to use AOP to do certain things, for example, print logs to the console. @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.METHOD) public @interface LogAround {} With this custom…
RRGT19
  • 1,437
  • 3
  • 28
  • 54
0
votes
1 answer

Spring AOP for certain controller class

I have controllers in the same package aa.bb.controller.A aa.bb.controller.B aa.bb.controller.C I want to intercept all the calls to A and B, but not C. Because I don't want to use @Pointcut("within(aa.bb.controller..*), which apply to all three…
Abe
  • 310
  • 3
  • 15
0
votes
0 answers

When are proxy objects created in Spring AOP?

I have been reading about Spring AOP and have a very basic question. When does Spring AOP creates a proxy object? Is it during the application start time when beans are created? OR Is it any time between application start(inclusive) and before…
user762421
  • 503
  • 1
  • 12
  • 24
0
votes
1 answer

Spring AOP custom annotation alternatives

I am working on a library which would allow clients to capture runtime data in their code. I am following the below steps. I am planning to do the following: Create a Annotation in Library. Use Spring AOP and create a Aspect and define a Pointcut…
user762421
  • 503
  • 1
  • 12
  • 24
0
votes
1 answer

Spring AOP running advices in separate threads

I have below Java code which intercepts the method getUserDetails() using Spring AOP and logs its execution time. The method calculateExecutionTime gets executed in the same thread as getUserDetails(). package com.poc.app.data; import…
user762421
  • 503
  • 1
  • 12
  • 24
0
votes
1 answer

Custom Spring Aspect logger cause exception

I wrote custom realisation of system logger based on spring aop, everything was working fine But after time i started getting error like in file, which blows my head, absolutely confusing error java.lang.NullPointerException: Cannot invoke…
0
votes
1 answer

Spring Dependency Injection with AspectJ

Currently I am reading some documentation about Quarkus in which they are constantly attacking a lot about DynamicProxy mechanism of Spring for Dependency Injection. I am quoting "Spring creates an implementation proxy for the interface and any…
posthumecaver
  • 1,584
  • 4
  • 16
  • 29
0
votes
0 answers

How to configure Hibernate Statement Inspector per session at runtime with AOP?

I am looking at the documentation here for StatementInspector. The documentation states the following: A StatementInspector may be either: shared by all sessions created by a given session factory, in which case it must be thread-safe, or a…
TerNovi
  • 390
  • 5
  • 16
0
votes
1 answer

@Transactional method calling a method in the same class

I have a class UserService which has a method saveUser() and saveAmount() as shown below. class UserService { @Transactional public void saveUsers() { saveUser1 to db; saveUser2 to db; saveAmount(); …
0
votes
1 answer

SpringBoot 2.7: Custom Annotation Aspect not working

Below is my custom annotation SkipForTestProfile which I created to skip execution for "it" profile but the SkipForTestProfileAspect code is not execuuted, i appreciate if someone can help me fix the Aspect to execute around the annotation…
OTUser
  • 3,788
  • 19
  • 69
  • 127