-
Notifications
You must be signed in to change notification settings - Fork 41.2k
Application fails to start when using Actuator and Jersey configured as a Filter #25262
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
Comments
The problem's occurring because filters are initialised more eagerly than servlets. When the initialization happens, Jersey's state is made immutable. If this happens before a call to @Fyro-Ing You can work around the problem by configuring Jersey's filter to be initialised lazily using Boot's @Bean
public DelegatingFilterProxyRegistrationBean jerseyFilterRegistration(JerseyApplicationPath applicationPath,
ResourceConfig resourceConfig, JerseyProperties jersey) {
DelegatingFilterProxyRegistrationBean registration = new DelegatingFilterProxyRegistrationBean("jerseyFilter") {
@Override
public DelegatingFilterProxy getFilter() {
DelegatingFilterProxy filter = super.getFilter();
filter.setTargetFilterLifecycle(true);
return filter;
}
};
registration.setUrlPatterns(Collections.singletonList(applicationPath.getUrlMapping()));
registration.setOrder(jersey.getFilter().getOrder());
registration.addInitParameter(ServletProperties.FILTER_CONTEXT_PATH, stripPattern(applicationPath.getPath()));
addInitParameters(jersey.getInit(), registration);
registration.setName("jerseyFilter");
registration.setDispatcherTypes(EnumSet.allOf(DispatcherType.class));
return registration;
}
@Bean
public ServletContainer jerseyFilter(ResourceConfig resourceConfig) {
return new ServletContainer(resourceConfig);
}
private String stripPattern(String path) {
if (path.endsWith("/*")) {
path = path.substring(0, path.lastIndexOf("/*"));
}
return path;
}
private void addInitParameters(Map<String, String> initParameters, DynamicRegistrationBean<?> registration) {
initParameters.forEach(registration::addInitParameter);
} |
The last version where this worked appears to be 2.1.8.RELEASE as it breaks in 2.1.9.RELEASE. I think that's due to the changes made for #17801 which stopped using a |
We'll update our auto-config to use the |
A downside of the delegating filter proxy approach that we didn't consider is that many Jersey-related errors won't be discovered until the first request is received. That doesn't feel great from a usability perspective. I think it would be good if we can rework the fix for #17801 to use a |
Here's a fix that avoids the use of a delegating filter proxy. Instead, it reworks the fix for #17801 by introducing a |
When using Spring boot with actuator, jersey configured with filter type and component extends from ResourceConfig, start failed
It's ok with servlet type or without actuator deps
To reproduce :
spring.jersey.type=filter
** your app must not have spring-web-mvc deps include on runtime" like spring-cloud-starter-netflix-hystrix-dashboard or org.springframework.boot:spring-boot-starter-web or bean "org.springframework.web.servlet.DispatcherServlet"
seems to be ko from long time ago, try with 2.3.x and 2.2.x with same bug
https://docs.spring.io/spring-boot/docs/current-SNAPSHOT/reference/htmlsingle/#boot-features-jersey
The text was updated successfully, but these errors were encountered: