Is it possible to set a bean name using annotations in Spring Framework? Is it possible to set a bean name using annotations in Spring Framework? java java

Is it possible to set a bean name using annotations in Spring Framework?


What you are asking is already available in Spring reference

By default, configuration classes use a @Bean method’s name as thename of the resulting bean. This functionality can be overridden,however, with the name attribute.

@Configurationpublic class AppConfig {    @Bean(name = "myFoo")    public Foo foo() {        return new Foo();    }}