Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/spring-boot/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Amazon web services Springboot:AWS中未正确显示Swagger UI格式_Amazon Web Services_Spring Boot_Swagger - Fatal编程技术网

Amazon web services Springboot:AWS中未正确显示Swagger UI格式

Amazon web services Springboot:AWS中未正确显示Swagger UI格式,amazon-web-services,spring-boot,swagger,Amazon Web Services,Spring Boot,Swagger,我有一个简单的spring启动应用程序,它有两个控制器echo controller和trac controller。我想为这些服务端点提供一个api文档。我正在尝试使用spring boot版本的swagger ui 2.6.1

我有一个简单的spring启动应用程序,它有两个控制器echo controller和trac controller。我想为这些服务端点提供一个api文档。我正在尝试使用spring boot版本的swagger ui 2.6.11.5.2.RELEASE

pom.xml
文件中,我添加了这些依赖项

伊奥·斯普林福克斯
springfox招摇过市用户界面
2.6.1
编译
org.springframework.security
spring安全配置
4.0.1.1发布
org.springframework.security
spring安全网
4.0.1.1发布
下面是我的回声控制器
@控制器
公共类EchoController{
@ApiOperation(value=“测试回显服务”,response=ResponseEntity.class)
@API响应(值)={
@ApiResponse(代码=200,消息=“检索到测试回显服务”,响应=ResponseEntity.class),
@ApiResponse(代码=500,message=“内部服务器错误”),
@ApiResponse(代码=404,消息=“未找到测试回显服务”)
})
@RequestMapping(value=“/echo/{any}”,method=RequestMethod.GET)
@应答器
公共字符串回显(@PathVariable(“any”)字符串any){
退回任何文件;
}
}
我对trac控制器端点也有类似的注释。
下面是我的招摇过市配置文件
@配置
@使能招摇过市2
公共类SwaggerConfig{
@豆子
公共卷宗生产API(){
返回新摘要(DocumentationType.SWAGGER_2)
.apinfo(apinfo())
.选择()
.api(RequestHandlerSelectors.basePackage(“com.demo.applications.trac.controller”))
.path(路径选择器.any())
.build();
}
//描述API
私有apinfo apinfo(){
返回新的ApiInfoBuilder()
.title(“TRAC微服务Rest API”)
.description(“此页面列出了TRAC MicroService的所有rest API。”)
.版本(“1.0-SNAPSHOT”)
.build();
}
}
下面是一个安全配置
@配置
类SecurityConfig扩展了WebSecurity配置适配器{
私有静态最终字符串[]身份验证白名单={
//--大摇大摆的用户界面
“/swagger resources/**”,
“/swagger ui.html”,
“/v2/api文档”,
“/configuration/ui”,
“/swagger resources/configuration/ui”,
“/swagger resources/configuration/security”,
“/configuration/security”,
“/webjars/**”,
“/swagger.json”,
“/csrf”,
“/webjars/springfox-swagger用户界面”,
“/webjars/springfox-swagger-ui/css”,
“/webjars/springfox-swagger-ui/images”,
“/echo/**”,
“/trac服务/**”
};
@凌驾
受保护的无效配置(HttpSecurity http)引发异常{
http.authorizeRequests()
.antMatchers(AUTH_白名单).permitAll()
.antMatchers(“/***”).denyAll();
}
@凌驾
public void configure(WebSecurity web)引发异常{
忽略().antMatchers(“/v2/api docs”、“/configuration/ui”、“/swagger resources”、“/configuration/security”、“/swagger ui.html”、“/webjars/**”、“/webjars/springfox swagger ui/css”、“/webjars/springfox swagger ui/images”);
}
}
大摇大摆的用户界面在本地(http)中正确显示

但是当我在AWS(https)中部署它时,html格式就消失了。我尝试了很多方法,但都不明白为什么html格式会在AWS中消失


从屏幕截图上看,您的CSS/JS似乎没有加载。请检查您的浏览器日志,查看用于发出请求的URL,并设置httpSecurity以允许加载与您现有安全角色类似的资源

还要确保以下事项

1.swagger的配置如下所示

@Configuration
@EnableWebSecurity
@EnableWebMvcSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {
    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http
            .authorizeRequests()
            .antMatchers("/v2/api-docs", "/swagger-resources/**", "/webjars/**", "/swagger-ui.html")
            .permitAll();
    }
}

2.尝试清理Chrome Web浏览器缓存。

当您点击时,是否所有内容都正确显示?请根据您的配置调整此url。另外,您是部署到AWS中的Elastic BeanStalk,还是正在自己的应用服务器/servlet容器上运行EC2实例?@Arun Patra,当我点击本地时,所有内容都显示正确。我正在部署到EC2实例。我使用的是docker文件。你能使用chrome中的inspect功能,并尝试找出浏览器无法下载的资源吗?你是对的,CSS/JS没有加载所有的CSS都无法加载。下面是来自浏览器的控制台输出,资源被解释为样式表,但使用MIME类型的应用程序/八位字节流传输:请参阅和
@Configuration
@EnableWebSecurity
@EnableWebMvcSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {
    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http
            .authorizeRequests()
            .antMatchers("/v2/api-docs", "/swagger-resources/**", "/webjars/**", "/swagger-ui.html")
            .permitAll();
    }
}