java - 没有找到这样的 bean 定义?

标签 java spring portlet

我正在做一个门户项目。当我将 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/

相关文章:

spring - 如何强制 Spring Boot 将正确的 HTTP 状态代码设置为错误响应?

java - Liferay 6.0 基于groupid动态使用Datasource

permissions - 当我将 portlet.properties 文件添加到 portlet 时,为什么会收到 HotDeployException? (Liferay 门户开发)

java - 在 checkstyle 中运行自定义检查时需要帮助

java - 推荐的 JScrollPane 导航小部件

java - 在 Spring 应用程序中使用 Hibernate 自动创建表

java - 创建 Liferay portlet 配置页面

Java 8可选,多个filter和多个map

java - 动态调用实现方法

java - 将参数传递给来自 xml 的不同切入点的相同切面方法