当前位置: 首页 > 知识库问答 >
问题:

如何修复:通过方法“returnReasonRepository”参数0表示的未满足的依赖关系;

束志业
2023-03-14

我正在尝试运行Spring boot应用程序,但我收到以下错误:

应用程序运行失败

组织。springframework。豆。工厂UnsatifiedDependencyException:创建名为“returnReasonRepository”的bean时出错,该bean在类路径资源[muscat/configuration/RepositoryConfiguration.class]中定义:通过方法“returnReasonRepository”参数0表示未满足的依赖关系;嵌套异常为org。springframework。豆。工厂BeanCreationException:创建名为“springReturnReasonRepository”的bean时出错,该名称在muscat中定义。存储库。在ServiceApplication上声明的@EnableJpaRepositories中定义的SpringReturnReasonRepository:init方法调用失败;嵌套异常为org。springframework。数据存储库。查询QueryCreationException:无法为公共抽象java创建查询。util。可选择的马斯喀特。存储库。SpringReturnReasonRepository。findByCode(java.lang.String)!原因:无法为方法公共抽象java创建查询。util。可选择的马斯喀特。存储库。SpringReturnReasonRepository。findByCode(java.lang.String)!找不到类型ReturnReason!的属性代码!;嵌套的异常是java。lang.IllegalArgumentException:无法为方法公共抽象java创建查询。util。可选择的马斯喀特。存储库。SpringReturnReasonRepository。findByCode(java.lang.String)!找不到类型ReturnReason的属性代码!

这是实体:

import lombok.Data;
import lombok.EqualsAndHashCode;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;

import static javax.persistence.GenerationType.IDENTITY;

    @Entity
    @Data
    @EqualsAndHashCode(of = "id", callSuper = false)
    public class ReturnReason {
        @Id
        @GeneratedValue(strategy = IDENTITY)
        private Long id;
    
        @Column
        private String reasonCode;
    
        @Column
        private String reasonDescription;
    
    
        @Column
        private String reasonType;
    }


and this is the 

        public interface ReturnReasonRepository extends MessageRepository<ReturnReason> {
            Optional<ReturnReason> findByCode(String reasonCode);
        }
        
        
        public class ReturnReasonRepositoryImpl implements ReturnReasonRepository {
            private final SpringReturnReasonRepository springReturnReasonRepository;
        
            public ReturnReasonRepositoryImpl(SpringReturnReasonRepository springReturnReasonRepository) {
                this.springReturnReasonRepository = springReturnReasonRepository;
            }
        
        
            @Override
            public Optional<ReturnReason> findByCode(String reasonCode) {
                return springReturnReasonRepository.findByCode(reasonCode);
            }
        
            @Override
            public ReturnReason save(ReturnReason returnReason) {
                return springReturnReasonRepository.save(returnReason);
            }
    
    
        public interface SpringReturnReasonRepository extends CrudRepository<ReturnReason, Long>, JpaSpecificationExecutor<ReturnReason> {
            Optional<ReturnReason> findByCode(String reasonCode);
        }
    
    
    @Configuration
    public class RepositoryConfiguration {
    
    
        @Bean
        public BankInformationRepository bankInformationRepository(SpringBankInformationRepository springBankInformationRepository) {
            return new BankInformationRepositoryImpl(springBankInformationRepository);
        }
    
        @Bean
        public ReturnReasonRepository returnReasonRepository(SpringReturnReasonRepository springReturnReasonRepository) {
            return new ReturnReasonRepositoryImpl(springReturnReasonRepository);
        }
    }

我的错误是什么?我该如何解决?

共有1个答案

别开诚
2023-03-14

马斯喀特。存储库。SpringReturnReasonRepository。findByCode(java.lang.String)!找不到类型ReturnReason的属性代码!

这是你的错误。在SpringReturnReasonRepository中,您有findByCode,但在您的ReturnReasonRepository实体中没有名为code的属性。如果将此方法重命名为findByReasonCode,它将起作用。

如果您想了解更多关于JPA存储库方法命名约定的信息,可以参考此链接。

 类似资料: