Skip to content

Instantly share code, notes, and snippets.

@bandicoot86
Created June 1, 2019 05:34
Show Gist options
  • Save bandicoot86/ec423688a405bb9bf5f52766e281d42e to your computer and use it in GitHub Desktop.
Save bandicoot86/ec423688a405bb9bf5f52766e281d42e to your computer and use it in GitHub Desktop.
ExampleSpring.java
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