使用Spring Reactive的RouterFunction来与嵌入式Eureka服务器一起使用来获取简单的Web应用程序时遇到问题。我尝试了几件事,包括使用注释@RestController的旧方法效果很好。此外,我尝试从POM文件中删除Eureka依赖项,之后RouterFunction端点可以正常工作。
POM:
<?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 http://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.0.3.RELEASE</version>
</parent>
<groupId>com.test</groupId>
<artifactId>tds</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<!--SPRING-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
<version>2.0.0.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-webflux</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>4.0.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
</dependencies>
</project>
路由器,没有被击中:
@Configuration
public class Router {
@Bean
public RouterFunction<ServerResponse> route(Handler handler) {
return route(GET("/test"), Handler::handle);
}
}
控制器,效果很好:
@RestController
@ResponseStatus(HttpStatus.OK)
public class controller {
@GetMapping("/discovery")
public String getApplication() {
return "test2222";
}
}
主要:
@SpringBootApplication
@EnableEurekaServer
public class DiscoveryApp {
public static void main(String[] args) {
SpringApplication.run(com.test.tds.DiscoveryApp.class, args);
}
}
如上所述,在删除对Eureka的依赖后,RouterFunction端点可以正常工作。
有人知道如何进行这项工作吗?
答案 0 :(得分:1)
显然Webflux
当前不支持Eureka server
。建议使用旧的spring-boot-starter-web
方法。
作为将来的参考: https://github.com/spring-cloud/spring-cloud-netflix/issues/3108#issuecomment-408262981