最近在嘗試搭自己的個人博客,寫swagger配置類的時候總是報這個錯:
org.springframework.beans.factory.BeanDefinitionStoreException: Failed to load bean class: com.honey.Swagger.Swagger2; nested exception is java.io.FileNotFoundException: class path resource [org/springframework/boot/autoconfigure/condition/ConditionalOnWebApplication.class] cannot be opened because it does not exist
主要問題在于不知道這個conditionalOnWebApplication.class是哪一步呼叫的...編譯完的target檔案里的確沒有這個檔案(不是系統找不到是真的沒有)
另外找了很多類似的,基本都是 .property .xml這樣的檔案找不到,像我一樣報.class檔案找不到的只有一個說洗掉target檔案夾重新下載....然而我試了下也是不行。

swagger.java代碼如下:
@Configuration
@EnableSwagger2
public class Swagger2 {
@Bean
public Docket createRestApi() {
ParameterBuilder tokenPar = new ParameterBuilder();
List<Parameter> pars = new ArrayList<Parameter>();
return new Docket(DocumentationType.SWAGGER_2)
.apiInfo(apiInfo())
.select()
.apis(RequestHandlerSelectors.basePackage("com.honey.Controller"))
.paths(PathSelectors.any())
.build();
}
private ApiInfo apiInfo() {
return new ApiInfoBuilder()
.title("swagger")
.description("簡單使用swagger2")
.version("1.0")
.build();
}
}
uj5u.com熱心網友回復:
你只需要知道缺了ConditionalOnWebApplication這個類,那就檢查依賴里是否有這個類不就好了?不管哪個IDE都有根據類名查找類的功能的,如果找不到說明不在,這個類在這個依賴里.
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-autoconfigure</artifactId>
</dependency>
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/258264.html
標籤:Java相關
