@Bean: Difference between revisions
Jump to navigation
Jump to search
(Created page with "=Internal= * Spring Dependency Injection and Inversion of Control Container Concepts") |
|||
(4 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
=External= | |||
* https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/context/annotation/Bean.html | |||
=Internal= | =Internal= | ||
* [[Spring_Dependency_Injection_and_Inversion_of_Control_Container_Concepts# | * [[Spring_Dependency_Injection_and_Inversion_of_Control_Container_Concepts#.40Configuration.2F.40Bean|Spring Dependency Injection and Inversion of Control Container Concepts]] | ||
=Overview= | |||
{{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
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();
}
}