Error injecting dependency in SpringBoot

0

I'm having the following error someone could help:

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'addAlunoEBController': Unsatisfied dependency expressed through field 'addAlunoService'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'addAlunoEBServiceImpl': Unsatisfied dependency expressed through field 'aebr'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'addAlunoEBRepository': Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: public abstract java.lang.Iterable com.borges.igreja.repository.AddAlunoEBRepository.findByAluno (com.borges.igreja.model.EspañaBiblica)! No property found for type AddAlunoEB! Did you mean 'students'?

Follow the classes to evaluate

  

Class Model

    package com.borges.igreja.model;
    import javax.persistence.Entity;
    import javax.persistence.GeneratedValue;
    import javax.persistence.GenerationType;
    import javax.persistence.Id;
    import javax.persistence.ManyToOne;
    import javax.persistence.Table;
    @Entity
    @Table(name="addalunoeb")
    public class AddAlunoEB {
        @Id
        @GeneratedValue(strategy = GenerationType.IDENTITY)
        private Long Id;

        @ManyToOne
        private Membros alunos;

        @ManyToOne
        private EscolaBiblica escolaBiblica;

        private String dtInicioEB;

        public Long getId() {
            return Id;
        }

        public void setId(Long id) {
            Id = id;
        }

        public Membros getAlunos() {
            return alunos;
        }

        public void setAlunos(Membros alunos) {
            this.alunos = alunos;
        }

        public EscolaBiblica getEscolaBiblica() {
            return escolaBiblica;
        }

        public void setEscolaBiblica(EscolaBiblica escolaBiblica) {
            this.escolaBiblica = escolaBiblica;
        }

        public String getDtInicioEB() {
            return dtInicioEB;
        }

        public void setDtInicioEB(String dtInicioEB) {
            this.dtInicioEB = dtInicioEB;
        }
    }
  

Repository Class

package com.borges.igreja.repository;

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

    import com.borges.igreja.model.AddAlunoEB;
    import com.borges.igreja.model.EscolaBiblica;

    @Repository
    public interface AddAlunoEBRepository extends JpaRepository<AddAlunoEB, Long> {
        Iterable<AddAlunoEB> findByAluno(EscolaBiblica escolaBiblica);

    }
  

Service Class

    package com.borges.igreja.service;

import java.util.List;

import com.borges.igreja.model.AddAlunoEB;
import com.borges.igreja.model.EscolaBiblica;

public interface AddAlunoService {

    List<AddAlunoEB> listarTodos();

    AddAlunoEB listarId(Long id);

    AddAlunoEB cadastrar(AddAlunoEB addAlunoEB);

    AddAlunoEB atualizar(AddAlunoEB addAlunoEB );

    void remover (Long id);

    Iterable<AddAlunoEB> listAluno(EscolaBiblica escolaBiblica);
}
  

Impl Class

    package com.borges.igreja.service.impl;

import java.util.List;

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

import com.borges.igreja.model.AddAlunoEB;
import com.borges.igreja.model.EscolaBiblica;
import com.borges.igreja.repository.AddAlunoEBRepository;
import com.borges.igreja.service.AddAlunoService;

@Service
public class AddAlunoEBServiceImpl implements AddAlunoService {

    @Autowired
    private AddAlunoEBRepository aebr;

    @Override
    public List<AddAlunoEB> listarTodos() {
        return this.aebr.findAll();
    }

    @Override
    public AddAlunoEB listarId(Long id) {
        return this.aebr.findOne(id);
    }

    @Override
    public AddAlunoEB cadastrar(AddAlunoEB addAlunoEB) {
        return this.aebr.save(addAlunoEB);
    }

    @Override
    public AddAlunoEB atualizar(AddAlunoEB addAlunoEB) {
        return this.aebr.save(addAlunoEB);
    }

    @Override
    public void remover(Long id) {
        this.aebr.delete(id);

    }

    @Override
    public Iterable<AddAlunoEB> listAluno(EscolaBiblica escolaBiblica) {

        return this.aebr.findByAluno(escolaBiblica);
    }

}
  

Controller class

    package com.borges.igreja.controller;

import java.util.List;

import javax.validation.Valid;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.borges.igreja.model.AddAlunoEB;
import com.borges.igreja.model.EscolaBiblica;
import com.borges.igreja.repository.AddAlunoEBRepository;
import com.borges.igreja.service.AddAlunoService;
import com.borges.igreja.service.EscolaBiblicaService;
import com.borges.igreja.service.MembrosService;


@Controller
@RequestMapping("/addAlunoEB")
public class AddAlunoEBController {

    @Autowired
    private EscolaBiblicaService escolaBiblicaService;

    @Autowired
    private MembrosService membrosService;

    @Autowired
    private AddAlunoService addAlunoService;

    @Autowired
    private AddAlunoEBRepository adr;

    @GetMapping
    public ModelAndView listarTodos() {
        ModelAndView modelAndView = new ModelAndView("addAlunoEB/listarAlunoEB");
        modelAndView.addObject("addAlunos", adr.findAll());
        return modelAndView;
    }

    @GetMapping("/{id}")
    public  ModelAndView addAluno(@PathVariable Long id, AddAlunoEB alunoEB) {
        EscolaBiblica escolaBiblica = escolaBiblicaService.listarId(id);
        ModelAndView modelAndView = new ModelAndView("addAlunoEB/AddAlunoEB");
        modelAndView.addObject(alunoEB);
        modelAndView.addObject("alunos", membrosService.listarTodos());
        modelAndView.addObject("escolasBiblicas", escolaBiblica);

        //Iterable<AddAlunoEB> addAlunoEB = addAlunoService.listAluno(escolaBiblica);
        Iterable<AddAlunoEB> iterable = addAlunoService.listAluno(escolaBiblica);
        modelAndView.addObject("addAlunosEB", iterable);
        return modelAndView;


    }

    @PostMapping("/{id}")
    public String addAlunoPost(@PathVariable Long id,AddAlunoEB addAlunoEB) {
        EscolaBiblica escolaBiblica = escolaBiblicaService.listarId(id);
        addAlunoEB.setEscolaBiblica(escolaBiblica);
        adr.save(addAlunoEB);
        return "redirect:/addAlunoEB/{id}";
    }

}

Thank you

    
asked by anonymous 06.01.2018 / 00:47

1 answer

0

It seems that JPA is trying to find a student attribute in the AddAlunoEB model. Your find is by Public School. My suggestion is to change the method name to findByBiblical.

    
06.01.2018 / 01:06