我想为我的 SpringBoot 应用程序安装 SWAGER。似乎 JWT 不提供对 swagger URL 的访问权限。
我正在尝试通过 url 访问此地址 localhost:8088/swagger-ui.html
这是 SwaggerConfig 类
@EnableSwagger2
@Configuration
public class SwaggerConfig {
@Bean
public Docket productApi() {
return new Docket(DocumentationType.SWAGGER_2)
.select()
.apis(RequestHandlerSelectors.basePackage("Path.to.my.controller"))
.build();
}
}
Run Code Online (Sandbox Code Playgroud)
我也试图从链接添加 WebAppConfig与下一个内容
@Configuration
@EnableWebMvc
public class WebAppConfig extends WebMvcConfigurerAdapter {
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("swagger-ui.html").addResourceLocations("classpath:/META-INF/resources/");
registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/");
}
}
Run Code Online (Sandbox Code Playgroud)
并尝试设置忽略网址:
@Configuration
public class WebSecurityConfiguration extends WebSecurityConfigurerAdapter {
@Override
public void configure(WebSecurity web) throws Exception {
web.ignoring().antMatchers("/resources/**");
}
}
Run Code Online (Sandbox Code Playgroud)
此版本的代码从 swagger url 自动重定向到“localhost:8088/login”。但下一个返回只是空页 …
我有 Spring boot 应用程序。这适用于嵌入式服务器。我可以使用 Postman 来测试 API。
现在我想在 Tomcat 8 上部署它,我创建 root.war 文件并将maven install
其放入 Tomcat/webapps/ 我运行 tomcat 没有任何错误。但是当我使用与邮递员相同的网址时,它给我 404 未找到。
我用于两者(嵌入式和 tomcat)的 url 示例:localhost:8080/auth/registration
我尝试server.context-path在 application.properties 中设置但没有结果。
我相信问题出在项目的配置中。
这是我的 pom.xml
parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.4.3.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>io.jsonwebtoken</groupId>
<artifactId>jjwt</artifactId>
<version>0.7.0</version>
</dependency>
<dependency>
<groupId>org.apache.tika</groupId>
<artifactId>tika-core</artifactId>
<version>1.14</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.8.0</version> …Run Code Online (Sandbox Code Playgroud)