nvr*_*vrs 3 spring inject autowired
我有一个服务bean(使用@Service注释),它实现了扩展ApplicationEvent抽象类的T类型事件对象的ApplicationListener接口.还有就是这个在Spring文档一个非常简单和明显的例子在这里
但是,当我尝试使用@Autowired将此bean注入其他的时,我得到的是:
org.springframework.beans.factory.NoSuchBeanDefinitionException:没有为依赖项找到类型[...]的匹配bean:预期至少有一个bean可以作为此依赖项的autowire候选者.依赖注释{@ org.springframework.beans.factory.annotation.Autowired(required = true)}
如果我尝试使用类似@Resource的东西,那么我会得到一个类强制转换异常(尝试注入一种类型的资源但获得代理).
如果我尝试使用类似@Resource的东西,那么我会得到一个类强制转换异常(尝试注入一种类型的资源但获得代理).
这听起来像是在尝试按类引用它,而它是作为基于接口的JDK代理连接的.
如果你有这个课程:
@Service
public class FooServiceImpl implements FooService{}
Run Code Online (Sandbox Code Playgroud)
把它当成:
@Autowired
private FooService fooService;
Run Code Online (Sandbox Code Playgroud)
不是:
@Autowired
private FooServiceImpl fooService;
Run Code Online (Sandbox Code Playgroud)
参考:
| 归档时间: |
|
| 查看次数: |
3123 次 |
| 最近记录: |