'Why spring-boot jersey with webflux cannot route my request?
Trying to migrate my jersey-container-netty-http to spring-boot.
I used JAX-RS annotations @GET @Path("/test") routing my request, but it didn't work. I changed the annotations to @RestController and @GetMapping("/test"), which is part of spring framework, it worked just fine. Any idea?
Demo: https://github.com/SBZORRO/spring-boot-without-servlet.git
Request host/test get a Whitelabel Error Page.
Completed 404 NOT_FOUND
HTTP GET "/test"
Mapped to ResourceWebHandler [classpath [META-INF/resources/], classpath [resources/], classpath [static/], classpath [public/]]
Resource not found
Resolved [ResponseStatusException: 404 NOT_FOUND] for HTTP GET /test
My spring-boot code:
This won't work.
@Component
public class Test{
@GET
@Path("/test")
public String test() {
return "helloworld";
}
}
Tried to add a jersey config, didn't work.
@Configuration
@ApplicationPath("/restful")
public class JerseyConfiguration extends ResourceConfig {
public JerseyConfiguration() {
register(Test.class);
}
}
This works.
@RestController
public class Test{
@GetMapping("/test")
public String test() {
return "helloworld";
}
}
The jersey-container-netty-http server code that I need migrate to spring-boot:
// No @Component here, comparing to `spring-boot` version.
public class Test {
@GET
@Path("/test")
public String test()
{
return "good";
}
}
// Create server
ResourceConfig resourceConfig = new ResourceConfig();
resourceConfig.packages("packages name");
Channel server = NettyHttpContainerProvider.createServer(uri, resourceConfig, false);
pom.xml
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<!-- Exclude the Tomcat dependency -->
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-webflux</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jersey</artifactId>
<exclusions>
<!-- Exclude the Tomcat dependency -->
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
