Полный проект можно найти на моем GitHub здесь: https://github.com/plasmastorm36/ToDoList/
Большая проблема заключается в том, что мое приложение не может найти этот загадочный объектEntityManagerFactory.
Я попробовал изменить файл application.properties и файл pom.xml, чтобы посмотреть, исправит ли это что-нибудь. Я также пробовал использовать autowired.
Каждый раз, когда я пытаюсь запустить его с помощью Maven, я получаю это сообщение об ошибке:
***************************
ПРИЛОЖЕНИЕ НЕ ЗАПУСТИЛО
***************************
Описание:
Параметру 0 конструктора в com.todo.demo.service.TaskService
требовался компонент с именем «entityManagerFactory», который не удалось найти.
Действие:< /p>
Рассмотрите возможность определения bean-компонента с именем «entityManagerFactory» в вашей
конфигурации.
Проблема может быть связана с на данный момент ничего, но я думаю, что именно здесь могут возникнуть проблемы.
Мой класс сущности
package com.todo.demo;
import java.time.LocalDate;
import jakarta.persistence.*;
@Entity
@Table(name = "tasks")
/**
* @Author Noah Rouse
* @email: [email protected]
* @description: this class is designed to store and represent tasks in a todo list
*/
public class Task {
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column
private long id;
@Column(name = "description", nullable = false)
private String description;
@Column(name = "completed")
private boolean completed;
@Column(name = "priority")
private String priority;
@Column(name = "due_date")
private LocalDate dueDate;
@Column(name = "created")
private LocalDate created;
@Column(name = "last_updated")
private LocalDate lastUpdated;
public Task () {}
public Task (final Long id, final String description, final String priority,
final LocalDate dueDate) {
this.id = id;
this.completed = false;
this.description = description;
this.priority = priority;
this.dueDate = dueDate;
this.created = LocalDate.now();
this.lastUpdated = created;
}
/**
* @return task id
*/
public long id () {
return this.id;
}
/**
* @return description
*/
public String description () {
return this.description;
}
/**
* set task description to new description and changes last updated value
* @return updated description
*/
public String description (final String description) {
this.description = description;
this.lastUpdated = LocalDate.now();
return this.description;
}
/**
* @return if the task is completed
*/
public boolean completed () {
return this.completed;
}
/**
* Set completed to true or false
* @return updated completed status
*/
public boolean completed (final boolean completed) {
this.completed = completed;
this.lastUpdated = LocalDate.now();
return this.completed;
}
/**
* @return priority of task
*/
public String priority () {
return this.priority;
}
/**
* sets task to new priority
* @return new priority
*/
public String priority (final String priority) {
this.priority = priority;
this.lastUpdated = LocalDate.now();
return this.priority;
}
/**
* @return current task due date
*/
public LocalDate dueDate () {
return this.dueDate;
}
/**
* change due date to new local date
* @return new due date
*/
public LocalDate dueDate (final LocalDate dueDate) {
this.dueDate = dueDate;
this.lastUpdated = LocalDate.now();
return this.dueDate;
}
/**
* @return when the task was last updated
*/
public LocalDate lastUpdated () {
return this.lastUpdated;
}
}
Мой класс обслуживания
package com.todo.demo.service;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.todo.demo.Task;
import com.todo.demo.repository.TaskRepository;
import java.time.LocalDate;
import java.util.Optional;
@Service
@Transactional
public class TaskService {
public class TaskNotFoundException extends Exception {
}
private final TaskRepository taskRepos;
public TaskService (final TaskRepository taskRepository) {
taskRepos = taskRepository;
}
public void updateTaskDescription (final long taskId, final String description)
throws TaskNotFoundException {
final Optional potentialTask = taskRepos.findById(taskId);
if (potentialTask.isPresent()) {
final Task task = potentialTask.get();
task.description(description);
taskRepos.save(task);
} else {
throw new TaskNotFoundException();
}
}
public void updateTaskCompletion (final long taskId, final boolean completed)
throws TaskNotFoundException {
final Optional potentialTask = taskRepos.findById(taskId);
if (potentialTask.isPresent()) {
final Task task = potentialTask.get();
task.completed(completed);
taskRepos.save(task);
} else {
throw new TaskNotFoundException();
}
}
public void updateTaskPriority (final long taskId, final String priority)
throws TaskNotFoundException {
final Optional potentialTask = taskRepos.findById(taskId);
if (potentialTask.isPresent()) {
final Task task = potentialTask.get();
task.priority(priority);
taskRepos.save(task);
} else {
throw new TaskNotFoundException();
}
}
public void updateTaskDueDate (final long taskId, final LocalDate dueDate)
throws TaskNotFoundException {
final Optional potentialTask = taskRepos.findById(taskId);
if (potentialTask.isPresent()) {
final Task task = potentialTask.get();
task.dueDate(dueDate);
taskRepos.save(task);
} else {
throw new TaskNotFoundException();
}
}
}
мой файл pom.xml
4.0.0
org.springframework.boot
spring-boot-starter-parent
3.3.5
com.todo
demo
0.0.1-SNAPSHOT
demo
Demo project for Spring Boot
21
com.h2database
h2
2.1.214
org.springframework.data
spring-data-jpa
3.3.5
jakarta.persistence
jakarta.persistence-api
3.2.0
org.springframework.boot
spring-boot-starter-web
org.springframework.boot
spring-boot-starter-test
test
org.springframework.boot
spring-boot-maven-plugin
Мой файл application.properties:
spring.application.name=demo
spring.datasource.url=jdbc:h2:mem:testdb;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE
spring.datasource.driverClassName=org.h2.Driver
spring.datasource.username=sa
spring.datasource.password=
spring.jpa.database-platform=org.hibernate.dialect.H2Dialect
spring.jpa.hibernate.ddl-auto=update
spring.jpa.show-sql=true
spring.h2.console.enabled=true
Подробнее здесь: https://stackoverflow.com/questions/791 ... -called-en
По какой-то причине, когда я пытаюсь запустить свою программу, она не может найти что-то под названиемentityManagerFacto ⇐ JAVA
-
- Похожие темы
- Ответы
- Просмотры
- Последнее сообщение