ITPub博客

首页 > 应用开发 > Java > java版spring cloud+spring boot+redis多租户社交电子商务平台

java版spring cloud+spring boot+redis多租户社交电子商务平台

原创 Java 作者:server77 时间:2019-09-20 17:45:01 0 删除 编辑

我们针对于HongHu cloud的eureka项目做以下构建,整个构建的过程很简单,我会将每一步都构建过程记录下来,希望可以帮助到大家:

1. 创建一个名为particle-common-eureka的maven项目,继承particle-commonservice,具体的pom.xml配置文件如下:

 

Xml代码   收藏代码
  1. <? xml   version = "1.0"   encoding = "UTF-8" ?>   
  2. < project   xmlns = "http://maven.apache.org/POM/4.0.0"   xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance"   
  3.      xsi:schemaLocation = "http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" >   
  4.      < modelVersion > 4.0.0 </ modelVersion >   
  5.   
  6.      < parent >   
  7.          < groupId > com.ml.honghu </ groupId >   
  8.          < artifactId > particle-commonservice </ artifactId >   
  9.          < version > 0.0.1-SNAPSHOT </ version >   
  10.      </ parent >   
  11.   
  12.      < artifactId > particle-commonservice-eureka </ artifactId >   
  13.      < packaging > jar </ packaging >   
  14.   
  15.      < name > particle-commonservice-eureka </ name >   
  16.      < description > particle-commonservice project for Spring Boot </ description >   
  17.   
  18.      < dependencies >   
  19.          < dependency >   
  20.              < groupId > org.springframework.cloud </ groupId >   
  21.              < artifactId > spring-cloud-starter-eureka-server </ artifactId >   
  22.          </ dependency >   
  23.          < dependency >   
  24.              < groupId > org.springframework.boot </ groupId >   
  25.              < artifactId > spring-boot-starter-security </ artifactId >   
  26.          </ dependency >   
  27.          < dependency >   
  28.              < groupId > org.springframework.boot </ groupId >   
  29.              < artifactId > spring-boot-devtools </ artifactId >   
  30.          </ dependency >   
  31.           
  32.          < dependency >   
  33.              < groupId > org.springframework.boot </ groupId >   
  34.              < artifactId > spring-boot-starter-test </ artifactId >   
  35.              < scope > test </ scope >   
  36.          </ dependency >   
  37.   
  38.      </ dependencies >   
  39.   
  40.      < build >   
  41.          < plugins >   
  42.              < plugin >   
  43.                  < groupId > org.springframework.boot </ groupId >   
  44.                  < artifactId > spring-boot-maven-plugin </ artifactId >   
  45.                  < executions >   
  46.                      < execution >   
  47.                          < id > 1 </ id >   
  48.                          < goals >   
  49.                              < goal > repackage </ goal >   
  50.                          </ goals >   
  51.                      </ execution >   
  52.                      < execution >   
  53.                          < id > 2 </ id >   
  54.                          < goals >   
  55.                              < goal > build-info </ goal >   
  56.                          </ goals >   
  57.                      </ execution >   
  58.                  </ executions >   
  59.                  < configuration >   
  60.                      < executable > true </ executable >   
  61.                  </ configuration >   
  62.                   
  63.              </ plugin >   
  64.          </ plugins >   
  65.      </ build >   
  66. </ project >   

 2. 在启动类入口引用eureka的相关配置,代码如下:

 

Java代码   收藏代码
  1. package  com.ml.honghu;  
  2.   
  3. import  org.springframework.boot.SpringApplication;  
  4. import  org.springframework.boot.autoconfigure.SpringBootApplication;  
  5. import  org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;  
  6.   
  7. @EnableEurekaServer   
  8. @SpringBootApplication   
  9. public   class  ServiceApplication {  
  10.   
  11.      public   static   void  main(String[] args) {  
  12.         SpringApplication.run(ServiceApplication. class , args);  
  13.     }  
  14. }  

 3. 配置application.yml文件

Xml代码   收藏代码
  1. # server (eureka 默认端口为:8761)  
  2. server:  
  3.   port: 8761  
  4.   
  5. # spring  
  6. spring:  
  7.   application:  
  8.     name: particle-commonservice-erueka  
  9.   
  10. # eureka  
  11. eureka:   
  12.   client:   
  13.     # 是否注册到eureka  
  14.     register-with-eureka: true  
  15.     # 是否从eureka获取注册信息  
  16.     fetch-registry: false  
  17.     availability-zones:   
  18.       honghu: honghuZone  
  19.     service-url:   
  20.       honghuZone: http://honghu:123456@localhost:8761/eureka/  
  21.       defaultZone: http://honghu:123456@localhost:8761/eureka/  
  22.   instance:  
  23.     prefer-ip-address: true  
  24.     hostname: localhost  
  25.     metadataMap:  
  26.       zone: honghuZone  
  27.       user: ${security.user.name}  
  28.       password: {security.user.password}  
  29.         
  30.   # 指定环境  
  31.   environment: dev  
  32.   #指定数据中心  
  33.   datacenter: honghu  
  34.   # 关闭自我保护模式  
  35.   server:   
  36.     enable-self-preservation: false  
  37.   #设置清理无效节点的时间间隔,默认60000,即是60s  
  38.     eviction-interval-timer-in-ms: 60000  
  39.   
  40. # 服务认证  
  41. security:   
  42.   basic:   
  43.     enabled: true  
  44.   user:   
  45.     name: honghu  
  46.     password: 123456  
  47.   
  48. management:  
  49.   security:  
  50.     enabled: false  

4. 增加项目的log机制和打包运行机制(后面我们会详细编写针对于Linux Centos下的打包部署机制)

5. 自此整个项目部署完成,通过手动方式进行Run As --> Spring Boot App,运行结果如下:

控制台运行结果:

 

访问控制台并登陆:

 

控制台运行效果:

从现在开始,我这边会将近期研发的spring cloud微服务云架构的搭建过程和精髓记录下来,帮助更多有兴趣研发spring cloud框架的朋友,大家来一起探讨spring cloud架构的搭建过程及如何运用于企业项目。


来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/69948899/viewspace-2657759/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2019-09-20

  • 博文量
    9
  • 访问量
    2778