Open mancze opened 1 year ago
Probably this needs extra documentation, but this is not currently a bug. You need to add @ScopedProxy
to @MyScope
, making this change passes the tests:
@Documented
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.PARAMETER, ElementType.TYPE, ElementType.METHOD})
@ScopedProxy
@interface MyScope {
}
Does that mean that custom scopes have to be annotated with @ScopedProxy
for AOP to work on them? That surely would use some docs :).
I have a follow up question to this. We were able to overcome the need of applying @ScopedProxy
by using eagerInitAnnotated(MyScope.class)
instead.
But after debugging the code, I'm not sure if we aren't taking advantage of possibly another issue in Micronaut. It appears, that usage of eagerInitAnnotated(<your annotation>)
automatically puts those beans always into Singleton
scope. It disregards the fact that they might be declared in some other scope. Is that something to be reported in a separate issue, or is that another case of insufficient documentation?
Expected Behavior
AOP annotations (e.g. caching annotations) on beans in custom scope should work normally.
Possibly related: #9208
Actual Behaviour
@Inject
injection points.NoSuchBeanException
is thrown when trying to retrieve AOP-annotated beans dynamically fromBeanContext
.Steps To Reproduce
./gradlew :test --tests "com.example.scope.AopInCustomScopeTest"
Environment Information
No response
Example Application
https://github.com/mancze/micronaut-sandbox/tree/aop-in-custom-scope
Version
3.9.1