先贴出报错信息:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'objectMapperConfigurer' defined in class path resource [springfox/documentation/spring/web/SpringfoxWebMvcConfiguration.class]: Post-processing of merged bean definition failed; nested exception is java.lang.IllegalStateException: Failed to introspect Class [springfox.documentation.spring.web.ObjectMapperConfigurer] from ClassLoader [sun.misc.Launcher$AppClassLoader@18b4aac2]
大概意思是说,嵌套异常,未找到某个类。百度后发现是swagger时候报错的。首先贴出swagger需要导入的包及版本,因为不同的版本可能导致不同的问题。
<!--swagger -->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.4.0</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.4.0</version>
</dependency>
然后贴下我的swagger的配置文件
package com.ymft.face_server.config;
import com.google.common.base.Predicates;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
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;
@EnableSwagger2
@Configuration
public class SwaggerConfig {
//是否开启swagger,正式环境一般是需要关闭的,可根据springboot的多环境配置进行设置
@Value(value = "${custom.swagger.enabled}")
Boolean swaggerEnabled;
@Bean
public Docket createRestApi() {
return new Docket(DocumentationType.SWAGGER_2).apiInfo(apiInfo())
// 是否开启
.enable(swaggerEnabled).select()
// 扫描的路径包
.apis(RequestHandlerSelectors.basePackage("face_server.controller"))
//排除某些不需要映射的路径
.paths(Predicates.not(PathSelectors.regex("/push.*")))
// 指定路径处理PathSelectors.any()代表所有的路径
.paths(PathSelectors.any())
.build().pathMapping("/");
}
private ApiInfo apiInfo() {
return new ApiInfoBuilder()
.title("人脸服务器接口")
.description("人脸服务器开放接口")
// 作者信息
.contact(new Contact("test", "http://www.baidu.com", "18666666666@163.com"))
.version("1.0.0")
.build();
}
}
顺便说下,我之前的项目就是这么配置的,可以用,没啥问题。然后就报错了。去百度,然后找到了很多说法。
比如:java包冲突,在maven中添加com.google.guava包
https://www.cnblogs.com/yuanbaodong/p/9491701.html
还有一些别的方法,都不行,然后找到这个帖子
就是去掉配置文件的@Configuration 注解,问题解决,原因的话,请大神指点