Guten Tag liebe Community.
Ich habe ein Spring Projekt angefangen ,aber bin dabei auf einige Probleme gestoßen.
Ich bekomme folgende Meldung:
***************************
APPLICATION FAILED TO START
***************************
Description:
Field projektRepository in controllers.MainController required a bean of type 'repo.ProjektRepository' that could not be found.
The injection point has the following annotations:
- @org.springframework.beans.factory.annotation.Autowired(required=true)
Action:
Consider defining a bean of type 'repo.ProjektRepository' in your configuration.
Das ist mein Controller:
Das ist das Model:
Das ist das Repository Interface:
Im persistence.xml habe ich folgenden Eintrag:
<class>model.Projekt</class>
Was mache ich falsch?
Ich habe ein Spring Projekt angefangen ,aber bin dabei auf einige Probleme gestoßen.
Ich bekomme folgende Meldung:
***************************
APPLICATION FAILED TO START
***************************
Description:
Field projektRepository in controllers.MainController required a bean of type 'repo.ProjektRepository' that could not be found.
The injection point has the following annotations:
- @org.springframework.beans.factory.annotation.Autowired(required=true)
Action:
Consider defining a bean of type 'repo.ProjektRepository' in your configuration.
Das ist mein Controller:
Java:
package controllers;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import models.Projekt;
import repo.ProjektRepository;
@Controller
public class MainController {
@GetMapping("/")
public String huiting(Model model) {
model.addAttribute("titel", "Haupt Seite");
return "sascoSpring";
}
@GetMapping("/sascoSpring")
public String greeting(Model model) {
model.addAttribute("titel", "Haupt Seite");
return "sascoSpring";
}
@Autowired
private ProjektRepository projektRepository;
@GetMapping("/addProg")
public String progAdd(Model model) {
//Das ist der ResultSet von der Tabelle
Iterable<Projekt> projekts=projektRepository.findAll();
model.addAttribute("proj",projekts);
return "programmhinzufuegen";
}
}
Java:
package models;
import java.io.Serializable;
import javax.persistence.*;
import java.sql.Timestamp;
import java.util.List;
/**
* The persistent class for the projekt database table.
*
*/
@Entity
@NamedQuery(name="Projekt.findAll", query="SELECT p FROM Projekt p")
public class Projekt implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@Column(name="projekt_id")
private int projektId;
private Timestamp hinzugefuegt;
private String projekt;
//bi-directional many-to-one association to Programm
@OneToMany(mappedBy="projekt")
private List<Programm> programms;
//bi-directional many-to-one association to ProjektStatistik
@OneToMany(mappedBy="projekt")
private List<ProjektStatistik> projektStatistiks;
public Projekt() {
}
public int getProjektId() {
return this.projektId;
}
public void setProjektId(int projektId) {
this.projektId = projektId;
}
public Timestamp getHinzugefuegt() {
return this.hinzugefuegt;
}
public void setHinzugefuegt(Timestamp hinzugefuegt) {
this.hinzugefuegt = hinzugefuegt;
}
public String getProjekt() {
return this.projekt;
}
public void setProjekt(String projekt) {
this.projekt = projekt;
}
public List<Programm> getProgramms() {
return this.programms;
}
public void setProgramms(List<Programm> programms) {
this.programms = programms;
}
public Programm addProgramm(Programm programm) {
getProgramms().add(programm);
programm.setProjekt(this);
return programm;
}
public Programm removeProgramm(Programm programm) {
getProgramms().remove(programm);
programm.setProjekt(null);
return programm;
}
public List<ProjektStatistik> getProjektStatistiks() {
return this.projektStatistiks;
}
public void setProjektStatistiks(List<ProjektStatistik> projektStatistiks) {
this.projektStatistiks = projektStatistiks;
}
public ProjektStatistik addProjektStatistik(ProjektStatistik projektStatistik) {
getProjektStatistiks().add(projektStatistik);
projektStatistik.setProjekt(this);
return projektStatistik;
}
public ProjektStatistik removeProjektStatistik(ProjektStatistik projektStatistik) {
getProjektStatistiks().remove(projektStatistik);
projektStatistik.setProjekt(null);
return projektStatistik;
}
}
Das ist das Repository Interface:
Java:
package repo;
import org.springframework.data.repository.CrudRepository;
import org.springframework.stereotype.Repository;
import models.Projekt;
@Repository
public interface ProjektRepository extends CrudRepository<Projekt,Long>{
}
Im persistence.xml habe ich folgenden Eintrag:
<class>model.Projekt</class>
Was mache ich falsch?