Skip to content

@Named annotation implies @Bean (Prototype) #11667

Closed
micronaut-projects/micronaut-data
#3362
@musketyr

Description

@musketyr

Expected Behavior

When a class is annotated only with @Named annotation and asked for injection then the bean locator throws NoSuchBeanException because of missing scope annotation such as @Singleton

Actual Behaviour

@Named annotation works as a synonym for @Bean and implies prototype scope. Every time the bean locator is asked for the bean, the new one is created.

Steps To Reproduce

  1. create a bean with only @Named annotation such as @Named("foo") public class NamedBean { }
  2. create injection point or ask bean locator for the bean beanLocator.getBean(NamedBean.class)
  3. new instance of the bean is created every time you ask for the bean

Environment Information

No response

Example Application

https://github.com/musketyr/named-annotation-bean-issue for reproducer

Version

4.7.6

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions