【发布时间】:2021-06-12 11:39:36
【问题描述】:
我用webflux写了一个rest api,我在这个项目中使用了liquebase,但是当我最后发送项目calisdirib请求时,我看到控制器不起作用。我找不到问题。
什么问题?当我使用 locahost 查询时, 它不来这里(不是工作请求)
请帮帮我
我的邮递员错误
org.springframework.web.server.ResponseStatusException: 404
NOT_FOUND\r\n\tat org.springframework.web.reactive.
resource.ResourceWebHandler.lambda$handle$1(R
esourceWebHandler.java:378)\r\n\tSuppressed:
reactor.core.publisher.FluxOnAssembly$OnAssemblyException: \nError has
been observed at the following site(s):\n\t|_ checkpoint ⇢ HTTP GET
\"/api/label\" [ExceptionHandlingWebHandler]\nStack trace:\r\n\t\tat
org.springframework.web.reactive.resource.ResourceWebHandler.
lambda$handle$1(R
esourceWebHandler.java:378)\r\n\t\tat
reactor.core.publisher.MonoDefer.subscribe(MonoDefer.java:44)\r\n\t\tat
reactor.core.publisher.Mono.subscribe(Mono.java:4046)\r\n\t\tat
我的控制器
@RestController
@RequestMapping("/api/label")//When I query using locahost, it doesn't come here (not working request)
public class LabelController {
@Autowired
LabelService labelService;//this service layer
@GetMapping
public Flux<LabelEntity> getAllLabels(){
return labelService.getAll();
}
}
主类
@SpringBootApplication
@EnableR2dbcRepositories
@ComponentScan("com.WebFluxTestCodes.WebFluxTestCodes.business.*")
public class WebFluxTestCodesApplication {
public static void main(String[] args) {
SpringApplication.run(WebFluxTestCodesApplication.class, args);//main class
}
}
pom.xml
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.4.3</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.WebFluxTestCodes</groupId>
<artifactId>WebFluxTestCodes</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>WebFluxTestCodes</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>11</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-r2dbc</artifactId>//r2dbc reactive dependency
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jdbc</artifactId>//jdbc
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-webflux</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.liquibase</groupId>
<artifactId>liquibase-core</artifactId>//liquibase database version control
<version>3.10.3</version>
</dependency>
<dependency>
<groupId>io.r2dbc</groupId>
<artifactId>r2dbc-postgresql</artifactId>//postgre database
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.liquibase</groupId>
<artifactId>liquibase-maven-plugin</artifactId>
<version>4.3.1</version>
</dependency>
<dependency>
<groupId>io.r2dbc</groupId>
<artifactId>r2dbc-pool</artifactId>
<version>0.9.0.M1</version>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>//lombok library anotation getter setter and other
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.projectreactor</groupId>
<artifactId>reactor-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>javax.persistence</groupId>
<artifactId>javax.persistence-api</artifactId>
<version>2.2</version>
</dependency>
</dependencies>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<excludes>
<exclude>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
【问题讨论】:
-
我相信我们在这里需要更多的上下文。请发布控制器和应用程序类(或相关摘录。)
-
你能发布你的控制器,路由。你是如何定义端点的?
-
没有对labelcontroller的请求
-
有几件事可能是错误的,您的文件夹结构是否正确,以便框架可以拾取和注册 RestController?
-
我不明白这是怎么回事
标签: spring-boot rest spring-webflux