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

Improve deprecation notice on ResourceProperties to direct people to WebProperties for dependency injection and then getResources() #28762

Closed
bjornharvold opened this issue Nov 21, 2021 · 6 comments
Labels
type: documentation A documentation update
Milestone

Comments

@bjornharvold
Copy link

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

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Nov 21, 2021
@yu-shiba
Copy link

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.

@snicoll
Copy link
Member

snicoll commented Nov 21, 2021

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

@snicoll snicoll closed this as completed Nov 21, 2021
@snicoll snicoll added status: invalid An issue that we don't feel is valid and removed status: waiting-for-triage An issue we've not yet triaged labels Nov 21, 2021
@wilkinsona
Copy link
Member

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.

@wilkinsona wilkinsona reopened this Nov 21, 2021
@wilkinsona wilkinsona changed the title Regression: Spring Boot 2.6.0 - WebProperties.Resources no longer available for injection Improve deprecation notice on ResourceProperties to direct people to WebProperties for dependency injection and then getResource() Nov 21, 2021
@wilkinsona wilkinsona added type: documentation A documentation update and removed status: invalid An issue that we don't feel is valid labels Nov 21, 2021
@wilkinsona wilkinsona added this to the 2.5.x milestone Nov 21, 2021
@wilkinsona wilkinsona changed the title Improve deprecation notice on ResourceProperties to direct people to WebProperties for dependency injection and then getResource() Improve deprecation notice on ResourceProperties to direct people to WebProperties for dependency injection and then getResources() Nov 21, 2021
@bjornharvold
Copy link
Author

bjornharvold commented Nov 21, 2021 via email

@wilkinsona wilkinsona modified the milestones: 2.5.x, 2.5.8 Nov 22, 2021
@vedhavi
Copy link

vedhavi commented Nov 24, 2021

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

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());
	}

minwoox added a commit to minwoox/armeria that referenced this issue Jan 21, 2022
Motivation:
- Micrometer 1.7.6 -> 1.8.2
- Spring 5.3.13 -> 5.3.15
- Spring Boot 2.5.7 -> 2.6.2

Modifications:
- Add `WebServerNamespace` `OperationArgumentResolver`.
  - Bind additional health group to server.
- Inject `WebProperties` directly instead of `WebProperties.Resources`.
  - spring-projects/spring-boot#28762
- Use `ApiVersion.LATEST` instead of `ActuatorMediaType.V3_JSON`.
trustin pushed a commit to line/armeria that referenced this issue Jan 24, 2022
Motivation:
- Micrometer 1.7.6 -> 1.8.2
- Spring 5.3.13 -> 5.3.15
- Spring Boot 2.5.7 -> 2.6.3

Modifications:
- Add `WebServerNamespace` `OperationArgumentResolver`.
  - Bind additional health group to server.
- Inject `WebProperties` directly instead of `WebProperties.Resources`.
  - spring-projects/spring-boot#28762
- Use `ApiVersion.LATEST` instead of `ActuatorMediaType.V3_JSON`.

Result:
- You can now use Armeria with Spring Boot 2.6.3
@UDragon-CK
Copy link

UDragon-CK commented Aug 4, 2022

@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());
}

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

No branches or pull requests

7 participants