Skip to content

JerseyWebApplicationInitializer always gets loaded, setting a ServletContext initParameter #45289

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
evandongen opened this issue Apr 25, 2025 · 1 comment
Assignees
Labels
type: bug A general bug
Milestone

Comments

@evandongen
Copy link

Summary:
The JerseyWebApplicationInitializer always gets loaded, setting a ServletContext initParameter contextConfigLocation to a value which breaks another WebApplicationInitalizer which already has a value for configLocation.

Details
Hi, I'm trying to incorporate springdoc (swagger / openapi docs) in our spring application, the console of the Frank!Framework. This console is a spring boot application which is bootstrapped when starting the framework.

Springdoc introduces the spring-boot-autoconfigure dependency to our application. When spring-boot-autoconfigure is present, it will load org.springframework.boot.autoconfigure.jersey.JerseyAutoConfiguration.JerseyWebApplicationInitializer, defined in the JerseyAutoConfiguration. Jersey is not present, so this auto configuration won't be loaded. But, this inner static class doesn't have a @ConditionalOn* annotation which makes sure it gets loaded (in our application), setting the contextConfigLocation initParameter to <NONE> in the servletContext. This results in overriding the context config location of our WebApplicationInitializer, which in turn makes sure our application doesn't start anymore, see the attached stacktrace. The error is: Caused by: java.io.FileNotFoundException: Could not open ServletContext resource [/<NONE>].

If I debug and make sure this <NONE> init parameter is set to 'null' in org.springframework.web.context.ContextLoader#configureAndRefreshWebApplicationContext, so it isn't overriding the configLocation of the webapplicationContext, our application starts like I would expect.

I can't seem to override this init parameter (you can only set this to a non-null value or check if the value is set). I think that Conditional loading of the JerseyWebApplicationInitializer will fix this issue. Other static inner classes use conditional loading in that file as well, for instance the JacksonResourceConfigCustomizer right below it.

I've discussed this with a few other contributors to our framework and we all think that this JerseyWebApplicationInitializer shouldn't be loaded. We are using spring boot 3.4.4.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Apr 25, 2025
@wilkinsona wilkinsona added type: bug A general bug and removed status: waiting-for-triage An issue we've not yet triaged labels Apr 25, 2025
@wilkinsona wilkinsona added this to the 3.3.x milestone Apr 25, 2025
@wilkinsona
Copy link
Member

Thanks for the report. Unfortunately, we can't use conditions here as it's the servlet container that finds and loads the classes that implement WebApplicationInitializer. It passes them to SpringServletContainerInitializer.onStartup(Set<Class<?>>, ServletContext) which then creates an instance of each class, orders them, and calls them. Instead, I think we can update JerseyWebApplicationInitializer to only set the init parameter when org.glassfish.jersey.server.spring.SpringWebApplicationInitializer is present.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug A general bug
Projects
None yet
Development

No branches or pull requests

3 participants