diff --git a/user-service/pom.xml b/user-service/pom.xml index d7ba613..ca69cbf 100644 --- a/user-service/pom.xml +++ b/user-service/pom.xml @@ -49,6 +49,8 @@ spring-boot-starter-json org.springframework.boot + + org.springframework spring-beans diff --git a/user-service/src/main/java/com/hp/user/service/UserServiceApplaction.java b/user-service/src/main/java/com/hp/user/service/UserServiceApplaction.java index 8195550..56e411c 100644 --- a/user-service/src/main/java/com/hp/user/service/UserServiceApplaction.java +++ b/user-service/src/main/java/com/hp/user/service/UserServiceApplaction.java @@ -1,12 +1,12 @@ package com.hp.user.service; -import cn.nyhlw.doc2swagger.springswagger2.EnableSwagger2; import org.mybatis.spring.annotation.MapperScan; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.cache.annotation.EnableCaching; +import org.springframework.context.annotation.ComponentScan; import com.alibaba.nacos.spring.context.annotation.config.NacosPropertySource; -import org.springframework.context.annotation.ComponentScan; /** * 用户服务启动类 @@ -14,11 +14,15 @@ import org.springframework.context.annotation.ComponentScan; * @since 2020/11/18 * */ -@EnableSwagger2 @MapperScan("com.hp.user.service.dao") //扫描的mapper @SpringBootApplication @NacosPropertySource(dataId = "userdatasource", autoRefreshed = true) -@ComponentScan("com.hp.user.service.config") +//不能加compentscan,加了 +@ComponentScan("com.hp.user.service.dao")//这个地方不能写错,写错的话会出现2个问题,如果写的路径扫描不到swaggerconfig那么页面会报错 +//(Unable to infer base url. This is common when using dynamic servlet registration or when the API is behind an API Gateway. +//The base url is the root of where all the swagger resources are served. For e.g. if the api is available at http://example.org/api/v2/api-docs then the base url is http://example.org/api/. Please enter the location manually: ), +//如果写的路径扫描不到controller那么页面不会有接口信息 +//所以最好不要写 public class UserServiceApplaction { public static void main(String[] args) { SpringApplication.run(UserServiceApplaction.class, args); diff --git a/user-service/src/main/java/com/hp/user/service/config/SwaggerConfig.java b/user-service/src/main/java/com/hp/user/service/config/SwaggerConfig.java index a6b2b85..f7602c1 100644 --- a/user-service/src/main/java/com/hp/user/service/config/SwaggerConfig.java +++ b/user-service/src/main/java/com/hp/user/service/config/SwaggerConfig.java @@ -1,21 +1,22 @@ package com.hp.user.service.config; -import java.util.Arrays; - -import cn.nyhlw.doc2swagger.springswagger2.EnableSwagger2; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; -import cn.nyhlw.doc2swagger.core.config.RestDocConfig; +//import cn.nyhlw.doc2swagger.springswagger2.EnableSwagger2; import springfox.documentation.builders.ApiInfoBuilder; import springfox.documentation.builders.PathSelectors; import springfox.documentation.builders.RequestHandlerSelectors; import springfox.documentation.service.ApiInfo; import springfox.documentation.spi.DocumentationType; import springfox.documentation.spring.web.plugins.Docket; +import springfox.documentation.swagger2.annotations.EnableSwagger2; +//这两个注释一定要有,没有以及EnableSwagger2依赖错误会报 +//(Unable to infer base url. This is common when using dynamic servlet registration or when the API is behind an API Gateway. +//The base url is the root of where all the swagger resources are served. For e.g. if the api is available at http://example.org/api/v2/api-docs then the base url is http://example.org/api/. Please enter the location manually: ), @Configuration -@EnableSwagger2 +@EnableSwagger2//并且这个注释要特别注意不能使用cn.nyhlw.doc2swagger.springswagger2.EnableSwagger2;一定要使用springfox.documentation.swagger2.annotations.EnableSwagger2; public class SwaggerConfig { public static final String VERSION = "1.0.0"; public static final String SWAGGER_SCAN_BASE_PACKAGE = "com.hp.user.service.controller";