@ComponentScan如何在Spring 3.2中运行?

时间:2013-10-01 14:58:22

标签: spring-mvc annotations autowired

我认为@ComponentScan能够以这种方式处理多个包:

@ComponentScan(basePackages = { "com.foo.bar.service", "com.foo.bar.repository" })

但是每当我在包数组中添加多个包时,我都会得到一个例外,当我只使用 com.foo.bar时(我想在使用com.foo.bar时) ,com.foo.bar以及所有子包将被扫描。)

如何告诉Spring扫描所有提到的软件包或软件包及其子软件包?

例外:

org.springframework.beans.factory.BeanCreationException: 
Error creating bean with name 'loginLogoutController': 
Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: 
Could not autowire field: private com.foo.bar.service.MyService com.foo.bar.controller.LoginLogoutController.myService; 
nested exception is org.springframework.beans.factory.BeanCreationException: 
Error creating bean with name 'repositoryMyService': 
Injection of autowired dependencies failed; 
nested exception is org.springframework.beans.factory.BeanCreationException: 
Could not autowire field: private com.foo.bar.repository.MyRepository com.foo.bar.service.RepositoryMyService.myRepository; 
nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: 
No qualifying bean of type [com.foo.bar.repository.MyRepository] found for dependency: 
expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: 
{@org.springframework.beans.factory.annotation.Autowired(required=true)}

存储库类只是一个扩展JpaRepository的接口。 MyService是常规界面,RepositoryMyService实现MyService,并使用@Service进行注释。 LoginLogoutController注明了@Controller

0 个答案:

没有答案