当前位置:编程学习 > JAVA >>

spring annotion找不到jar里的类导致NoSuchBeanDefinitionException错误

最近在维护一个老项目,结果修改了一个jar包,重新打包后,启动时发生了如下错误:
32417 [main] 13 Aug 2012 10:46:21,318 ERROR org.springframework.web.context.ContextLoader  initWebApplicationContext - Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userService': Autowiring of fields failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.oss.service.UserService com.oss.ws.server.impl.UserServiceImpl.userService; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No unique bean of type [com.oss.service.UserService] is defined: Unsatisfied dependency of type [class com.oss.service.UserService]: expected at least 1 matching bean
... more
Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.oss.service.UserService com.gnet.tang.usermanager.ws.server.impl.UserServiceImpl.UserService; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No unique bean of type[com.oss.service.UserService] is defined: Unsatisfied dependency of type [class com.oss.service.UserService]: expected at least 1 matching bean
        ... 40 more
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No unique bean of type [com.oss.service.UserService] is defined: Unsatisfied dependency of type [class com.oss.service.UserService]: expected at least 1 matching bean
        ... 42 more
并且通过分析,发现userService是通过spring的@service注解的,后在xml里通过context:component-scan来查找这些类并初始化bean。 后经过试验发现,将新的类通过rar的工具放入到易做图ar里就不会出错,说明是打包的过程出错了。
       可以通过打包的时候选中”Add directory entries“选项来解决。如下图:

作者:jkeven
补充:软件开发 , Java ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,