After upgrading from Spring Boot 2.5.6 to Spring Boot 2.6.0, my Spring Web Flux reactive app fails to start due to my global error web exception handler.
public class GlobalErrorWebExceptionHandler extends AbstractErrorWebExceptionHandler {
@Autowired
public GlobalErrorWebExceptionHandler(ErrorAttributes errorAttributes,
WebProperties.Resources resources,
ApplicationContext applicationContext,
ServerCodecConfigurer serverCodecConfigurer) {
super(errorAttributes, resources, applicationContext);
super.setMessageWriters(serverCodecConfigurer.getWriters());
super.setMessageReaders(serverCodecConfigurer.getReaders());
}
}
Parameter 1 of constructor in io.trippay.platform.web.TripPayGlobalErrorWebExceptionHandler required a bean of type 'org.springframework.boot.autoconfigure.web.WebProperties$Resources' that could not be found.
I looked at the migration document and there are not clues to what changed or what should be done to mitigate this issue.
Thank you
Comment From: yu-shiba
I had a similar problem.
@Configuration
public class WebMvcConfig implements WebMvcConfigurer {
private static final String[] VERSION_PATTERNS = { "/plugins/**", "/img/**", "/css/**", "/js/**" };
@Autowired
Resources resources;
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
VersionResourceResolver versionResolver = new VersionResourceResolver()
.addContentVersionStrategy(VERSION_PATTERNS);
// enable fingerprint
registry.addResourceHandler("/**")
.addResourceLocations(resources)
.setCachePeriod(3600 * 24 * 30)
.resourceChain(true)
.addResolver(versionResolver);
}
}
I think there is a similar problem with Web Mvc.
Comment From: snicoll
It isn't a regression. ResourceProperties (which is the one that was bound to spring.resources) is deprecated since Spring Boot 2.4. This deprecated code was removed in 2.6 as we usually do.
The tricky thing here is that ResourceProperties extends from Resources so injecting the latter worked. If you need to access resources information, you need to inject WebProperties and access its getResources accessor. I've added a note in the release notes
Comment From: wilkinsona
I think we should improve the deprecation in 2.5.x to point people to WebProperties and then getResources() rather than just pointing them to WebProperties.Resources.
Comment From: bjornharvold
Cheers Andy 🍻
On November 21, 2021 at 20:12:51, Andy Wilkinson @.***) wrote:
Reopened #28762 https://github.com/spring-projects/spring-boot/issues/28762.
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/spring-projects/spring-boot/issues/28762#event-5650003885, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAE4V74TF7TKK6H2UMTLDGTUNDV5HANCNFSM5IOTABCA .
Comment From: vedhavi
It isn't a regression.
ResourceProperties(which is the one that was bound tospring.resources) is deprecated since Spring Boot 2.4. This deprecated code was removed in 2.6 as we usually do.The tricky thing here is that
ResourcePropertiesextends fromResourcesso injecting the latter worked. If you need to access resources information, you need to injectWebPropertiesand access itsgetResourcesaccessor. I've added a note in the release notes
An example would help people better. So adding to @snicoll 's comments, as some people like me will not be able to grab it at the very first instant
For instance.
.....
@Configuration
@Order(-2)
public class ExceptionHandler extends AbstractErrorWebExceptionHandler {
...
// Spring boot 2.5.7
public ExceptionHandler(ErrorAttributes errorAttributes, Resources resources,
ApplicationContext applicationContext, ServerCodecConfigurer configurer) {
super(errorAttributes, resources, applicationContext);
this.setMessageWriters(configurer.getWriters());
}
// Spring boot 2.6.0
public ExceptionHandler(ErrorAttributes errorAttributes, WebProperties webproperties,
ApplicationContext applicationContext, ServerCodecConfigurer configurer) {
super(errorAttributes, webproperties.getResources(), applicationContext);
this.setMessageWriters(configurer.getWriters());
}
Comment From: UDragon-CK
@Slf4j
@Configuration
public class NrpWebPropertiesConfiguration {
@Bean
public WebProperties.Resources resources() {
return new WebProperties.Resources();
}
}
public WebFluxGlobalExceptionHandler(ErrorAttributes errorAttributes, NrpWebPropertiesConfiguration nrpWebPropertiesConfiguration,
ApplicationContext applicationContext, ServerCodecConfigurer serverCodecConfigurer) {
super(errorAttributes, nrpWebPropertiesConfiguration.resources(), applicationContext);
super.setMessageWriters(serverCodecConfigurer.getWriters());
super.setMessageReaders(serverCodecConfigurer.getReaders());
}