Closed sascha-frinken closed 4 months ago
@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 Sorry to rush, but we need to make a decision on whether we can continue to work with micronaut in our GUIs. It would be helpful just to know if and when the problem will be fixed.
@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 AbstractInitializableBeanDefinition
classes which relate to AutoConfigurationPackages.Registrar.class
. This class is package private, which I believe is the cause of the failure
ok so a bug in the Groovy compiler
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 inject-groovy
We also (under groovy) see
WARNING: Spring ImportSelector [org.springframework.boot.autoconfigure.AutoConfigurationImportSelector] found in @Import declaration on element [boot4groovy.Application] was ignored. Ensure that the type is present on the annotation processor classpath. Note that only simple ImportSelector implementations that do no implement Aware interfaces (which cannot run at build time) are supported.
@SpringBootApplication ^
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:
@Import({AutoConfigurationPackages.Registrar.class})
public @interface AutoConfigurationPackage {
The same problem might be with: ImportAutoConfigurationImportSelector
registered by:
@Import({ImportAutoConfigurationImportSelector.class})
public @interface ImportAutoConfiguration
@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 Thank you very much!
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