首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Springfox类型的javax.servlet.http.HttpServletRequest不存在

Springfox类型的javax.servlet.http.HttpServletRequest不存在
EN

Stack Overflow用户
提问于 2022-03-20 18:42:18
回答 1查看 1.8K关注 0票数 2

我正在尝试使用SpringFox。

Spring版本:‘org.SpringFrawork.boot:3.0.0-快照’

build.gradle

代码语言:javascript
运行
复制
dependencies {
...
  implementation 'io.springfox:springfox-petstore:2.10.5'
  implementation "io.springfox:springfox-swagger2:3.0.0"
  implementation "io.springfox:springfox-oas:3.0.0"
  implementation 'io.springfox:springfox-swagger-ui:3.0.0'
...
}

弹簧启动级

代码语言:javascript
运行
复制
@SpringBootApplication
@EnableSwagger2
@EnableOpenApi
public class ServiceApplication {
    public static void main(String[] args) {
        SpringApplication.run(ServiceApplication.class, args);
    }
}

SwaggerUiWebMvcConfigurer

代码语言:javascript
运行
复制
@Component
public class SwaggerUiWebMvcConfigurer implements WebMvcConfigurer {
    private final String baseUrl;

    public SwaggerUiWebMvcConfigurer(
        @Value("${springfox.documentation.swagger-ui.base-url:}") String baseUrl) {
        this.baseUrl = baseUrl;
    }

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        String baseUrl = StringUtils.trimTrailingCharacter(this.baseUrl, '/');
        registry.
            addResourceHandler(baseUrl + "/swagger-ui/**")
            .addResourceLocations("classpath:/META-INF/resources/webjars/springfox-swagger-ui/")
            .resourceChain(false);
    }

    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
        registry.addViewController(baseUrl + "/swagger-ui/")
            .setViewName("forward:" + baseUrl + "/swagger-ui/index.html");
    }
}

SwaggerConfig

代码语言:javascript
运行
复制
@Configuration
public class SwaggerConfig {
    @Bean
    public Docket petApi() {
        return new Docket(DocumentationType.SWAGGER_2)
            .groupName("full-petstore-api")
            .apiInfo(apiInfo())
            .select()
            .paths(any())
            .build();
    }

    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
            .title("API")
            .description("Service API")
            .termsOfServiceUrl("http://springfox.io")
            .contact(new Contact("springfox", "", ""))
            .license("Apache License Version 2.0")
            .licenseUrl("https://github.com/springfox/springfox/blob/master/LICENSE")
            .version("2.0")
            .build();
    }
}

SecurityConfig

代码语言:javascript
运行
复制
@Configuration
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {
    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http.authorizeRequests().anyRequest().anonymous().and().csrf().csrfTokenRepository(CookieCsrfTokenRepository.withHttpOnlyFalse());
    }
}

当我启动任务'bootRun‘时,我会得到一个错误:

代码语言:javascript
运行
复制
[  restartedMain] o.s.boot.SpringApplication: Application run failed

java.lang.TypeNotPresentException: Type javax.servlet.http.HttpServletRequest not present
    at java.base/sun.reflect.generics.factory.CoreReflectionFactory.makeNamedType(CoreReflectionFactory.java:117) ~[na:na]
    at java.base/sun.reflect.generics.visitor.Reifier.visitClassTypeSignature(Reifier.java:125) ~[na:na]
...

Deprecated Gradle features were used in this build, making it incompatible with Gradle 8.0.

Caused by: java.lang.ClassNotFoundException: javax.servlet.http.HttpServletRequest

我尝试使用SpringFox演示项目示例和SpringFox,但每次都会遇到这个错误。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-03-21 07:08:22

SpringBoot3.0是为Java17和JakartaEE构建的,而不是 JavaEE。Spring 3还在开发中,还没有最终发布。目前还没有正式的发布日期,但预计不会比2022年的Q4更早发布。在此之前,我不会考虑Spring 3的生产(或者当他们开始发布候选版本时)。

尽管如此,目前还没有支持SpringFox的JakartaEE版本,因此无法在SpringFox 3中使用(参见)。因此,在解决这个问题之前,SpringFox和SpringFox 3的结合是行不通的。

使用2.6.x (目前这是Spring的最新版本)。

票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/71549614

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档