You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
micronaut-spring-boot:5.4.0 fails with io.micronaut.context.exceptions.NoSuchBeanException: No bean of type [io.micronaut.context.event.ApplicationEventPublisher<io.micronaut.context.event.StartupEvent>] when running a jar file
#516
Open
donbeave opened this issue
Jan 10, 2024
· 5 comments
gradle bootRun works well, but building the application as jar file and running it leads to an startup error:
Exception in thread "main" java.lang.reflect.InvocationTargetException
at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:119)
at java.base/java.lang.reflect.Method.invoke(Method.java:578)
at org.springframework.boot.loader.launch.Launcher.launch(Launcher.java:91)
at org.springframework.boot.loader.launch.Launcher.launch(Launcher.java:53)
at org.springframework.boot.loader.launch.JarLauncher.main(JarLauncher.java:58)
Caused by: io.micronaut.context.exceptions.NoSuchBeanException: No bean of type [io.micronaut.context.event.ApplicationEventPublisher<io.micronaut.context.event.StartupEvent>] exists. Make sure the bean is not disabled by bean requirements (enable trace logging for 'io.micronaut.context.condition' to check) and if the bean is enabled then ensure the class is declared a bean and annotation processing is enabled (for Java and Kotlin the 'micronaut-inject-java' dependency should be configured as an annotation processor).
at io.micronaut.context.DefaultBeanContext.newNoSuchBeanException(DefaultBeanContext.java:2773)
at io.micronaut.context.DefaultApplicationContext.newNoSuchBeanException(DefaultApplicationContext.java:304)
at io.micronaut.context.DefaultBeanContext.resolveBeanRegistration(DefaultBeanContext.java:2735)
at io.micronaut.context.DefaultBeanContext.getBean(DefaultBeanContext.java:1729)
at io.micronaut.context.DefaultBeanContext.getBean(DefaultBeanContext.java:856)
at io.micronaut.context.BeanLocator.getBean(BeanLocator.java:96)
at io.micronaut.context.DefaultBeanContext.publishEvent(DefaultBeanContext.java:1815)
at io.micronaut.context.DefaultBeanContext.start(DefaultBeanContext.java:376)
at io.micronaut.context.DefaultApplicationContext.start(DefaultApplicationContext.java:199)
at io.micronaut.spring.context.MicronautApplicationContext.start(MicronautApplicationContext.java:458)
at com.example.demo.DemoApplication.main(DemoApplication.java:14)
at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:104)
... 4 more
You might want to check if it did create a shadow jar and if meta-inf services are merged correctly
There is only one file in services:
java.nio.file.spi.FileSystemProvider
There is no shadow jar, as it normal Spring Boot application created with Spring Initializer (https://start.spring.io) with micronaut-spring-boot dependency. It's not using Micronaut Gradle plugin and Gradle Shadow plugin. It's using Micronaut as parent context for Spring Boot application.
@dstepanov I found a related issue in Micronaut Gradle plugin: micronaut-projects/micronaut-gradle-plugin#406, the only difference is that in my case I'm using Micronaut as a parent context without Gradle shadow and Micronaut Gradle plugins, only Spring gradle plugin with micronaut-spring-boot dependency. It worked fine for Micronaut 3, but not for Micronaut 4. Has something changed in 4th version and need to add some extra config?
The upstream change in Spring Boot 3.2 is documented in the release notes.
The previous URL format of
jar:file:/dir/myjar.jar:BOOT-INF/lib/nested.jar!/com/example/MyClass.class
has been replaced with
jar:nested:/dir/myjar.jar/!BOOT-INF/lib/nested.jar!/com/example/MyClass.class.
That causes the FileSystemProvider for "file:" to be used instead of Spring's NestedFileSystemProvider, and that former one won't be able to load /nested:.../.
This is then causing the ServiceScanner to be unable to find any META-INF/micronaut/io.micronaut.inject.BeanDefinitionReference files listing out bean definitions, causing those NoSuchBeanException.
Expected Behavior
No response
Actual Behaviour
gradle bootRun
works well, but building the application as jar file and running it leads to an startup error:Steps To Reproduce
micronaut-spring-no-bean-of-type-applicationeventpublisher-exists
repositoryEnvironment Information
JDK Version:
Example Application
https://github.com/donbeave/micronaut-spring-no-bean-of-type-applicationeventpublisher-exists
Version
4.2.3
The text was updated successfully, but these errors were encountered: