Failed to introspect annotated methods on class ..

今天在springboot中使用swagger-UI出現(xiàn)下面的錯(cuò)誤,錯(cuò)誤日志在最下面給出支救。程序在軟件中并沒有報(bào)錯(cuò),為什么一運(yùn)行就報(bào)錯(cuò)呢拷淘,缺少類文件各墨,可是明明存在呀。

然后自己看了一下源代碼启涯,由于我是把springboot發(fā)布到外部tomcat上贬堵,所有在springboot啟動(dòng)文件中繼承了SpringBootServletInitializer恃轩,所有是不是因?yàn)镾pringBootServletInitializer的原因,導(dǎo)致swagger沒有加載呢扁瓢。

根據(jù)這個(gè)思路详恼,我把代碼調(diào)整如下:

 <!-- Swagger -->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.4.0</version>
</dependency>

<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.4.0</version>
</dependency>

Application.class

import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.context.web.SpringBootServletInitializer;
import org.springframework.context.annotation.Configuration;

@Configuration
@SpringBootApplication
public class Application extends SpringBootServletInitializer {

     @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
    return application.sources(Swagger.class);
    }
}

Swagger.class

import org.springframework.boot.SpringApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.context.request.async.DeferredResult;

import springfox.documentation.builders.PathSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

@Configuration
@EnableSwagger2
public class Swagger{

public static void main(String[] args) {
SpringApplication.run(Swagger.class, args);
}
@Bean
public Docket testApi() {
return new Docket(DocumentationType.SWAGGER_2)
.groupName("test")
.genericModelSubstitutes(DeferredResult.class)
//.genericModelSubstitutes(ResponseEntity.class)
.useDefaultResponseMessages(false)
.forCodeGeneration(true)
.pathMapping("/test")//api測(cè)試請(qǐng)求地址
.select()
.paths(PathSelectors.regex("/common/.*"))//過濾的接口
.build()
.apiInfo(testApiInfo());
}


@Bean
public Docket demoApi() {
return new Docket(DocumentationType.SWAGGER_2)
.groupName("demo")
.genericModelSubstitutes(DeferredResult.class)
//  .genericModelSubstitutes(ResponseEntity.class)
.useDefaultResponseMessages(false)
.forCodeGeneration(false)
.pathMapping("/")
.select()
.paths(PathSelectors.regex("/comm.*"))//過濾的接口
.build()
.apiInfo(demoApiInfo());
}

private ApiInfo testApiInfo() {
Contact contact = new Contact("王念", "http://my.oschina.net/wangnian", "2251181679@qq.com");
ApiInfo apiInfo = new ApiInfo("某API接口",//大標(biāo)題
"REST風(fēng)格API",//小標(biāo)題
"0.1",//版本
"www.baidu.com",
contact,//作者
"主頁(yè)",//鏈接顯示文字
""http://網(wǎng)站鏈接
);
return apiInfo;
}

private ApiInfo demoApiInfo() {
Contact contact = new Contact("王念", "http://my.oschina.net/wangnian", "2251181679@qq.com");
ApiInfo apiInfo = new ApiInfo("某API接口",//大標(biāo)題
"REST風(fēng)格API",//小標(biāo)題
"0.1",//版本
"www.baidu.com",
contact,//作者
"主頁(yè)",//鏈接顯示文字
""http://網(wǎng)站鏈接
);
return apiInfo;
}
}

然后。引几。還是報(bào)錯(cuò)昧互。后來查了一下,有的說需要在pom文件中添加下面代碼:

 <dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
</dependency>

結(jié)果還是報(bào)錯(cuò)

后經(jīng)過多次派出伟桅,發(fā)現(xiàn)是類引入出現(xiàn)問題敞掘,去掉下面引入進(jìn)正確了:

<!-- https://mvnrepository.com/artifact/xml-apis/xml-apis -->
<dependency>
<groupId>xml-apis</groupId>
<artifactId>xml-apis</artifactId>
<version>1.0.b2</version>
</dependency>

