我有一个服务 bean(用 @Service 注释),它为扩展 ApplicationEvent 抽象类的 T 类型的事件对象实现 ApplicationListener 接口。Spring docs here中有一个非常简单明了的示例
但是,当我尝试使用 @Autowired 将此 bean 注入其他 bean 时,我得到的是:
org.springframework.beans.factory.NoSuchBeanDefinitionException:没有为依赖项找到类型 [...] 的匹配 bean:预计至少有 1 个 bean 有资格作为此依赖项的自动装配候选者。依赖注解 {@org.springframework.beans.factory.annotation.Autowired(required=true)}
如果我尝试使用 @Resource 之类的东西,那么我会得到一个类转换异常(尝试注入一种类型的资源但得到一个代理)。