@Bean

From NovaOrdis Knowledge Base
Jump to navigation Jump to search

External

Internal

Overview

@Bean in Spring Dependency Injection and Inversion of Control Container Concepts

Register a Bean under a Specific Name

The following registers a MyComponent singleton under the name "blue":

@Configuration
public class ... {

    @Bean("blue")
    public MyComponent getMyComponent() {
      return new MyComponent();
    }
}