4

Error:

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'appController': Unsatisfied dependency expressed through field 'service'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'jenkinsService': Unsatisfied dependency expressed through field 'repo'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jenkinsRepo': Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Failed to create query for method public abstract java.util.List com.example.crud.JenkinsRepo.findByrun_id(java.lang.String)! No property run found for type Jenkins!

This is the Jenkins class to define table entity:

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;
    }

}

Controller class:

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";
    }

}

Repository class:

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);
}

Service class:

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");
    }

}
4
  • add your repo code and what query are you running ? Commented Apr 16, 2020 at 17:02
  • I have added in the code..named JenkinsRepo and i want to query result based on run_id Commented Apr 16, 2020 at 17:45
  • try List<Jenkins> findByRun_id(String run_id); use capital R Commented Apr 16, 2020 at 17:48
  • Thanks Abinash....the answer posted by robertobatts worked!! Commented Apr 16, 2020 at 17:57

1 Answer 1

16

spring-data uses the underscore as a separator for nested fields when it tries to inject a query from the method signature. So, if you do findByrun_id Spring will search for the nested field Jenkins.run.id. You should change the attribute run_id to runId and then rename your method to findByrunId or findByRunId

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks a lot!!!...it worked. was trying to resolve this for days.
Is there a way to disable this ?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.