@Bean: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
 
Line 10: Line 10:


{{Internal|Spring_Dependency_Injection_and_Inversion_of_Control_Container_Concepts#.40Configuration.2F.40Bean|@Bean in Spring Dependency Injection and Inversion of Control Container Concepts}}
{{Internal|Spring_Dependency_Injection_and_Inversion_of_Control_Container_Concepts#.40Configuration.2F.40Bean|@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":
<syntaxhighlight lang='java'>
@Configuration
public class ... {
    @Bean("blue")
    public MyComponent getMyComponent() {
      return new MyComponent();
    }
}
</syntaxhighlight>

Latest revision as of 01:35, 6 December 2018

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();
    }
}