resteasy / resteasy-spring-boot

Apache License 2.0
123 stars 51 forks source link

Ignore registration failure for resteasy servlet #314

Closed dsharinov closed 3 months ago

dsharinov commented 4 months ago

When deploying application on Tomcat, I'm getting the following error:

java.lang.IllegalStateException: Failed to register 'servlet ResteasyServlet' on the servlet context. Possibly already registered?
        at org.springframework.boot.web.servlet.DynamicRegistrationBean.register(DynamicRegistrationBean.java:122)
        at org.springframework.boot.web.servlet.RegistrationBean.onStartup(RegistrationBean.java:52)
        at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.selfInitialize(ServletWebServerApplicationContext.java:241)
        at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.createWebServer(ServletWebServerApplicationContext.java:197)
        at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.onRefresh(ServletWebServerApplicationContext

Executable war file runs without any issues. If when debugging, I set ignoreRegistrationFailure to true in ResteasyApplicationBuilder#build the application is deployed successfully. I checked the code for Jersey, and it's also configured to ignore registration failures. I couldn't find an easy way to get ride of the error.

liweinan commented 4 months ago

@dsharinov Could you please provide a sample project to reproduce this on Github?

dsharinov commented 4 months ago

@liweinan https://github.com/dsharinov/resteasy-example That's a simple example that fails with the error when deployed on Tomcat but runs successfully as a Spring Boot application.

    Caused by: java.lang.IllegalStateException: Failed to register 'servlet com.example.resteasy.ResteasyServlet' on the servlet context. Possibly already registered?
        at org.springframework.boot.web.servlet.DynamicRegistrationBean.register(DynamicRegistrationBean.java:122)
        at org.springframework.boot.web.servlet.RegistrationBean.onStartup(RegistrationBean.java:52)
        at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.selfInitialize(ServletWebServerApplicationContext.java:241)
        at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.createWebServer(ServletWebServerApplicationContext.java:197)
        at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.onRefresh(ServletWebServerApplicationContext.java:162)

Just in case, here are my settings for Tomcat run configuration in IntelliJ: image

liweinan commented 4 months ago

@dsharinov Thanks for the example and detail explanations :D I'll check it.

liweinan commented 4 months ago

Sorry I was working on some other tasks, I'll try to find time to check this during this week.

liweinan commented 4 months ago

@dsharinov I deployed the project to Tomcat 11 and it seems it doesn't have problem:

image

The Tomcat version I used is:

dsharinov commented 4 months ago

@liweinan Thanks! That's good to know, unfortunately it's still an alpha version. I cannot tell customers to install it. Would it still be possible to ignore registration failures and see if it works on Tomcat 10?

liweinan commented 4 months ago

@liweinan Thanks! That's good to know, unfortunately it's still an alpha version. I cannot tell customers to install it. Would it still be possible to ignore registration failures and see if it works on Tomcat 10?

I haven't tested it on Tomcat 10. I'll verify this.

liweinan commented 4 months ago

@dsharinov I tested it on Tomcat 10 and the example also works:

image

The tomcat I used is:

liweinan commented 3 months ago

I assume this issue is answered. Please reopen it if the problem exists.