Skip to content
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

Resource Versioning Handler not being called if any FilterRegistrationBean is found #14897

Closed
iamareebjamal opened this issue Oct 18, 2018 · 6 comments
Assignees
Labels
type: blocker An issue that is blocking us from releasing type: bug A general bug type: regression A regression from a previous release
Milestone

Comments

@iamareebjamal
Copy link

iamareebjamal commented Oct 18, 2018

Issue:

If actuator starter dependency is included in the project, the resource strategies stop working, for instance, GZip or Content Versioning strategies are not called. Even AbstractResourceHandler stops getting invoked. Removing the actuator starter dependency makes the config start working again. This is reproducible on a simple https://start.spring.io template (with thymeleaf, web and actuator starters) as well. This also gets resolved on downgrading to 2.0.5. Sample repo is provided below

Sample Repo:

https://github.com/iamareebjamal/spring-boot-resource-versioning-bug

Environment:

Spring Boot 2.0.6

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Oct 18, 2018
@philwebb
Copy link
Member

Thanks for the detailed report and for the sample application. I'm still digging into the root cause, but it looks like the problem might be related to the @ConditionalOnMissingBean on the FilterRegistrationBean<ResourceUrlEncodingFilter> resourceUrlEncodingFilter() method in ThymeleafWebMvcConfiguration.

In 2.0.5 running with debug reports:

   ThymeleafAutoConfiguration.ThymeleafWebMvcConfiguration#resourceUrlEncodingFilter matched:
      - @ConditionalOnMissingBean (types: org.springframework.web.servlet.resource.ResourceUrlEncodingFilter; SearchStrategy: all) did not find any beans (OnBeanCondition)
      - @ConditionalOnEnabledResourceChain enabled (OnEnabledResourceChainCondition)

in 2.0.6

   ThymeleafAutoConfiguration.ThymeleafWebMvcConfiguration#resourceUrlEncodingFilter:
      Did not match:
         - @ConditionalOnMissingBean (types: org.springframework.boot.web.servlet.FilterRegistrationBean; SearchStrategy: all) found beans of type 'org.springframework.boot.web.servlet.FilterRegistrationBean' webMvcMetricsFilter (OnBeanCondition)

@philwebb philwebb added type: bug A general bug type: blocker An issue that is blocking us from releasing type: regression A regression from a previous release and removed status: waiting-for-triage An issue we've not yet triaged labels Oct 18, 2018
@philwebb philwebb added this to the 2.0.7 milestone Oct 18, 2018
@philwebb
Copy link
Member

philwebb commented Oct 18, 2018

Commits 64f04fc and 6cc272e changed resourceUrlEncodingFilter from a concrete bean of type ResourceUrlEncodingFilter to a FilterRegistrationBean. The @ConditionalOnMissingBean doesn't check generics so it now matches when any other FilterRegistrationBean exists (for example, when actuator adds one for metrics).

@philwebb
Copy link
Member

philwebb commented Oct 18, 2018

@iamareebjamal Until we can fix this, you can work-around the issue by adding the following to your @SpringBootApplication class:

@Bean
public FilterRegistrationBean<ResourceUrlEncodingFilter> resourceUrlEncodingFilter() {
	FilterRegistrationBean<ResourceUrlEncodingFilter> registration = new FilterRegistrationBean<>(new ResourceUrlEncodingFilter());
	registration.setDispatcherTypes(DispatcherType.REQUEST, DispatcherType.ERROR);
	return registration;
}

@philwebb philwebb added the for: team-attention An issue we'd like other members of the team to review label Oct 18, 2018
iamareebjamal added a commit to iamareebjamal/zhcet-web that referenced this issue Oct 19, 2018
iamareebjamal added a commit to zhcet-amu/zhcet-web that referenced this issue Oct 19, 2018
@bclozel
Copy link
Member

bclozel commented Oct 19, 2018

Should we reconsider #7475 ?

@wilkinsona
Copy link
Member

It looks like it. An alternative would be to use a specific bean name when checking for a missing bean, but that feels more like a workaround than a long-term solution.

@philwebb philwebb removed the for: team-attention An issue we'd like other members of the team to review label Oct 19, 2018
@philwebb
Copy link
Member

For 2.0 we can rely on @ConditionalOnBean(ResourceUrlEncodingFilter). This won't detect if the user is adding FilterRegistrationBean, but it will restore 2.0.5 functionality.

@philwebb philwebb self-assigned this Oct 22, 2018
@philwebb philwebb changed the title Resource Versioning Handler not being called if actuator starter is included Resource Versioning Handler not being called if any FilterRegistrationBean is found Oct 22, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: blocker An issue that is blocking us from releasing type: bug A general bug type: regression A regression from a previous release
Projects
None yet
Development

No branches or pull requests

5 participants