Hallo zusammen wieder mal eine Spring boot Frage :
Ich habe ein Projekt "model" und ein weiteres "spring".
Im "spring" Projekt soll die Database Anbindung passieren.
Ich verwende dazu h2.
Hier mein Pom (aus Spring Projekt)
Hier das Repository Interface
Die Klasse ImportedTeam befindet sich im model Projekt.
Jedoch bekomme ich dann die Exception :
Wenn ich die Klasse Imported Team nun in das Spring Projekt verschiebe funktioniert es.
Ich hoffe es ist nicht allzu kompliziert erklärt.
Kann mir jemand einen Tipp geben
Ich habe ein Projekt "model" und ein weiteres "spring".
Im "spring" Projekt soll die Database Anbindung passieren.
Ich verwende dazu h2.
Hier mein Pom (aus Spring Projekt)
Java:
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-thymeleaf -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
Hier das Repository Interface
Java:
public interface TeamRepository extends JpaRepository<ImportedTeam, Long> {
}
Java:
@Controller
public class EmployeeController {
@Autowired
private EmployeeRepository employeeData;
@Autowired
private TeamRepository teamData;
@GetMapping("/")
public String addNewEmployee(Model model) {
Employee emp = new Employee();
emp.setName("Test Name 1");
employeeData.save(emp);
ImportedTeam team = new ImportedTeam();
team.setName("team 2 - ");
teamData.save(team);
List<Employee> all = employeeData.findAll();
System.out.println("ALL EMPLOYEES : " + all.size());
model.addAttribute("teams", teamData.findAll());
model.addAttribute("employees", employeeData.findAll());
return "index2";
}
}
Die Klasse ImportedTeam befindet sich im model Projekt.
Jedoch bekomme ich dann die Exception :
Code:
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'employeeController': Unsatisfied dependency expressed through field 'teamData'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'teamRepository': Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Not a managed type: class volleyball.model.match.team.ImportedTeam
Wenn ich die Klasse Imported Team nun in das Spring Projekt verschiebe funktioniert es.
Ich hoffe es ist nicht allzu kompliziert erklärt.
Kann mir jemand einen Tipp geben