下面給出報(bào)錯(cuò)日志:

  .   ____  ___ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::(v1.3.1.RELEASE)

2016-09-23 09:16:27.134  INFO 4788 --- [ost-startStop-1] com.ilex.jiutou.Application  : Starting Application on XHJ4XGJHX0LDDYM with PID 4788 (Z:\zhaolixiang\java\javaweb\software\apache-tomcat-7.0.69\webapps\www.jiutouxiang.com\WEB-INF\classes started by Administrator in Z:\zhaolixiang\java\javaweb\software\apache-tomcat-7.0.69\bin)
2016-09-23 09:16:27.141  INFO 4788 --- [ost-startStop-1] com.ilex.jiutou.Application  : No active profile set, falling back to default profiles: default
2016-09-23 09:16:27.520  INFO 4788 --- [ost-startStop-1] ationConfigEmbeddedWebApplicationContext : Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@bf16099: startup date [Fri Sep 23 09:16:27 CST 2016]; root of context hierarchy
2016-09-23 09:16:28.272  WARN 4788 --- [ost-startStop-1] ationConfigEmbeddedWebApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanDefinitionStoreException: Failed to parse configuration class [com.ilex.jiutou.Application]; nested exception is java.lang.IllegalStateException: Failed to introspect annotated methods on class com.ilex.jiutou.Application
2016-09-23 09:16:28.283 ERROR 4788 --- [ost-startStop-1] o.s.boot.SpringApplication   : Application startup failed

org.springframework.beans.factory.BeanDefinitionStoreException: Failed to parse configuration class [com.ilex.jiutou.Application]; nested exception is java.lang.IllegalStateException: Failed to introspect annotated methods on class com.ilex.jiutou.Application
    at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:181) ~[spring-context-4.2.4.RELEASE.jar:4.2.4.RELEASE]
    at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:321) ~[spring-context-4.2.4.RELEASE.jar:4.2.4.RELEASE]
    at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:243) ~[spring-context-4.2.4.RELEASE.jar:4.2.4.RELEASE]
    at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:273) ~[spring-context-4.2.4.RELEASE.jar:4.2.4.RELEASE]
    at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:98) ~[spring-context-4.2.4.RELEASE.jar:4.2.4.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:678) ~[spring-context-4.2.4.RELEASE.jar:4.2.4.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:520) ~[spring-context-4.2.4.RELEASE.jar:4.2.4.RELEASE]
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:118) ~[spring-boot-1.3.1.RELEASE.jar:1.3.1.RELEASE]
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:764) ~[spring-boot-1.3.1.RELEASE.jar:1.3.1.RELEASE]
    at org.springframework.boot.SpringApplication.doRun(SpringApplication.java:357) ~[spring-boot-1.3.1.RELEASE.jar:1.3.1.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:305) ~[spring-boot-1.3.1.RELEASE.jar:1.3.1.RELEASE]
    at org.springframework.boot.context.web.SpringBootServletInitializer.run(SpringBootServletInitializer.java:149) [spring-boot-1.3.1.RELEASE.jar:1.3.1.RELEASE]
    at org.springframework.boot.context.web.SpringBootServletInitializer.createRootApplicationContext(SpringBootServletInitializer.java:129) [spring-boot-1.3.1.RELEASE.jar:1.3.1.RELEASE]
    at org.springframework.boot.context.web.SpringBootServletInitializer.onStartup(SpringBootServletInitializer.java:85) [spring-boot-1.3.1.RELEASE.jar:1.3.1.RELEASE]
    at org.springframework.web.SpringServletContainerInitializer.onStartup(SpringServletContainerInitializer.java:175) [spring-web-4.2.4.RELEASE.jar:4.2.4.RELEASE]
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5573) [catalina.jar:7.0.69]
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:147) [catalina.jar:7.0.69]
    at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:899) [catalina.jar:7.0.69]
    at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:875) [catalina.jar:7.0.69]
    at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:652) [catalina.jar:7.0.69]
    at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:1260) [catalina.jar:7.0.69]
    at org.apache.catalina.startup.HostConfig$DeployDirectory.run(HostConfig.java:2002) [catalina.jar:7.0.69]
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [na:1.8.0_20]
    at java.util.concurrent.FutureTask.run(FutureTask.java:266) [na:1.8.0_20]
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [na:1.8.0_20]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [na:1.8.0_20]
    at java.lang.Thread.run(Thread.java:745) [na:1.8.0_20]
