紧急求救一个spring注解问题,启动报错Error creating bean with name

fly2749 2011-12-15 03:31:55
我的项目使用了spring注解的方式,在每一层中做了标示,用的是@Component(name="xxx")和@Resource(name="xxx"),
但是当我启动时会报如下错误,具体原因在网上找出,应该是注入的变量必须是接口类型,但是我的已经指定为接口类型,请大家帮看下,谢谢,具体错误如下:


org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'uAction': Injection of resource fields failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'uFacade': Injection of resource fields failed; nested exception is org.springframework.beans.factory.BeanNotOfRequiredTypeException: Bean named 'uService' must be of type [com.xxx.xxx.xxx.xxx.IUService], but was actually of type [$Proxy32]
...全文
11796 9 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
fly2749 2011-12-15
  • 打赏
  • 举报
回复
[Quote=引用 7 楼 xinlan1022 的回复:]

@Qualifier用这个加上你要装配的service看看呢
[/Quote]
@Qualifier这个我试过,不行。
fly2749 2011-12-15
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 heroshen1988 的回复:]

引用 4 楼 majia518 的回复:
引用 3 楼 heroshen1988 的回复:

没有注入成功,好像是声明uService的地方错了,地址没有写全

没明白,哪里没有写全?


抱歉,看错了
之前我也出现这种情况,原因是因为我在action中注入时注入的是实现类,正确的应该是接口注入;
例如:
@Resource
private Impl impl,这样sp……
[/Quote]
我注入的就是接口啊
xinlan1022 2011-12-15
  • 打赏
  • 举报
回复
@Qualifier用这个加上你要装配的service看看呢
heroshen1988 2011-12-15
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 majia518 的回复:]
引用 3 楼 heroshen1988 的回复:

没有注入成功,好像是声明uService的地方错了,地址没有写全

没明白,哪里没有写全?
[/Quote]

抱歉,看错了
之前我也出现这种情况,原因是因为我在action中注入时注入的是实现类,正确的应该是接口注入;
例如:
@Resource
private Impl impl,这样spring注入的是一个代理类[$Proxy6],
得改为:
@Resource
private Interface nterface;
majia518 2011-12-15
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 heroshen1988 的回复:]

没有注入成功,好像是声明uService的地方错了,地址没有写全
[/Quote]
没明白,哪里没有写全?
heroshen1988 2011-12-15
  • 打赏
  • 举报
回复
没有注入成功,好像是声明uService的地方错了,地址没有写全
fly2749 2011-12-15
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 xinlan1022 的回复:]

@Resource
IUService uService;是这样声明 的吗?
[/Quote]
是的 这样会报错,改成了如下方式:
@Resource(name="uService",type=IUService.class)
private IUService uService;
还是报错............
还有一点我要说明,我项目中有两个不同包下同样名称的action,service,.......dao等等
xinlan1022 2011-12-15
  • 打赏
  • 举报
回复
@Resource
IUService uService;是这样声明 的吗?

81,122

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