用@Configuration注解该类,等价 与XML中配置beans;用@Bean标注方法等价于XML中配置bean。
@Configuration
public class SpringConfig {
@Bean
public Piano piano(){
return new Piano();
}
@Bean(name = "counter")
public Counter counter(){
return new Counter(12,"Shake it Off",piano());
}
}