我继续通过邮递员收到 404(找不到资源)。我已经通过谷歌尝试过,但我找不到正确的解决方案。
航线等级
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.MediaType;
import org.springframework.web.reactive.function.server.RouterFunction;
import org.springframework.web.reactive.function.server.RouterFunctions;
import org.springframework.web.reactive.function.server.ServerResponse;
import static org.springframework.web.reactive.function.server.RequestPredicates.*;
@Configuration
public class DroneRouters {
@Bean
public RouterFunction<ServerResponse> routes(final DroneHandler droneHandler) {
return RouterFunctions.
route(GET("/").and(accept(MediaType.APPLICATION_JSON)), droneHandler::registerDrone);
}
}
处理程序类
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.reactive.function.server.ServerRequest;
import org.springframework.web.reactive.function.server.ServerResponse;
import reactor.core.publisher.Mono;
@Component
public class DroneHandler {
private static final Logger LOGGER = LoggerFactory.getLogger(DroneHandler.class);
@Autowired
public DroneHandler() {}
public Mono<ServerResponse> registerDrone(final ServerRequest request) {
return ServerResponse.ok().build();
}
}
以下是postman截图 端口配置为 8081
java 版本 8 春季启动版本 '2.7.10'
这是我的 gradle 文件
plugins {
id 'java'
id 'org.springframework.boot' version '2.7.10'
id 'io.spring.dependency-management' version '1.0.15.RELEASE'
}
group = 'com.musala'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '1.8'
configurations {
compileOnly {
extendsFrom annotationProcessor
}
}
repositories {
mavenCentral()
}
dependencies {
// implementation 'org.springframework.boot:spring-boot-starter-security'
implementation 'org.springframework.boot:spring-boot-starter-validation'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-webflux'
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
compileOnly 'org.projectlombok:lombok'
runtimeOnly 'com.h2database:h2'
annotationProcessor 'org.projectlombok:lombok'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'io.projectreactor:reactor-test'
// testImplementation 'org.springframework.security:spring-security-test'
}
tasks.named('test') {
useJUnitPlatform()
}
有人可以帮我解决这个问题吗?