springboot 偶尔打包出现静态资源访问404问题

先说明我遇到的情况

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上面去注解。问题解决。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值