我正在开发一个门户项目。当我将portlet部署到WebSphere时,我得到了NoSuchBeanDefintionException
,我还检查了component-scan
中的包,并且还搜索了它,但我没有找到任何解决方案。每个portlet的context.xml中的所有必需包。
请参阅下面的日志
Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.myhealthone.common.model.Account com.hca.cpp.coreservice.UserServiceImpl.account; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.myhea.common.model.Account] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@ringframework.beans.factory.annotation.Autowired(required=true)}
> at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcesva:514)
> at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:87)
> at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor285)
... 147 more
> Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.myhealthone.common.model.Account] found for depy: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotatiowired(required=true)}
我将所有必需的软件包添加到组件扫描。
答案 0 :(得分:1)
Spring 2.5引入了进一步的构造型注释:@Component, @Service和@Controller。 @Component用作通用构造型 对于任何Spring管理的组件;而@Repository,@ Service和 @Controller作为@Component的特化,更具体 用例(例如,在持久性,服务和表示层中, 分别)。这意味着您可以为组件添加注释 使用@Component的类,但通过使用@Repository注释它们, 相反,@ Service或@Controller更适合你的类 适合通过工具处理或与方面相关联。对于 例如,这些刻板印象注释成为理想的目标 切入点。当然,也可能是@Repository,@ Service, 和@Controller在将来的版本中可能带有额外的语义 Spring框架。因此,如果您在使用之间做出决定 服务层的@Component或@Service,@ Service显然是 更好的选择。同样,如上所述,@ Repository已经存在 支持作为自动异常翻译的标记 持久层。
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd">
<context:component-scan base-package="org.example"/>
</beans>
@Service
public class SimpleMovieLister {
private MovieFinder movieFinder;
@Autowired
public SimpleMovieLister(MovieFinder movieFinder) {
this.movieFinder = movieFinder;
}
}
@Repository
public class JpaMovieFinder implements MovieFinder {
// implementation elided for clarity
}