基于springCloud微服务架构的电商项目(第二天)

一、子项目集成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

 

 

 

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值