Skip to content

DefaultMicronautServlet does not work with eagerInitSingletons #895

@greg-esper

Description

@greg-esper

Expected Behavior

When using eagerInitSingletons(true), the default Micronaut servlet URL mappings should be set to the value of micronaut.servlet.mapping.

Actual Behaviour

The default Micronaut servlet URL mappings are left empty, resulting in all requests 404ing.

MicronautServletInitializer.resolveName(BeanIdentifier identifier, BeanDefinition<?> definition) should be returning "micronaut", which is the @Named value of DefaultMicronautServlet, instead it returns defaultMicronautServlet.

I tested versions 4.5.0-4.12.0 of micronaut-servlet and all are affected.

Steps To Reproduce

  1. Create a project using jetty-server w/ Micronaut Platform version 4.7.6
  2. Add any controller method, e.g. @Get("/ping")
  3. Configure the application to use eagerInitSingletons(true)
  4. Attempt to load the /ping endpoint, observe a 404

I did find a workaround. By injecting @Named("micronaut") DefaultMicronautServlet servlet into a controller, the name resolves correctly in MicronautServletInitializer.resolveName.

Environment Information

Linux
Java 17

Example Application

https://github.com/greg-esper/micronaut-servlet-eager-init/

Version

Micronaut Platform 4.7.6

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions