在类上加@Component,相当于将这个类注册成为了一个bean,交由Spring容器管理。【注意需要在xml中配置这个类所在的包可以被扫描到,否则无法被spring自动管理】。
@Component(“xxx”),相当于是给这个bean加了一个id名称。后面可以通过这个id(xxx)来自动注入。
如果将@Component(“xxx”)改为@Component(“yyy”)后,发现提示
No qualifying bean of type [。。。。] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true), @org.springframework.beans.factory.annotation.Qualifier(value=americanMusic)}
这种错误的话,各位,那你需要将你的服务重新发布一遍。即将Server,先clean,再publish。因为class文件在你仅仅start服务的时候不会被重新发布的。