这是我的课程,我不知道该怎么做来修复这个错误。对不起,如果我只是在这里张贴,但我想让你知道这一切。
我想创建一个后端应用程序,在那里我可以使用Postgres和JDBC存储有关事件的详细信息。这里是整个错误
应用程序启动失败
说明:
事件中构造函数的参数0。提醒pp.model.事件需要一个类型为“java.util.UUID”的bean,但找不到。
注入点具有以下注释:-@com。fasterxml。杰克逊。注释。JsonProperty(索引=-1,访问=自动,值=“id”,默认值=”,必需=false)
行动:
考虑定义“java”类型的bean。util。配置中的UUID。
事件Java语言
package event.ReminderApp.model;
import com.fasterxml.jackson.annotation.JsonProperty;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import java.util.Date;
import java.util.UUID;
@SpringBootApplication
public class Event {
private final UUID id;
private final String name;
private final Date startDate;
private final Date endDate;
private final String details;
@Autowired
public Event(@JsonProperty("id") UUID id,
@JsonProperty("name") String name,
@JsonProperty("startDate") Date startDate,
@JsonProperty("endDate") Date endDate,
@JsonProperty("details") String details) {
this.id = id;
this.name = name;
this.startDate = startDate;
this.endDate = endDate;
this.details = details;
}
pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" 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">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.3.1.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>event</groupId>
<artifactId>ReminderApp</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>ReminderApp</name>
<description>This app is a google calendar clone</description>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- https://mvnrepository.com/artifact/javax.persistence/javax.persistence-api -->
<dependency>
<groupId>javax.persistence</groupId>
<artifactId>javax.persistence-api</artifactId>
<version>2.2</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.flywaydb</groupId>
<artifactId>flyway-core</artifactId>
</dependency>
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.3.0</version>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-jpa</artifactId>
<version>2.1.17.RELEASE</version>
</dependency>
<dependency>
<groupId>jakarta.validation</groupId>
<artifactId>jakarta.validation-api</artifactId>
<version>2.0.2</version>
</dependency>
<dependency>
<groupId>com.sun.istack</groupId>
<artifactId>istack-commons-runtime</artifactId>
<version>3.0.11</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>5.2.7.RELEASE</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M5</version>
<configuration>
<!-- Activate the use of TCP to transmit events to the plugin -->
<forkNode implementation="org.apache.maven.plugin.surefire.extensions.SurefireForkNodeFactory"/>
</configuration>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>9</source>
<target>9</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
EventDatabaseService。Java语言
package event.ReminderApp.dao;
import event.ReminderApp.model.Event;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;
import java.util.Date;
import java.util.List;
import java.util.Optional;
import java.util.UUID;
@Repository
public class EventDatabaseService implements EventInterface {
private final JdbcTemplate jdbcTemplate;
@Autowired
public EventDatabaseService(JdbcTemplate jdbcTemplate) {
this.jdbcTemplate = jdbcTemplate;
}
@Override
public int insertEvent(UUID id, Event Event) {
return 0;
}
@Override
public List<Event> selectAllEvents() {
final String sql = "SELECT id, eventName, startdate, enddate, details FROM event";
return jdbcTemplate.query(sql, (resultSet, i )-> {
UUID eventId = UUID.fromString(resultSet.getString("id"));
String eventName = resultSet.getString("eventName");
Date startDate = resultSet.getDate("startdate");
Date endDate = resultSet.getDate("endDate");
String details = resultSet.getString("details");
return new Event(eventId, eventName, startDate, endDate, details);
});
}
@Override
public Optional<Event> selectEventById(UUID id) {
return Optional.empty();
}
@Override
public int updateEventById(UUID id, Event Event) {
return 0;
}
@Override
public int deleteEventById(UUID id) {
return 0;
}
}
事件控制器。Java语言
package event.ReminderApp.api;
import event.ReminderApp.model.Event;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import event.ReminderApp.service.EventService;
import javax.validation.Valid;
import javax.validation.constraints.NotNull;
import java.util.List;
import java.util.UUID;
@RestController
@RequestMapping("event/ReminderApp/api/v1/event")
public class EventController {
public final EventService eventService;
@Autowired
public EventController(EventService eventService) {
this.eventService = eventService;
}
@PostMapping
public void addEvent(@RequestBody Event event) {
eventService.addEvent(event);
}
@GetMapping
public List<Event> getAllEvents() {
return eventService.getAllEvents();
}
@GetMapping("{id}")
public Event getEventById(@PathVariable("id") UUID id) {
return eventService.getEventById(id)
.orElse(null);
}
@PutMapping("{id}")
public void updateEvent(@PathVariable("id") UUID id, @Valid @NotNull @RequestBody Event eventToUpdate) {
eventService.updateEvent(id, eventToUpdate);
}
@DeleteMapping("{id}")
public void deleteEvent(@PathVariable("id") UUID id) {
eventService.deleteEvent(id);
}
}
事件服务。Java语言
package event.ReminderApp.service;
import event.ReminderApp.dao.EventInterface;
import event.ReminderApp.model.Event;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.Optional;
import java.util.UUID;
@Service
public class EventService {
public final EventInterface eventInterface;
@Autowired
public EventService(EventInterface eventInterface) {
this.eventInterface = eventInterface;
}
public int addEvent(Event event) {
return eventInterface.insertEvent(event);
}
public Optional<Event> getEventById(UUID id) {
return eventInterface.selectEventById(id);
}
public List<Event> getAllEvents() {
return eventInterface.selectAllEvents();
}
public int updateEvent(UUID id, Event event){
return eventInterface.updateEventById(id, event);
}
public int deleteEvent(UUID id) {enter code here
return eventInterface.deleteEventById(id);
}
}```
您是否尝试在带有main方法的类上使用@SpringBootApplication?类似于这个例子https://spring.io/guides/gs/spring-boot/
package com.example.springboot;
import java.util.Arrays;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
@SpringBootApplication
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
@Bean
public CommandLineRunner commandLineRunner(ApplicationContext ctx) {
return args -> {
System.out.println("Let's inspect the beans provided by Spring Boot:");
String[] beanNames = ctx.getBeanDefinitionNames();
Arrays.sort(beanNames);
for (String beanName : beanNames) {
System.out.println(beanName);
}
};
}
}
我想有一个SSO CAS认证,我已经按照Bealdung的教程(https://www.baeldung.com/spring-security-cas-sso第4部分)的说明,但当我作为Spring启动应用程序运行时,我有这个错误 SecurityConfig中构造函数的参数0需要找不到类型为“org.springframework.security.cas.authentication.Cas
我有两个项目: null 提前感谢您的帮助。
在此处输入图像描述 在此处输入图像描述 我仍然不知道该怎么办(我在UserRepository上尝试了Repository注释-错误是一样的)。错误消息:`启动ApplicationContext时出错。要显示条件报告,请在启用“调试”的情况下重新运行应用程序。2022-03-14 09:04:54.626错误7236---[main]o.s.b.d.LoggingFailureAnalysisR
ResourceServerConfiguration中构造函数的参数0需要类型为“StratusAuthenticationEntryPoint”的bean,但找不到该bean。 我使用的是spring boot 2.6.6,代码如下: 错误消息:
我正在创建一个,其中任何客户端都可以提交请求,这些请求可以是、、、。 但是在创建这个应用程序时,我遇到了以下错误: 我的应用程序的结构是: 我尝试用、、注释,但仍然得到相同的错误。 我甚至从这些答案中尝试了解决方案: (1)构造函数的参数0需要一个类型为'java.lang.String'的bean,但找不到该bean 但我仍然无法解决我的问题。
以下是服务: 下面是映射器: