Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/311.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Spring数据无法为方法创建查询_Java_Spring_Hibernate_Spring Boot_Spring Mvc - Fatal编程技术网

Java Spring数据无法为方法创建查询

Java Spring数据无法为方法创建查询,java,spring,hibernate,spring-boot,spring-mvc,Java,Spring,Hibernate,Spring Boot,Spring Mvc,错误: org.springframework.beans.factory.UnsatifiedPendencyException:创建名为“appController”的bean时出错:通过字段“service”表示的未满足的依赖关系;嵌套异常为org.springframework.beans.factory.unsatifiedpendencyException:创建名为“jenkinservice”的bean时出错:通过字段“repo”表示未满足的依赖关系;嵌套异常为org.spring

错误:

org.springframework.beans.factory.UnsatifiedPendencyException:创建名为“appController”的bean时出错:通过字段“service”表示的未满足的依赖关系;嵌套异常为org.springframework.beans.factory.unsatifiedpendencyException:创建名为“jenkinservice”的bean时出错:通过字段“repo”表示未满足的依赖关系;嵌套异常为org.springframework.beans.factory.BeanCreationException:创建名为“jenkinsRepo”的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;
导入org.springframework.beans.factory.annotation.Autowired;
导入org.springframework.stereotype.Controller;
导入org.springframework.ui.Model;
导入org.springframework.web.bind.annotation.RequestMapping;
导入java.util.List;
@控制器
公共类appController{
@自动连线
私人詹金斯服务;
@请求映射(“/”)
公共字符串视图主页(模型){
List listProducts=service.getbyrun_id();
model.addAttribute(“TestsReports”,listProducts);
返回“索引”;
}
}
存储库类:

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;
导入org.springframework.data.jpa.repository.JpaRepository;
导入org.springframework.stereotype.Repository;
导入java.util.List;
@存储库
公共接口JenkinsRepo扩展了JpaRepository{
列出findByrun_id(字符串运行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");
    }

}
package com.example.crud;
导入org.springframework.beans.factory.annotation.Autowired;
导入org.springframework.stereotype.Service;
导入java.util.List;
@服务
公共类服务{
@自动连线
私人JenkinsRepo回购;
列表getbyrun_id(){
返回回购findByrun_id(“测试”);
}
}

spring data在尝试从方法签名中插入查询时,使用下划线作为嵌套字段的分隔符。因此,如果执行
findByrun\u id
Spring将搜索嵌套字段Jenkins.run.id。您应该将属性
run\u id
更改为
runId
,然后将您的方法重命名为
findByrunId
findByrunId

添加您的回购代码和您正在运行的查询?我在代码中添加了名为JenkinsRepo的..我想基于run\u idtry
列出findByRun\u id(字符串run\u id)查询结果使用大写字母
R
谢谢阿比纳什……罗伯特巴特斯给出的答案奏效了!!谢谢!!!。。。成功了。几天来一直试图解决此问题。是否有方法禁用此功能?