Skip to content
This repository has been archived by the owner on Feb 23, 2023. It is now read-only.

Spring AOP is only working for "concrete classes" #956

Closed
goafabric opened this issue Aug 6, 2021 · 4 comments
Closed

Spring AOP is only working for "concrete classes" #956

goafabric opened this issue Aug 6, 2021 · 4 comments
Labels
status: waiting-for-triage An issue we've not yet triaged or decided on

Comments

@goafabric
Copy link

Following the examples from the spring-native project, it is possible to weave aspects.
However this only works for very "concrete" classes.

This works:
@around("execution(public * org.goafabric.calleeservice.logic.CalleeLogic.*(..))")
public Object around(ProceedingJoinPoint joinPoint) throws Throwable {

A wildcard for all classes in logic does not:
@around("execution(public * org.goafabric.calleeservice.logic..*(..)) )")
public Object around(ProceedingJoinPoint joinPoint) throws Throwable {
=> See Wildcard Exception Below

Using an annotation is also not working:
@around("execution(public * *(..)) && within(@org.goafabric.calleeservice.crossfunctional.DurationLog *)")
public Object around(ProceedingJoinPoint joinPoint) throws Throwable {

@target(ElementType.TYPE)
@retention(RetentionPolicy.RUNTIME)
public @interface DurationLog {
}

=> See Annotation Exception

...

At this state it's pretty unusable, because they only choice would be than to list all classes that we want to weave.
Or am I missing something here ?

thx in advance

-- Wildcard Exception ---
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'metaDataSourceAdvisor':
Cannot resolve reference to bean 'methodSecurityMetadataSource' while setting constructor argument; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name
'org.springframework.security.config.annotation.method.configuration.GlobalMethodSecurityConfiguration': Unsatisfied dependency expressed through method 'setObjectPostProcessor' parameter 0;
nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'objectPostProcessor' defined in class path resource [org/springframework/security/config/annotation/configuration/ObjectPostProcessorConfiguration.class]: Initialization of bean failed; nested exception is com.oracle.svm.core.jdk.UnsupportedFeatureError: Proxy class defined by interfaces [interface org.springframework.security.config.annotation.ObjectPostProcessor, interface org.springframework.beans.factory.DisposableBean, interface org.springframework.beans.factory.SmartInitializingSingleton] not found. Generating proxy classes at runtime is not supported. Proxy classes need to be defined at image build time by specifying the list of interfaces that they implement. To define proxy classes use -H:DynamicProxyConfigurationFiles= and -H:DynamicProxyConfigurationResources= options.

-- Annotation Exception --

'org.springframework.security.config.annotation.configuration.ObjectPostProcessorConfiguration':
Initialization of bean failed; nested exception is java.lang.IllegalArgumentException:
warning no match for this type name:
org.***.calleeservice.crossfunctional.DurationLog [Xlint:invalidAbsoluteTypeName]

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Aug 6, 2021
@sdeleuze
Copy link
Contributor

Could you please qualify this one @aclement ?

@sdeleuze sdeleuze changed the title Spring AOP is only working for "conrecte classes" Spring AOP is only working for "concrete classes" Aug 17, 2021
@aclement
Copy link
Contributor

Can you possibly share a small test project?

In the annotation case, my immediate first thought is that the exception that says you need a proxy says you don't need a proxy for lots of things, you just are missing a proxy for these 3 types and I presume those 3 types don't match any of your point cuts.

[
 interface org.springframework.security.config.annotation.ObjectPostProcessor,
 interface org.springframework.beans.factory.DisposableBean,
 interface org.springframework.beans.factory.SmartInitializingSingleton
]

So I would add the hint manually for that and see if it progresses further. That may just be a missing static hint we don't have.

However, that's not to say there isn't an issue:

At this state it's pretty unusable, because they only choice would be than to list all classes that we want to weave.
Or am I missing something here ?

Yes, I imagine if doing load-time weaving (and not compile time weaving) all the types would need listing. What Spring Native has is all the building blocks of infrastructure so things are actually possible. The higher level analysis algorithms aren't all written (e.g. something that evaluates point cuts at build time and auto registers the necessary reflection entries and any proxies) - this is doable but hasn't been done yet (at least it is doable for reasonable uses of execution() and within() that scope to a set of types).

If you do contribute a test project we can maybe use that as a basis to start fleshing it out.

You could use the GraalVM agent to collect configuration so that at least the app will build into a native-image - that would be an interesting measure of whether it will fully behave when the build time analysis is written, or if there is some other problem lurking. Using the agent means you won't have to list all the types, the agent will simply produce it during collection.

@goafabric
Copy link
Author

goafabric commented Aug 18, 2021

Ok thank you for the very complete information.
The Project / Class in Question is here:
https://github.com/goafabric/callee-service/blob/aspect/src/main/java/org/goafabric/calleeservice/crossfunctional/DurationLogAspect.java

You see to other Expressions that are commented out, only the active one works.

I remeber that I also tried to set hints for Objectprocessor etc ... but afterwards, just other classes would come up that need to be annotated .. so i stopped there

As you can see the project is pretty, pretty basic...

The Quarkus people somehow managed to get it working without any hints ... just with the
Annotation Variant (only).

Thx for the support

Andreas

@goafabric
Copy link
Author

Created a new issue for Boot 3.0
spring-projects/spring-framework#29519

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
status: waiting-for-triage An issue we've not yet triaged or decided on
Development

No branches or pull requests

4 participants