-
Notifications
You must be signed in to change notification settings - Fork 46
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unable to build SpringContext with MicronautApplicationContext as parent #521
Comments
@graemerocher @dstepanov I confirm that there is indeed a bug and now it is not possible to launch the application with spring annotations In general, I think we need to pay more attention to this library and refine it to maximum spring support. I think this will help to popularize micronaut even more. if he can work with the spring code. |
@altro3 I hope you mean Micronaut not Microsoft ;) |
@sascha-frinken yeah, thanks. This is a dumb online translator. He doesn't understand what micronaut is :-). Usually, he translates it as minecraft, but it seems like today is a special day. |
@altro3 @graemerocher |
@sascha-frinken I am going to check this on Monday. |
It seems to work when using Java 🤔 https://github.com/grails-core-issues-forks/micronaut-spring-521 |
It looks like under groovy we are generating |
ok so a bug in the Groovy compiler |
Do you mean the compiler itself, or something we are doing? |
So adding diff --git a/spring-annotation/src/main/java/io/micronaut/spring/annotation/beans/ImportAnnotationVisitor.java b/spring-annotation/src/main/java/io/micronaut/spring/annotation/beans/ImportAnnotationVisitor.java
index de4b9c8f..79b83865 100644
--- a/spring-annotation/src/main/java/io/micronaut/spring/annotation/beans/ImportAnnotationVisitor.java
+++ b/spring-annotation/src/main/java/io/micronaut/spring/annotation/beans/ImportAnnotationVisitor.java
@@ -80,7 +80,9 @@ public final class ImportAnnotationVisitor implements TypeElementVisitor<Object,
for (AnnotationClassValue<?> a : acv) {
String className = a.getName();
context.getClassElement(className).ifPresent(typeToImport -> {
- handleImport(element, context, typeToImport);
+ if (typeToImport.isPublic()) {
+ handleImport(element, context, typeToImport);
+ }
});
}
} Makes this work, but I suspect it isn't the fix, and we may need a fix in core somewhere in We also (under groovy) see
But I am not currently sure if this is part of the same issue... |
The only solution is to avoid loading this class or copy and create an alternative of that class registered by:
The same problem might be with:
|
The ImportAnnotationVisitor would walk the spring hierarchy and cause package-private classes to have definitions created for them. This would then fail at runtime, as Micronaut could not access these defined beans. This fix only visits public classes to prevent this problem. Closes #521
@sascha-frinken We've just released v5.4.1 of micronaut spring which we believe fixes this issue (by not creating bean definitions for spring's private configuration classes) |
@timyates The test project is working now. As soon as we get around to working on our Micronaut 4 migration, I'll let you know if we have any problems. |
Expected Behavior
Run an application with SpringContext and MicronautApplicationContext as parent.
Actual Behaviour
Application won't start.
Same was working with micronaut 3.
Error
Steps To Reproduce
Environment Information
OS: Linux
JDK: 17 & 21
Example Application
https://github.com/safri-net/mn4-spring-issue
Version
4.2.3
The text was updated successfully, but these errors were encountered: