@Bean: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
No edit summary
 
(One intermediate revision by the same user not shown)
Line 9: Line 9:
=Overview=
=Overview=


{{Internal|Spring_Dependency_Injection_and_Inversion_of_Control_Container_Concepts#.40Configuration.2F.40Bean|Spring Dependency Injection and Inversion of Control Container Concepts @Bean}}
{{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();
    }
}