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

spring数据无法为方法创建查询

施选
2023-03-14

错误:

unsatisfiedDependencyException:创建名为“app controller”的bean时出错:通过字段“service”表示的未满足的依赖关系;嵌套异常为org.springframework.beans.factory.unsatisfieddependencyexception:创建名为“jenkins service”的bean时出错:通过字段“repo”表示的不满足的依赖关系;嵌套异常为org.springframework.beans.factory.BeanCreationException:创建名为“jenkins repo”的bean时出错:调用init方法失败;嵌套异常为java.lang.IllegalArgumentException:无法为方法public abstract java.util.list com.example.crud.jenkinsrepo.findByRun_id(java.lang.String)创建查询!找不到类型Jenkins的属性运行!

这是定义表实体的Jenkins类:

package com.example.crud;

import javax.persistence.*;

@Entity
@Table(name="test_case_failure")
public class Jenkins {

    @Id
    @Column(name = "failure_id")
    private int failure_id;

    @Column(name="test_case_name")
    private String test_case_name;
    @Column(name="expected_value")
    private String expected_value;
    @Column(name="error_name")
    private String error_name;
    @Column(name="auto_error_type")
    private String auto_error_type;
    @Column(name="run_id")
    private String run_id;

    public Jenkins() {
    }

    public int getFailure_id() {
        return failure_id;
    }

    public void setFailure_id(int failure_id) {
        this.failure_id = failure_id;
    }

    public String getTest_case_name() {
        return test_case_name;
    }

    public void setTest_case_name(String test_case_name) {
        this.test_case_name = test_case_name;
    }

    public String getExpected_value() {
        return expected_value;
    }

    public void setExpected_value(String expected_value) {
        this.expected_value = expected_value;
    }

    public String getError_name() {
        return error_name;
    }

    public void setError_name(String error_name) {
        this.error_name = error_name;
    }

    public String getAuto_error_type() {
        return auto_error_type;
    }

    public void setAuto_error_type(String auto_error_type) {
        this.auto_error_type = auto_error_type;
    }

    public String getRun_id() {
        return run_id;
    }

    public void setRun_id(String run_id) {
        this.run_id = run_id;
    }

}

控制器类:

package com.example.crud;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

@Controller
public class appController {

    @Autowired
    private jenkinsService service;

    @RequestMapping("/")
    public String viewHomePage(Model model) {
        List<Jenkins> listProducts = service.getbyrun_id();
        model.addAttribute("TestsReports", listProducts);

        return "index";
    }

}

存储库类:

package com.example.crud;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface JenkinsRepo extends JpaRepository<Jenkins, Integer> {
    List<Jenkins> findByrun_id(String run_id);
}

服务类别:

package com.example.crud;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class jenkinsService {

    @Autowired
    private JenkinsRepo repo;

    List<Jenkins> getbyrun_id() {
        return repo.findByrun_id("test");
    }

}

共有1个答案

范振海
2023-03-14

spring-Data在尝试从方法签名注入查询时使用下划线作为嵌套字段的分隔符。因此,如果您执行findbyrun_id,spring将搜索嵌套字段jenkins.run.id。您应该将属性run_id更改为runid,然后将方法重命名为findByrunidfindByrunid

 类似资料:
  • 并将其添加到主存储库: 启动应用程序时,出现以下错误: 原因:org.SpringFramework.Data.Mapping.PropertyReferenceException:未找到类型Friends的属性findFriends!在org.springframework.data.mapping.propertypath.(propertypath.java:77)在org.springfr

  • 我在用户和电话号码之间有一种“一对一”的关系。因此,一个用户可以有多个电话号码。 在前端,我必须只提取登录用户的电话号码,或者如果用户是管理员,我必须显示所有用户的电话号码。我已经设法实现了这一部分,但我遇到的问题如下:在前端,用户还有一个“电话号码”搜索框。因此,如果用户或管理员搜索987(比如前3位数字),则应显示包含“987”且与其个人资料相关联的任何电话号码。如果用户是管理员,我应该显示包

  • Spring cloud openFeign无法创建动态查询参数。它抛出以下异常,因为SpringMvcContract试图查找不存在的RequestParam value属性。 我尝试使用而不是,但不生成查询参数。

  • 我正在尝试基于此示例编写自己的代码。 我使用的是Spring Boot,所有依赖项都来自https://start.spring.io/ 这是我的知识库: 我的控制器的一部分: 我的Spring Boot: 我收到此错误: 我做错了什么?如果有必要,我可以发布更多类似实体的代码 我正在使用IntelliJ IDEA。

  • 我想列一份订单,比如 这是我的密码 我使用的是Java Spring Boot和Spring Data JPA,我遇到了如下错误 你们能帮帮我吗!我想我在《findAllOrderBycreateDateDesc》中错了。谢谢对不起我的英语。这是我第一次发布我的问题。除息的

  • 我想在Eclipse中用for创建10个txt文件,但是为什么我这么做的时候会出错?