Описание:
Параметру 0 конструктора в com.learn.restapi.learnrestapi.service.DepartmentService требуется bean-компонент типа com.learn.restapi.learnrestapi.persistence.DepartmentRepository. который не удалось найти.
Действие:
Рассмотрите возможность определения bean-компонента типа com.learn.restapi.learnrestapi.persistence.DepartmentRepository в ваша конфигурация.
Кто-нибудь может помочь мне с вышеуказанными проблемами. Ниже приведены мои файлы.
Я новичок в Java и начал этот проект, просматривая
руководство.
DepartmentRepository.java
package com.learn.restapi.learnrestapi.persistence;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
@Repository
public interface DepartmentRepository extends JpaRepository {
}
DepartmentService.java
package com.learn.restapi.learnrestapi.service;
import com.learn.restapi.learnrestapi.persistence.Department;
import com.learn.restapi.learnrestapi.persistence.DepartmentRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.Optional;
@Service
public class DepartmentService {
DepartmentRepository repository;
@Autowired
public DepartmentService(DepartmentRepository repository) {
this.repository = repository;
}
public List getAllDepartments() {
return this.repository.findAll();
}
public Department getDepartmentById(Long id) {
return this.repository.findById(id).get();
}
public Department saveDepartment(Department department) {
return this.repository.save(department);
}
public Department updateDepartment(Long id, Department department) {
Optional dept = this.repository.findById(id);
if (dept.isPresent()) {
Department d = dept.get();
d.setName(department.getName());
return this.repository.save(d);
}
throw new RuntimeException("Department not found");
}
public void deleteDepartment(Long id) {
this.repository.deleteById(id);
}
}
pom.xml
4.0.0
org.springframework.boot
spring-boot-starter-parent
3.3.3
com.learn.restapi
LearnRestAPI
0.0.1-SNAPSHOT
LearnRestAPI
LearnRestAPI
17
17
17
jcenter-snapshots
jcenter
https://jcenter.bintray.com/
org.springframework.boot
spring-boot-starter-data-jpa
org.springframework.boot
spring-boot-starter-web
com.microsoft.sqlserver
mssql-jdbc
runtime
org.projectlombok
lombok
true
org.springframework.boot
spring-boot-starter-test
test
io.springfox
springfox-boot-starter
3.0.0
org.springdoc
springdoc-openapi-starter-webmvc-ui
2.3.0
javax.servlet
javax.servlet-api
4.0.1
provided
org.springframework.boot
spring-boot-maven-plugin
org.projectlombok
lombok
Подробнее здесь: https://stackoverflow.com/questions/789 ... pe-departm
Параметр 0 конструктора в DepartmentService требовал bean-компонента типа DepartmentRepository, который не удалось найти ⇐ JAVA
-
- Похожие темы
- Ответы
- Просмотры
- Последнее сообщение
-
-
Параметр 0 конструктора требовал bean-компонента типа X, который не удалось найти.
Anonymous » » в форуме JAVA - 0 Ответы
- 24 Просмотры
-
Последнее сообщение Anonymous
-