一、子项目集成swagger
对于微服务架构项目而言,每个子项目需要先集成swagger,集成步骤如下:
1.添加pom依赖。
<dependency>
<groupId>com.spring4all</groupId>
<artifactId>swagger-spring-boot-starter</artifactId>
<version>1.7.0.RELEASE</version>
</dependency>
2.添加swagger相关配置
3.启动类上开启swagger注解
4.在接口上添加注解信息
5.在浏览器上直接访问http://localhost:9002/swagger-ui.html
就可以在页面上进行调试接口,非常方便。
二、集成所有子项目的swagger
创建网关子项目zuul,将所有项目的接口文档集成在一起。
1.添加需要的依赖
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-zuul</artifactId>
</dependency>
<dependency>
<groupId>com.spring4all</groupId>
<artifactId>swagger-spring-boot-starter</artifactId>
<version>1.7.0.RELEASE</version>
</dependency>
2.添加配置
3.启动类
4.访问页面http://localhost:9003/swagger-ui.html ,zuul项目的端口我设置成9003,你需要修改成自己的端口。
三、搭建一个maven私服
上传nexus包并解压,
启动nexus
cd /usr/local/nexus-3.13.0-01/bin
./nexus start
登录用户名和密码admin/admin123
四、上传本地Maven工程到私服上
因为这个项目是面向接口的,所以我们项目是需要发布到私服中去的。
首先在私服上创建一个maven仓库,创建仓库时注意仓库的类型为Release,意思是发行版。
现在我们将cgb-shop-service-api-member和cgb-shop-service-api-weixin发布到私服上,首先更改本地maven中的setting文件
<server>
<id>youxianqi</id>
<username>youxianqi</username>
<password>123456</password>
</server>
这个配置就是私服的配置嘛,很好理解,同时需要在pom文件中,指定私服的地址
<!--指定仓库地址 -->
<distributionManagement>
<repository>
<!--此名称要和.m2/settings.xml中设置的ID一致 -->
<id>youxianqi</id>
<url>http://192.168.9.7:8081/repository/youxianqi/</url>
</repository>
</distributionManagement>
<build>
<plugins>
<!--发布代码Jar插件 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.7</version>
</plugin>
<!--发布源码插件 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>2.2.1</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
注意:所有工程的版本需要改成RELEASE,不然jar包是传不上去的,因为我们的库指定了版本RELEASE,因为我们的会员服务依赖于微信服务,所以先将微信服务打包就行了。中间很多次都失败了,但是慢慢的去查原因,最终将两个jar包上传到私服中。
五、批量上传jar包到maven私服中
1.先将本地maven/repository仓库打一个完整的zip压缩包
2.上传到linux目录,如:/usr/local
3.解压repository.zip
4.进入repository目录
5.创建touch mavenimport.sh脚本,写入以下内容:
while getopts ":r:u:p:" opt; do
case $opt in
r) REPO_URL="$OPTARG"
;;
u) USERNAME="$OPTARG"
;;
p) PASSWORD="$OPTARG"
;;
esac
done
find . -type f -not -path './mavenimport\.sh*' -not -path '*/\.*' -not -path '*/\^archetype\-catalog\.xml*' -not -path '*/\^maven\-metadata\-local*\.xml' -not -path '*/\^maven\-metadata\-deployment*\.xml' | sed "s|^\./||" | xargs -I '{}' curl -u "$USERNAME:$PASSWORD" -X PUT -v -T {} ${REPO_URL}/{} ;
6.输入chmod a+x mavenimport.sh进行可执行授权
7.执行导入命令
./mavenimport.sh -u admin -p admin123 -r http://192.168.1.3:8081/repository/cgb-cma-releases/
参考博客:https://my.oschina.net/u/437309/blog/3081680