Spring boot Webflux router endpoint produces 404 with external server

已回答

When using embedded Tomcat (v.10.1.19) server in IntelliJ Ultimate (Build #IU-233.14475.28) the reactive app I realized with Spring boot (v.3.2.3) and webflux dependency works just fine. However,  when deployed on external Tomcat server (v.10.1.20), the app reports http status 404. What I did so far:

I'd be glad to understand the reason, could anyone help with analysis? 

 

Router

@Configuration
@EnableWebFlux
public class Router {
    @Bean
    public RouterFunction<ServerResponse> router(AppController controller) {
        return RouterFunctions
                .route(GET("/product/state"), controller::handleGetProductStateRequest);
    }
}

Controller

@Component
public class AppController {
    private final ProductRepository repository;
    public AppController(ProductRepository repository){
        this.repository = repository;
    }
    /**
     * Get product state as stream
     * This handler function processes GET requests and sends a response
     */
    public Mono<ServerResponse> handleGetProductRequest(ServerRequest ignoredRequest) {
        Flux<Product> products= repository.getProductStream();
        return ServerResponse.ok().header("Access-Control-Allow-Origin", "*")
                .contentType(MediaType.TEXT_EVENT_STREAM)
                .body(products, Product.class);
    }
}

pom.xml

<dependencies>
    <dependency>
       <groupId>org.springframework.boot</groupId>
       <artifactId>spring-boot-starter-webflux</artifactId>
    </dependency>
    <dependency>
       <groupId>org.springframework.boot</groupId>
       <artifactId>spring-boot-starter-tomcat</artifactId>
       <scope>provided</scope>
    </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>
</dependencies>
0

Hello, Hamp Mathias 

 

Deploying a Spring Boot application with WebFlux on an external Tomcat server and encountering a 404 error can be due to several reasons. Here are some potential causes and solutions to consider:

Servlet Initializer:
Ensure your application extends SpringBootServletInitializer and overrides the configure method. This is necessary for deploying to an external servlet container.
Tomcat Version Compatibility:
Spring Boot 3.x may not be compatible with Tomcat 10.1.x due to changes in the Jakarta EE specifications. Consider downgrading to Tomcat 9 or upgrading your Spring Boot application to align with the Jakarta EE 9 requirements.
Context Path:
Verify the context path of your application when deployed on the external server. It should match the one configured in your application properties.
Application Properties:
Check your application.properties or application.yml file for any server-specific configurations that might be causing issues when deployed externally.
Packaging:
Make sure your project is packaged as a WAR file with the necessary dependencies marked as provided since they are supplied by the external Tomcat server.
Deployment Method:
Try deploying your WAR file through the Tomcat Manager UI to see if there are any errors during the deployment process.
Logs:
Review the Tomcat server logs for any exceptions or errors that could indicate what’s going wrong.
Spring Boot Version:
Since you’re using Spring Boot 3.2.3, ensure that all your dependencies are compatible with this version.

 

I hope my suggestion is helpful for you.

 

Best Regard,
patrick521
 

0

Hamp Mathias  Can you check the logs file in the external Tomcat to see if any exceptions inside it? The file should be apache-tomcat-10.0.27-install-dir/logs/catalina.out .

0

请先登录再写评论。