1、pom
<dependency>
<groupId>com.spring4all</groupId>
<artifactId>swagger-spring-boot-starter</artifactId>
<version>2.0.2.RELEASE</version>
</dependency>
2、配置文件中加入一行
spring.mvc.pathmatch.matching-strategy=ant_path_matcher
如果不加入,运行会报错
Failed to start bean 'documentationPluginsBootstrapper'; nested exception is java.lang.NullPointerException: Cannot invoke "org.springframework.web.servlet.mvc.condition.PatternsRequestCondition.getPatterns()" because "this.condition" is null
3、启动类
@SpringBootApplication(scanBasePackages = {"需要扫描的包","com.spring4all.swagger"})
public class SwaggerMpApplication {
public static void main(String[] args) {
SpringApplication.run(SwaggerMpApplication.class, args);
}
}
4、controller
@RestController
public class HelloController {
@ApiOperation("这是hello接口")
@GetMapping("/hello")
public String hello(){
return "hello";
}
}