Caused by: java.lang.IllegalStateException: Failed to introspect annotated methods on class com.ilex.jiutou.Application
    at org.springframework.core.type.StandardAnnotationMetadata.getAnnotatedMethods(StandardAnnotationMetadata.java:163) ~[spring-core-4.2.4.RELEASE.jar:4.2.4.RELEASE]
    at org.springframework.context.annotation.ConfigurationClassParser.doProcessConfigurationClass(ConfigurationClassParser.java:291) ~[spring-context-4.2.4.RELEASE.jar:4.2.4.RELEASE]
    at org.springframework.context.annotation.ConfigurationClassParser.processConfigurationClass(ConfigurationClassParser.java:231) ~[spring-context-4.2.4.RELEASE.jar:4.2.4.RELEASE]
    at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:198) ~[spring-context-4.2.4.RELEASE.jar:4.2.4.RELEASE]
    at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:167) ~[spring-context-4.2.4.RELEASE.jar:4.2.4.RELEASE]
    ... 26 common frames omitted
Caused by: java.lang.NoClassDefFoundError: springfox/documentation/spring/web/plugins/Docket
    at java.lang.Class.getDeclaredMethods0(Native Method) ~[na:1.8.0_20]
    at java.lang.Class.privateGetDeclaredMethods(Class.java:2688) ~[na:1.8.0_20]
    at java.lang.Class.getDeclaredMethods(Class.java:1962) ~[na:1.8.0_20]
    at org.springframework.core.type.StandardAnnotationMetadata.getAnnotatedMethods(StandardAnnotationMetadata.java:152) ~[spring-core-4.2.4.RELEASE.jar:4.2.4.RELEASE]
    ... 30 common frames omitted
