ПРИЛОЖЕНИЕ НЕ ЗАПУСТИЛО
Описание:
Полю questionsDAO в com.demo.QuizApp.service.QuestionService требовался bean-компонент типа com.demo.QuizApp.dao.questionDAO, который не удалось найти.
Точка внедрения имеет следующие аннотации:
- @org.springframework.beans.factory.annotation.Autowired(required=true)
Действие:
Рассмотрите возможность определения компонента типа «com.demo.QuizApp.dao.questionDAO» в вашей конфигурации.**
Вот мой код.
QuestionContoller.java
Код: Выделить всё
package com.demo.QuizApp.controller;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.demo.QuizApp.service.QuestionService;
@RestController
@RequestMapping("questions")
public class QuestionContoller {
@Autowired
QuestionService questionService;
@GetMapping("AllQuestions")
public Long getAllQuestionAll() {
return questionService.getAllQuestionAll();
}
}
Код: Выделить всё
package com.demo.QuizApp.service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.demo.QuizApp.dao.questionDAO;
@Service
public class QuestionService {
@Autowired
questionDAO questionDAO;
public long getAllQuestionAll() {
return questionDAO.count();
}
}
Код: Выделить всё
package com.demo.QuizApp.model;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.Table;
import lombok.Data;
@Data
@Entity
@Table(name = "Question")
public class Question {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id")
private int id;
@Column(name = "questionTitle")
private String questionTitle;
@Column(name = "rightAnswer")
private String rightAnswer;
@Column(name = "diffcultyLevel")
private String diffcultyLevel;
@Column(name = "option1")
private String option1;
@Column(name = "option2")
private String option2;
@Column(name = "option3")
private String option3;
@Column(name = "option4")
private String option4;
}
Код: Выделить всё
package com.demo.QuizApp.dao;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
import com.demo.QuizApp.model.Question;
@Repository
public interface questionDAO extends JpaRepository{
}
Код: Выделить всё
spring.application.name=QuizApp
spring.datasource.driver-class-name=org.postgresql.Driver
spring.datasource.url=jdbc:postgresql://localhost:5432/QuestionDB
spring.datasource.username=postgres
spring.datasource.password=root
spring.jpa.hibernate.ddl-auto=update
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect
spring.autoconfigure.exclude=org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration
Код: Выделить всё
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
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.2.3
com.demo
QuizApp
0.0.1-SNAPSHOT
QuizApp
Demo project for Spring Boot
17
org.springframework.boot
spring-boot-starter-data-jpa
org.springframework.boot
spring-boot-starter-web
mysql
mysql-connector-java
5.1.49
org.hibernate
hibernate-core
4.1.4.Final
org.hibernate
hibernate-entitymanager
5.2.3.Final
javax.xml.bind
jaxb-api
2.3.0
org.postgresql
postgresql
runtime
org.projectlombok
lombok
true
org.springframework.boot
spring-boot-starter-test
test
org.springframework.boot
spring-boot-maven-plugin
org.projectlombok
lombok
Подробнее здесь: https://stackoverflow.com/questions/781 ... e-but-i-fa