Skip to content
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

Issue when enabling eager initialization #627

Open
lengors opened this issue Sep 18, 2024 · 0 comments
Open

Issue when enabling eager initialization #627

lengors opened this issue Sep 18, 2024 · 0 comments
Labels
type: bug Something isn't working

Comments

@lengors
Copy link

lengors commented Sep 18, 2024

Expected Behavior

I expected that when enabling eager initialization (of singletons), the application would continue to work as before.

Actual Behaviour

I get an exception when the application is booting with eager initialization (of singletons) is enabled. The exception is the following:

15:19:48.141 [main] ERROR io.micronaut.runtime.Micronaut - Error starting Micronaut server: Bean definition [io.micronaut.spring.boot.ApplicationRunnerListener] could not be loaded: Failed to inject value for parameter [commandLine] of class: io.micronaut.spring.boot.ApplicationRunnerListener

Message: No bean of type [io.micronaut.core.cli.CommandLine] exists.
Path Taken: new ApplicationRunnerListener(CommandLine commandLine,List<CommandLineRunner E> commandLineRunnerList,List<ApplicationRunner E> applicationRunnerList) --> new ApplicationRunnerListener([CommandLine commandLine],List<CommandLineRunner E> commandLineRunnerList,List<ApplicationRunner E> applicationRunnerList)
io.micronaut.context.exceptions.BeanInstantiationException: Bean definition [io.micronaut.spring.boot.ApplicationRunnerListener] could not be loaded: Failed to inject value for parameter [commandLine] of class: io.micronaut.spring.boot.ApplicationRunnerListener

Message: No bean of type [io.micronaut.core.cli.CommandLine] exists.
Path Taken: new ApplicationRunnerListener(CommandLine commandLine,List<CommandLineRunner E> commandLineRunnerList,List<ApplicationRunner E> applicationRunnerList) --> new ApplicationRunnerListener([CommandLine commandLine],List<CommandLineRunner E> commandLineRunnerList,List<ApplicationRunner E> applicationRunnerList)
        at io.micronaut.context.DefaultBeanContext.initializeContext(DefaultBeanContext.java:1996)
        at io.micronaut.context.DefaultApplicationContext.initializeContext(DefaultApplicationContext.java:307)
        at io.micronaut.context.DefaultBeanContext.configureAndStartContext(DefaultBeanContext.java:3314)
        at io.micronaut.context.DefaultBeanContext.start(DefaultBeanContext.java:345)
        at io.micronaut.context.DefaultApplicationContext.start(DefaultApplicationContext.java:215)
        at io.micronaut.runtime.Micronaut.start(Micronaut.java:75)
        at io.github.lengors.Application.main(Application.java:15)
Caused by: io.micronaut.context.exceptions.DependencyInjectionException: Failed to inject value for parameter [commandLine] of class: io.micronaut.spring.boot.ApplicationRunnerListener
Message: No bean of type [io.micronaut.core.cli.CommandLine] exists.
Path Taken: new ApplicationRunnerListener(CommandLine commandLine,List<CommandLineRunner E> commandLineRunnerList,List<ApplicationRunner E> applicationRunnerList) --> new ApplicationRunnerListener([CommandLine commandLine],List<CommandLineRunner E> commandLineRunnerList,List<ApplicationRunner E> applicationRunnerList)
        at io.micronaut.context.AbstractInitializableBeanDefinition.resolveBean(AbstractInitializableBeanDefinition.java:2204)
        at io.micronaut.context.AbstractInitializableBeanDefinition.getBeanForConstructorArgument(AbstractInitializableBeanDefinition.java:1350)
        at io.micronaut.spring.boot.$ApplicationRunnerListener$Definition.instantiate(Unknown Source)
        at io.micronaut.context.DefaultBeanContext.resolveByBeanFactory(DefaultBeanContext.java:2330)
        at io.micronaut.context.DefaultBeanContext.doCreateBean(DefaultBeanContext.java:2300)
        at io.micronaut.context.DefaultBeanContext.doCreateBean(DefaultBeanContext.java:2312)
        at io.micronaut.context.DefaultBeanContext.createRegistration(DefaultBeanContext.java:3123)
        at io.micronaut.context.SingletonScope.getOrCreate(SingletonScope.java:80)
        at io.micronaut.context.DefaultBeanContext.findOrCreateSingletonBeanRegistration(DefaultBeanContext.java:3025)
        at io.micronaut.context.DefaultBeanContext.initializeEagerBean(DefaultBeanContext.java:2698)
        at io.micronaut.context.DefaultBeanContext.initializeContext(DefaultBeanContext.java:1990)
        ... 6 common frames omitted
Caused by: io.micronaut.context.exceptions.NoSuchBeanException: No bean of type [io.micronaut.core.cli.CommandLine] exists.
        at io.micronaut.context.DefaultBeanContext.newNoSuchBeanException(DefaultBeanContext.java:2794)
        at io.micronaut.context.DefaultApplicationContext.newNoSuchBeanException(DefaultApplicationContext.java:322)
        at io.micronaut.context.DefaultBeanContext.resolveBeanRegistration(DefaultBeanContext.java:2757)
        at io.micronaut.context.DefaultBeanContext.getBean(DefaultBeanContext.java:1745)
        at io.micronaut.context.AbstractBeanResolutionContext.getBean(AbstractBeanResolutionContext.java:89)
        at io.micronaut.context.AbstractInitializableBeanDefinition.resolveBean(AbstractInitializableBeanDefinition.java:2188)
        ... 16 common frames omitted

Steps To Reproduce

Simply clone the linked example and run:

./mvnw clean mn:run

Alternatively, go to micronaut launch, select the spring and spring-boot features.
Then enable eagear initialization of singletons as follows:

@SpringBootApplication
public class Application {
    public static void main(String[] args) {
        Micronaut
            .build(args)
            .classes(Application.class)
            .eagerInitSingletons(true)
            .start();
    }
}

Finally, run the same command as above.

Environment Information

  • Operating System: Windows 11
  • JDK: 21

Example Application

https://github.com/lengors/micronaut-spring-bug-demo

Version

4.6.2

@graemerocher graemerocher added the type: bug Something isn't working label Sep 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants