Java 创建名为';客户控制器';:通过字段'表示未满足的依赖关系;客户服务;;

Java 创建名为';客户控制器';:通过字段'表示未满足的依赖关系;客户服务;;,java,spring,spring-boot,Java,Spring,Spring Boot,我正在尝试启动Spring Boot应用程序,但下面的错误返回给我: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'clienteController': Unsatisfied dependency expressed through field 'clienteService'; nested exception is org.springfra

我正在尝试启动Spring Boot应用程序,但下面的错误返回给我:

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'clienteController': Unsatisfied dependency expressed through field 'clienteService'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'clienteService' defined in file [C:\Users\RenanFreitasDevenz\Documents\api-simulacao\target\classes\com\simulacao\api\services\ClienteService.class]: Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'clienteRepository' defined in com.simulacao.api.repository.ClienteRepository defined in @EnableMongoRepositories declared on MongoRepositoriesRegistrar.EnableMongoRepositoriesConfiguration: Invocation of init method failed; nested exception is org.springframework.data.mapping.PropertyReferenceException: No property buscarClientePorId found for type Cliente!
类别ClientRepository:

package com.simulacao.api.repository;

import com.simulacao.api.documents.Cliente;
import org.springframework.data.mongodb.repository.MongoRepository;
import org.springframework.stereotype.Repository;

import java.util.Optional;

@Repository
public interface ClienteRepository extends MongoRepository<Cliente, String> {

    Cliente buscarClientePorId(String id);
    Cliente buscarClientePorNome(String nome);
    Optional<Cliente> buscarClientePorCpf(String cpf);
}
我试图做但没有解决的问题: 1-用@ComponentScan(“com.simulaco.api”)注释主类

2-注意带有@service的服务类别

如果您需要我发布更多的代码片段,请告诉我


可以做什么?

正如我从您的代码中看到的,在您的存储库中,您有方法
Cliente-buscarclienterproid(String-id)和类似的方法

您使用的是查询方法,它必须具有类似于
findbyFollowdByPropertyOfyOurEntity
的内容

根据Spring数据存储库文档

SpringDataJPA执行属性检查并遍历嵌套属性

根据这个改变你的方法,它应该会起作用

例如,将存储库中的方法更改为

@Repository
public interface ClienteRepository extends MongoRepository<Cliente, 
String> {
    Cliente findById(String id);
}
@存储库
公共接口ClientRepository扩展了MongoRepository{
客户findById(字符串id);
}
我解决了我的问题

我必须使存储库的查询适应:

findByParametro ...
例:


你的问题有很多代码。请你把范围缩小到具体的问题上,清楚地说明你在哪里挣扎?另外,请在发布时格式化您的代码,那样的话,您会吸引更多的读者。根据我报告的异常,我在指出问题的地方发布了代码流。这不是异常
的一部分吗?找不到类型Cliente的属性buscarclientporid对你有帮助吗?它没有解决问题。它是什么?你是怎么解决的?您是否将该字段作为相应的属性映射?我进行了调整,但问题仍然存在<代码>可选的findById(字符串id)相同的错误?由于该属性不存在,因此出现错误。
package com.simulacao.api.documents;

import lombok.*;
import org.hibernate.validator.constraints.br.CPF;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.index.Indexed;
import org.springframework.data.mongodb.core.mapping.Document;
import org.springframework.stereotype.Component;

import javax.validation.constraints.NotEmpty;

@Document
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
@Component
public class Cliente {

    @Id
    private String id;

    @NotEmpty(message = "Nome não pode ser vazio")
    private String nome;

    @Indexed(unique=true)
    @CPF
    private String cpf;

    private Conta conta;

    private boolean ativo;
}
@Repository
public interface ClienteRepository extends MongoRepository<Cliente, 
String> {
    Cliente findById(String id);
}
findByParametro ...
findBy "Property name"