Created
June 1, 2019 05:34
-
-
Save bandicoot86/ec423688a405bb9bf5f52766e281d42e to your computer and use it in GitHub Desktop.
ExampleSpring.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.example.demo; | |
import org.springframework.context.annotation.AnnotationConfigApplicationContext; | |
import org.springframework.context.annotation.Bean; | |
import org.springframework.context.annotation.Configuration; | |
@Configuration | |
public class SimpleSpringApplication { | |
public static void main(String[] args) { | |
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(SimpleSpringApplication.class); | |
System.out.println(context.getBean(B1AndB2Holder.class)); | |
} | |
@Bean | |
public B1AndB2Holder holder() { | |
return new B1AndB2Holder(b1(), b2()); | |
} | |
@Bean | |
public Bean1 b1() { | |
return new Bean1(); | |
} | |
@Bean | |
public Bean2 b2() { | |
return new Bean2(); | |
} | |
public class Bean1 { | |
} | |
public class Bean2 { | |
} | |
public class B1AndB2Holder { | |
private final Bean1 b1; | |
private final Bean2 b2; | |
public B1AndB2Holder(Bean1 b1, Bean2 b2) { | |
this.b1 = b1; | |
this.b2 = b2; | |
} | |
@Override | |
public String toString() { | |
return "B1AndB2Holder{" + | |
"b1=" + b1 + | |
", b2=" + b2 + | |
'}'; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment