Skip to content

Instantly share code, notes, and snippets.

@jnizet
Created May 11, 2014 06:43
Show Gist options
  • Save jnizet/c7c393072d3af65a9e02 to your computer and use it in GitHub Desktop.
Save jnizet/c7c393072d3af65a9e02 to your computer and use it in GitHub Desktop.
Setter injection
public class Bar {
}
public class Foo {
@Autowired
public void setBar(Bar bar) {
System.out.println("setBar() was called");
}
}
@Configuration
public class AppConfig {
@Bean
public Foo foo() {
return new Foo();
}
@Bean
public Bar bar() {
return new Bar();
}
}
public class Main {
public static void main(String[] args) {
new AnnotationConfigApplicationContext(AppConfig.class).getBean(Foo.class);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment