The class in jar cannot be found in spring annotion, causing NoSuchBeanDefinitionException error.

Source: Internet
Author: User

Recently, I was maintaining an old project. As a result, I modified a jar package. After the package is repackaged, the following error occurs when the project is started:
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: cocould 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: cocould 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
Through analysis, we found that userService is annotated by @ service in spring, and then searched for these classes in xml and initialized beans through context: component-scan. After the experiment, it is found that the new class is put into the old jar by using the rar tool, which indicates that the packaging process is wrong.
You can solve this problem by selecting the "Add directory entries" option during packaging. For example:

Author: jkeven

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.