Caused by: java.lang.ClassNotFoundException: springfox.documentation.spring.web.plugins.Docket
    at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1858) ~[catalina.jar:7.0.69]
    at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1701) ~[catalina.jar:7.0.69]
    ... 34 common frames omitted
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個(gè)濱河市楣铁,隨后出現(xiàn)的幾起案子玖雁,更是在濱河造成了極大的恐慌,老刑警劉巖盖腕,帶你破解...
    沈念sama閱讀 222,183評(píng)論 6 516
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件赫冬,死亡現(xiàn)場(chǎng)離奇詭異,居然都是意外死亡溃列,警方通過查閱死者的電腦和手機(jī)劲厌,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 94,850評(píng)論 3 399
  • 文/潘曉璐 我一進(jìn)店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來听隐,“玉大人补鼻,你說我怎么就攤上這事雅任》绶叮” “怎么了?”我有些...
    開封第一講書人閱讀 168,766評(píng)論 0 361
  • 文/不壞的土叔 我叫張陵沪么,是天一觀的道長(zhǎng)硼婿。 經(jīng)常有香客問我,道長(zhǎng)禽车,這世上最難降的妖魔是什么加酵? 我笑而不...
    開封第一講書人閱讀 59,854評(píng)論 1 299
  • 正文 為了忘掉前任,我火速辦了婚禮哭当,結(jié)果婚禮上猪腕,老公的妹妹穿的比我還像新娘。我一直安慰自己钦勘,他們只是感情好陋葡,可當(dāng)我...
    茶點(diǎn)故事閱讀 68,871評(píng)論 6 398
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著彻采,像睡著了一般腐缤。 火紅的嫁衣襯著肌膚如雪捌归。 梳的紋絲不亂的頭發(fā)上,一...
    開封第一講書人閱讀 52,457評(píng)論 1 311
  • 那天岭粤,我揣著相機(jī)與錄音惜索,去河邊找鬼。 笑死剃浇,一個(gè)胖子當(dāng)著我的面吹牛巾兆,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播虎囚,決...
    沈念sama閱讀 40,999評(píng)論 3 422
  • 文/蒼蘭香墨 我猛地睜開眼角塑,長(zhǎng)吁一口氣:“原來是場(chǎng)噩夢(mèng)啊……” “哼!你這毒婦竟也來了淘讥?” 一聲冷哼從身側(cè)響起圃伶,我...
    開封第一講書人閱讀 39,914評(píng)論 0 277
  • 序言:老撾萬(wàn)榮一對(duì)情侶失蹤,失蹤者是張志新(化名)和其女友劉穎蒲列,沒想到半個(gè)月后窒朋,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體,經(jīng)...
    沈念sama閱讀 46,465評(píng)論 1 319
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡蝗岖,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 38,543評(píng)論 3 342
  • 正文 我和宋清朗相戀三年侥猩,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片剪侮。...
    茶點(diǎn)故事閱讀 40,675評(píng)論 1 353
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡拭宁,死狀恐怖洛退,靈堂內(nèi)的尸體忽然破棺而出瓣俯,到底是詐尸還是另有隱情,我是刑警寧澤兵怯,帶...
    沈念sama閱讀 36,354評(píng)論 5 351
  • 正文 年R本政府宣布彩匕,位于F島的核電站,受9級(jí)特大地震影響媒区,放射性物質(zhì)發(fā)生泄漏驼仪。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 42,029評(píng)論 3 335
  • 文/蒙蒙 一袜漩、第九天 我趴在偏房一處隱蔽的房頂上張望绪爸。 院中可真熱鬧,春花似錦宙攻、人聲如沸奠货。這莊子的主人今日做“春日...
    開封第一講書人閱讀 32,514評(píng)論 0 25
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽(yáng)递惋。三九已至柔滔,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間萍虽,已是汗流浹背睛廊。 一陣腳步聲響...
    開封第一講書人閱讀 33,616評(píng)論 1 274
  • 我被黑心中介騙來泰國(guó)打工, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留杉编,地道東北人超全。 一個(gè)月前我還...
    沈念sama閱讀 49,091評(píng)論 3 378
  • 正文 我出身青樓,卻偏偏與公主長(zhǎng)得像王财,于是被迫代替她去往敵國(guó)和親卵迂。 傳聞我的和親對(duì)象是個(gè)殘疾皇子,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 45,685評(píng)論 2 360

推薦閱讀更多精彩內(nèi)容

  • Spring Cloud為開發(fā)人員提供了快速構(gòu)建分布式系統(tǒng)中一些常見模式的工具(例如配置管理绒净,服務(wù)發(fā)現(xiàn)见咒,斷路器,智...
    卡卡羅2017閱讀 134,707評(píng)論 18 139
  • 《Spring Boot開發(fā):從0到1》 大綱結(jié)構(gòu)v2.0 第一部分Spring Boot基礎(chǔ) 第1章 Sprin...
    光劍書架上的書閱讀 10,965評(píng)論 1 70
  • Android 自定義View的各種姿勢(shì)1 Activity的顯示之ViewRootImpl詳解 Activity...
    passiontim閱讀 172,304評(píng)論 25 707
  • 大家晚上好呀挂疆,歡迎和我一起PPT每日一學(xué)一操作改览。我們先回顧一下昨天的學(xué)習(xí)內(nèi)容吧!PPT學(xué)習(xí)04_如何簡(jiǎn)單處理放大后...
    徐胥閱讀 775評(píng)論 0 4
  • 兒子告訴我說缤言,小狗晚上在我們家門口的地墊上睡覺宝当。 深夜我打開門,果然看見門口的小狗向樓下走去胆萧。 這條小狗來到小區(qū)我...
    田峰閱讀 192評(píng)論 0 0