Parameter 0 of constructor in springfox.documentation.spring.data.rest.EntityServicesProvider required a bean of type 'javax.servlet.ServletContext' that could not be found.
See original GitHub issueFrom a few days ago to now, the following error starts to happen.
Parameter 0 of constructor in springfox.documentation.spring.data.rest.EntityServicesProvider required a bean of type ‘javax.servlet.ServletContext’ that could not be found.
The problem occurs mainly because here, in my company, we have a common module that is responsible for including a few libraries. This module is used by both Web SpringBoot Applications and Non-Web SpringBoot Applications.
I’ve have validated that the EntityServicesProvider is always created even if it’s not a Web Application Project. Of course, because it is being included by the dependency imported by the common module. For sure, I could exclude the Springfox lib using Maven, but why not conditionate the SpringDataRestConfiguration to the @ConditionalOnWebApplication???
Just an Idea.
SpringDataRestConfiguration is working correctly because RepositoryRestConfiguration it’s being imported by the common module. Imagine the following situation: (a) my-application (there are a lot of (a) apps) imports (b) my-common, which also imports © a bunch of libraries, including spring-data-jpa, spring-data-rest, … and also, springfox-*. This common is a module used to concentrate the most used libraries in one place. All other applications import it to make things easier concerning dependency management. Almost all applications are a Web Application, but a little number of them are Non-Web. In this case, we start the application with:
new SpringApplicationBuilder(Application.class).web(WebApplicationType.NONE).run(args);
RepositoryRestConfiguration is in the Classpath but it is not being created because is a Non-Web application, although SpringDataRestConfiguration is still being loaded. Even in a Non-Web environment.
About the common. Don’t judge me. It isn’t my idea hehehe! This problem starts to happen a few days ago. I’ve been used version 3.0.0-SANPSHOT since the beginning of the year.
There is a project attached showing the error.
The solution could be: sample-springfox.zip
@Configuration
@ComponentScan(
basePackages = {"springfox.documentation.spring.data.rest"}
)
@Incubating("2.5.0")
@ConditionalOnWebApplication
@ConditionalOnClass({RepositoryRestConfiguration.class})
public class SpringDataRestConfiguration {
...
}
Issue Analytics
- State:
- Created 3 years ago
- Comments:7 (3 by maintainers)
Top GitHub Comments
Heyyy, it’s working 😉 Thanks for everything
That helped fixing it. Let me know how that works for you!