我想用春狐。
Spring Boot版本:"组织.Spring框架.启动:3.0.0-快照"
- 构建分级 *
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'
...
}
- Spring Boot类 *
@SpringBootApplication
@EnableSwagger2
@EnableOpenApi
public class ServiceApplication {
public static void main(String[] args) {
SpringApplication.run(ServiceApplication.class, args);
}
}
- Swagger UI网络管理配置器 *
@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");
}
}
- Swagger 配置 *
@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();
}
}
- 安全配置 *
@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'时,我收到一个错误:
[ 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-Boot,但每次都出现这个错误。
2条答案
按热度按时间3pmvbmvn1#
Sping Boot 3.0是为Java17和JakartaEE构建的,不是JavaEE。Spring Boot 3仍在开发中,还没有看到最终版本。还没有正式发布日期,但预计不会早于2022年第四季度。在那之前,我不会考虑Spring Boot 3的生产(或者当他们开始发布Release Candidate时)。
也就是说,目前没有支持JakartaEE的SpringFox版本,因此无法与Sping Boot 3一起使用(参见this)。因此,在这个问题得到解决之前,SpringFox和Spring Boot 3的组合将无法工作。
使用2.6.x(目前是Sping Boot 的最新发布版本)。
2g32fytz2#
只需将此依赖项添加到pom.xml中
https://mvnrepository.com/artifact/javax.servlet/javax.servlet-api
如有必要,还可将该属性添加到www.example.com中application.properties
第一个月
来源:Failed to start bean 'documentationPluginsBootstrapper' in spring data rest