Описание:
Параметру 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
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
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
LearnRestApiApplication.java
package com.learn.restapi.learnrestapi;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class LearnRestApiApplication {
public static void main(String[] args) {
SpringApplication.run(LearnRestApiApplication.class, args);
}
}
Подробнее здесь: https://stackoverflow.com/questions/789 ... pe-departm
Параметр 0 конструктора в DepartmentService требовал bean-компонента типа DepartmentRepository, который не удалось найти ⇐ JAVA
Программисты JAVA общаются здесь
1726551613
Anonymous
Описание:
Параметру 0 конструктора в com.learn.restapi.learnrestapi.service.DepartmentService требуется bean-компонент типа com.learn.restapi.learnrestapi.persistence.DepartmentRepository. который не удалось найти.
Действие:
Рассмотрите возможность определения bean-компонента типа com.learn.restapi.learnrestapi.persistence.DepartmentRepository в ваша конфигурация.
Кто-нибудь может помочь мне с вышеуказанными проблемами. Ниже приведены мои файлы.
Я новичок в Java и начал этот проект, просматривая
руководство.
[b]DepartmentRepository.java[/b]
package com.learn.restapi.learnrestapi.persistence;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
@Repository
public interface DepartmentRepository extends JpaRepository {
}
[b]DepartmentService.java[/b]
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);
}
}
[b]pom.xml[/b]
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
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
[b]LearnRestApiApplication.java[/b]
package com.learn.restapi.learnrestapi;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class LearnRestApiApplication {
public static void main(String[] args) {
SpringApplication.run(LearnRestApiApplication.class, args);
}
}
Подробнее здесь: [url]https://stackoverflow.com/questions/78990087/parameter-0-of-constructor-in-departmentservice-required-a-bean-of-type-departm[/url]
Ответить
1 сообщение
• Страница 1 из 1
Перейти
- Кемерово-IT
- ↳ Javascript
- ↳ C#
- ↳ JAVA
- ↳ Elasticsearch aggregation
- ↳ Python
- ↳ Php
- ↳ Android
- ↳ Html
- ↳ Jquery
- ↳ C++
- ↳ IOS
- ↳ CSS
- ↳ Excel
- ↳ Linux
- ↳ Apache
- ↳ MySql
- Детский мир
- Для души
- ↳ Музыкальные инструменты даром
- ↳ Печатная продукция даром
- Внешняя красота и здоровье
- ↳ Одежда и обувь для взрослых даром
- ↳ Товары для здоровья
- ↳ Физкультура и спорт
- Техника - даром!
- ↳ Автомобилистам
- ↳ Компьютерная техника
- ↳ Плиты: газовые и электрические
- ↳ Холодильники
- ↳ Стиральные машины
- ↳ Телевизоры
- ↳ Телефоны, смартфоны, плашеты
- ↳ Швейные машинки
- ↳ Прочая электроника и техника
- ↳ Фототехника
- Ремонт и интерьер
- ↳ Стройматериалы, инструмент
- ↳ Мебель и предметы интерьера даром
- ↳ Cантехника
- Другие темы
- ↳ Разное даром
- ↳ Давай меняться!
- ↳ Отдам\возьму за копеечку
- ↳ Работа и подработка в Кемерове
- ↳ Давай с тобой поговорим...
Мобильная версия