先说明我遇到的情况
1、控制台直接运行永远不会出现404问题
2、打jar包有时候不会404,有时候再怎么clean打出来的包运行访问静态资源仍旧404
3、pom文件增加如下内容,当时打包没有出现404,以为问题解决了,等了几天又出现404。泪奔。。。
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>1.4.2.RELEASE</version>
<configuration>
<mainClass>com.abc.def.GuangguangApplication</mainClass>
</configuration>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
我的项目配置
1、集成了Swagger2, 如下:
@Configuration
@EnableSwagger2
public class MySwagger extends WebMvcConfigurationSupport {
@Bean
public Docket createRestApi() {
return new Docket(DocumentationType.SWAGGER_2)
.apiInfo(apiInfo())
.select()
.apis(RequestHandlerSelectors.basePackage("com.abc.def.controller"))//这里是controller所处的包名
.paths(PathSelectors.any())
.build();
}
//构建api文档的详细信息函数
private ApiInfo apiInfo() {
return new ApiInfoBuilder()
//页面标题
.title("逛逛平台API接口服务")
//描述
.description("逛逛平台API接口服务")
.termsOfServiceUrl("API terms of service")
//版本号s
.version("1.0")
.build();
}
}
2、加了序列化和反序列化操作,如下:
@Configuration
@EnableWebMvc
public class WebConfig implements WebMvcConfigurer {
@Override
public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
converters.add(0, new MappingJackson2HttpMessageConverter());
converters.add(1, new ResourceHttpMessageConverter());
}
}
最终解决方案:
把@Swagger2 和 @EnableWebMvc放到Applicatin上面去注解。问题解决。