spring-cloud / spring-cloud-commons

Common classes used in different Spring Cloud implementations
Apache License 2.0
708 stars 704 forks source link

Spring boot 3.0 fail with jersey and spring cloud (open feign, ect) #1295

Closed OlgaMaciaszek closed 1 year ago

OlgaMaciaszek commented 1 year ago

@Fyro-Ing commented on Tue Mar 14 2023

When using Spring boot 3.0 with jersey (not mvc) with spring cloud open feign, start failed

org.springframework.beans.factory.BeanDefinitionStoreException: Failed to process import candidates for configuration class [com.fortuneo.api.esign.Application]: class path resource [org/springframework/web/servlet/config/annotation/WebMvcConfigurer.class] cannot be opened because it does not exist
    at org.springframework.context.annotation.ConfigurationClassParser.processImports(ConfigurationClassParser.java:524)
    at org.springframework.context.annotation.ConfigurationClassParser$DeferredImportSelectorGroupingHandler.lambda$processGroupImports$1(ConfigurationClassParser.java:726)
    at java.base/java.lang.Iterable.forEach(Iterable.java:75)
    at ...
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:732)
    at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:434)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:310)
    at org.springframework.boot.builder.SpringApplicationBuilder.run(SpringApplicationBuilder.java:150)
    at com.fortuneo.api.esign.Application.main(Application.java:18)
Caused by: java.io.FileNotFoundException: class path resource [org/springframework/web/servlet/config/annotation/WebMvcConfigurer.class] cannot be opened because it does not exist
    at org.springframework.core.io.ClassPathResource.getInputStream(ClassPathResource.java:211)
    at org.springframework.core.type.classreading.SimpleMetadataReader.getClassReader(SimpleMetadataReader.java:54)
    at org.springframework.core.type.classreading.SimpleMetadataReader.<init>(SimpleMetadataReader.java:48)
    at ...

Spring cloud open feign include org.springframework.cloud:spring-cloud-commons with a default config for web mvc

https://github.com/spring-cloud/spring-cloud-commons/blob/8ec45e03b00f3ad96bbc03a86390ed029364bb89/spring-cloud-commons/src/main/java/org/springframework/cloud/commons/security/ResourceServerTokenRelayAutoConfiguration.java#L58

To reproduce : run starter

https://start.spring.io/#!type=gradle-project&language=java&platformVersion=3.0.4&packaging=jar&jvmVersion=17&groupId=com.example&artifactId=demo&name=demo&description=Demo%20project%20for%20Spring%20Boot&packageName=com.example.demo&dependencies=lombok,cloud-feign,jersey

Workaround : set "spring.cloud.mvc.token-relay.enabled" at false

gbzarelli commented 1 year ago

I went through the same problem when I updated my project to spring boot 3 (PR).

The workaround worked for me, thanks.

rob-valor commented 1 year ago

@OlgaMaciaszek Any progress on this issue?

I'm not sure it is correct to move the issue here. ResourceServerTokenRelayAutoConfiguration is, looking at the property, mvc oriented and depends on classes from web-mvc (like WebMvcConfigurer) but is only checking for GenericWebApplicationContext (web) through the ConditionalOnWebApplication. For me, it seems better that ResourceServerTokenRelayAutoConfiguration has also a @ConditionalOnClass(WebMvcConfigurer.class) to ensure that there is indeed a web-mvc classpath present.

Now, looking at what is in that ResourceServerTokenRelayAutoConfiguration class..., it doesn't seems to do anything useful. All the code that could do any useful work is commented out :open_mouth: :thinking: :wink:

Adding that additional class check could fix the issue and being such a small fix, can be included in the upcoming release. We are currently upgrading our internal libraries to Spring Boot 3.x and also facing the missing class issue :disappointed:

OlgaMaciaszek commented 1 year ago

Looking into it now.

OlgaMaciaszek commented 1 year ago

This is a bug in Commons. Moving it there. Will provide a fix.