CompactDisc有多个实现类,我想要注入其中的一个
@Component
public class SgtPeppers implements CompactDisc {
private String title = "Sgt. Pepper's Lonely Hearts Club Band";
private String artist = "The Beatles";
public void play() {
System.out.println("Playing " + title + " by " + artist);
}
}
用默认的bean可以
但是我把bean id改成其他,比如
@Component("segment")
public class SgtPeppers implements CompactDisc {
...
}
怎么就找不到了?
3月10号更新,今天又可以了,真是奇怪,还是没找到出现问题的关键
3月17号:感觉是IDE的问题
You definitely can’t find it. You use @Component to automatically inject, and then the name of the injection is sgtPeppers.
@Resource is based on the name. How can you get it right if your name is wrong?
In addition, the name of the automatic injection is The name injected is based on the class name and the first letter is lowercase
You need to specify @Component("segment")