@Configuration
public class CDPlayerConfig {
@Bean
public CompactDisc sgtPeppers(){
return new SgtPeppers();
}
@Bean
public CDPlayer cdPlay(){
return new CDPlayer(sgtPeppers());
}
}
这个是能执行的
把
@Bean
public CompactDisc sgtPeppers(){
return new SgtPeppers();
}
放到另一个配置文件中,然后通过@Import引入
@Configuration
public class CDConfig {
@Bean
public CompactDisc sgtPeppers(){
return new SgtPeppers();
}
}
引入外部的配置文件
@Configuration
@Import(CDConfig.class)
public class CDPlayerConfig {
@Bean
public CDPlayer cdPlay(){
return new CDPlayer(sgtPeppers());
}
}
就找不到这个method
The basic concept is wrong. sgtPeppers() is a method of calling this class. If it is not defined, of course it will cause a compilation error and has nothing to do with spring.
Change it like this:
Incorrect understanding
Can be used with @Bean @Qualifier