我正在做一个门户项目。当我将 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)}
我将所有必需的包添加到组件扫描。
最佳答案
来自 this link
Spring 2.5 introduces further stereotype annotations: @Component, @Service and @Controller. @Component serves as a generic stereotype for any Spring-managed component; whereas, @Repository, @Service, and @Controller serve as specializations of @Component for more specific use cases (e.g., in the persistence, service, and presentation layers, respectively). What this means is that you can annotate your component classes with @Component, but by annotating them with @Repository, @Service, or @Controller instead, your classes are more properly suited for processing by tools or associating with aspects. For example, these stereotype annotations make ideal targets for pointcuts. Of course, it is also possible that @Repository, @Service, and @Controller may carry additional semantics in future releases of the Spring Framework. Thus, if you are making a decision between using @Component or @Service for your service layer, @Service is clearly the better choice. Similarly, as stated above, @Repository is already supported as a marker for automatic exception translation in your persistence layer.
<?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
}
关于java - 没有找到这样的 bean 定义?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25899153/