个人记录

记录公司微服务项目,模块添加的步骤

一  创建Module

选择maven

groupid和artifactid 参考 pom文件

<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<!-- 父项目 -->
<artifactId>kps.parent</artifactId>
<!-- 父项目id -->
<groupId>com.kps</groupId>
<version>1.0</version>
</parent>
<modelVersion>4.0.0</modelVersion> <!-- 项目id -->
<artifactId>kps.appAPIScan</artifactId>
<!-- 项目名 -->
<name>kps.appAPIScan</name>
<url>http://maven.apache.org</url>
<properties>
<imageName>apiscan:${project.version}</imageName>
</properties> <dependencies>
<dependency>
<groupId>com.kps</groupId>
<artifactId>kps.web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-eureka</artifactId>
</dependency>
<!--
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-netflix-eureka-client</artifactId>
</dependency>
-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-config-client</artifactId>
</dependency> <dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency> </dependencies> <!-- 打boot结构jar插件 -->
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>com.spotify</groupId>
<artifactId>docker-maven-plugin</artifactId>
<configuration>
<imageName>${imageName}</imageName>
</configuration>
</plugin>
</plugins>
</build> </project>

二  增加启动应用

这里注意,要和controller文件夹同级

代码:

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.ServletComponentScan;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.context.annotation.ComponentScan; @EnableEurekaClient // 配置本应用将使用服务注册和服务发现
@SpringBootApplication
@ComponentScan(basePackages={"com.kps"},lazyInit=true)
@ServletComponentScan(basePackages={"com.kps"})
public class AppAPIScanApp {
public static void main( String[] args )
{
SpringApplication.run(AppAPIScanApp.class, args);
}
}

PS:如果SpringApplication报错:cannot access org.springframework.core.env

那么把Module重新导入一下就好了。

三  增加配置文件

application.yml

spring:
application:
name: kps.appAPIScan server:
port: 9100 #Security authentication is enabled by default above springboot 1.5.x
management:
security:
enabled: false eureka:
client:
serviceUrl:
defaultZone: ${registry.url}
instance:
lease-expiration-duration-in-seconds: 60
lease-renewal-interval-in-seconds: 30
preferIpAddress: true
instanceId: ${spring.cloud.client.ipAddress}:${server.port}

bootstrap.yml

spring:
http:
encoding:
charset: UTF-8
enabled: true
force: true
cloud:
config:
uri: http://${host:localhost}:9089
name: config
profile: ${active:dev}

四  修改zuul网管配置

application.yml

spring:
profiles:
active: ${active:dev}
application:
name: springCloud.zuul
thymeleaf:
prefix: classpath:/templates/
suffix: .html
mode: LEGACYHTML5
encoding: UTF-8
content-type: text/html
cache: false server:
port: 9090
# context-path: /zuul #Security authentication is enabled by default above springboot 1.5.x
management:
security:
enabled: false eureka:
client:
serviceUrl:
defaultZone: ${registry.url}
registry-fetch-interval-seconds: 5 # 拉取服务注册信息间隔时间 (默认为30秒)
instance:
lease-expiration-duration-in-seconds: 60 # 注册中心超过这个时间没收到心跳,会视为无效节点(默认为90秒)
lease-renewal-interval-in-seconds: 30 # 发送心跳间隔时间(默认30秒)
preferIpAddress: true
instanceId: ${spring.cloud.client.ipAddress}:${server.port} zuul:
add-host-header: true #webui重定向 请求头host显示为网关的(eg:localhost:9090)而非webui的
ignoredServices: '*' #禁用服务名路游
sensitive-headers: #传递头信息
retryable: true #负载均衡时,路游的服务重启时,可通过重试到其他相同服务
# host:
# socket-timeout-millis: 60000
# connect-timeout-millis: 60000
routes:
sys:
path: /sys/**
serviceId: kps.webAPISYS
common:
path: /common/**
serviceId: kps.webAPICommon
po:
path: /po/**
serviceId: kps.webAPIPO
wms:
path: /wms/**
serviceId: kps.webAPIWMS
eq:
path: /eq/**
serviceId: kps.webAPIEQ
kps:
path: /kps/**
serviceId: kps.webUI
helka:
path: /helka/**
serviceId: kps.helka
abc:
path: /abc/**
serviceId: kps.abc
app:
path: /app/**
serviceId: kps.appAPIScan

其实只增加了

    app:
path: /app/**
serviceId: kps.appAPIScan

五  看一下config中心

如果需要feign接口,那么就需要配置config,

(这里我没有配置,因为不需要)

看一下 config-dev

 #registry url
registry:
url: http://${host:localhost}:9088/eureka/ ## DataSource
spring:
datasource:
url: ***
username: ***
password: ***
jpa:
generate-ddl: false
hibernate:
ddl-auto: none
database: mysql
show-sql: false
resources:
chain:
strategy:
content:
enabled: true
paths: /** redis:
host: ***
database: 1
pool:
max-active: 20
min-idle: 1
max-idle: 1
max-wait: 1 #druid connect pool
db:
druid:
url: ${spring.datasource.url}
username: ${spring.datasource.username}
password: ${spring.datasource.password}
filters: stat,wall
max-active: 60
initial-size: 10
max-wait: 60000
min-idle: 10
time-between-eviction-runs-millis: 600000
min-evictable-idle-time-millis: 300000
test-while-idle: true
test-on-borrow: false
test-on-return: false
pool-prepared-statements: false
max-open-prepared-statements: 20 #file
file:
accessPath: /file/** #访问文件前缀
uploadFolder: d://uploadFiles/ #上传文件存放路径 isDebug: false #app scan
appSign: *** feign:
sysService: kps.webAPISYS
poService: kps.webAPIPO
wmsService: kps.webAPIWMS
commonService: kps.webAPICommon
eqService: kps.webAPIEQ kintechWebAPIURL: http://localhost:9004/kps/api/

application.yml

spring:
profiles:
active: native
application:
name: springCloud.config server:
port: 9089 endpoints:
health:
enabled: true #Security authentication is enabled by default above springboot 1.5.x
management:
security:
enabled: false info:
author: cjh
fileName: config

springcloud 新增微服务的更多相关文章

  1. 用SpringCloud进行微服务架构演进

    在<架构师必须要知道的阿里的中台战略与微服务> 中已经阐明选择SpringCloud进行微服务架构实现中台战略,因此下面介绍SpringCloud的一些内容,SpringCloud已经出来 ...

  2. 基于Spring-Cloud的微服务框架设计

    基于Spring-Cloud的微服务框架设计 先进行大的整体的框架整理,然后在针对每一项进行具体的详细介绍

  3. SpringCloud学习--微服务架构

    目录 微服务架构快速指南 SOA Dubbo Spring Cloud Dubbo与SpringCloud对比 微服务(Microservice)架构快速指南 什么是软件架构? 软件架构是一个包含各种 ...

  4. springCloud搭建微服务集群+Zuul服务器端负载均衡

    概述 最近研究了一下springCloud的微服务集群,主要用到了SpringCloud的服务发现和服务器端负载均衡,所有的项目都是用的springboot,可以和springCloud无缝对接. 技 ...

  5. SpringCloud与微服务系列专栏

    一. 前置知识 学习SpringCloud之前需要具备和掌握如下框架和工具的使用:SpringMVC,Spring,Spring Boot,Mybatis,Maven,Git. SpringCloud ...

  6. springCloud进阶(微服务架构&Eureka)

    springCloud进阶(微服务架构&Eureka) 1. 微服务集群 1.1 为什么要集群 为了提供并发量,有时同一个服务提供者可以部署多个(商品服务).这个客户端在调用时要根据一定的负责 ...

  7. 一个C#开发者学习SpringCloud搭建微服务的心路历程

    前言 Spring Cloud很火,很多文章都有介绍如何使用,但对于我这种初学者,我需要从创建项目开始学起,所以这些文章对于我的启蒙,帮助不大,所以只好自己写一篇文章,用于备忘. SpringClou ...

  8. SpringCloud与微服务Ⅴ --- Eureka服务注册与发现

    一.Eureka是什么 Eureka是Netflix的一个子模块,也是核心模块之一.Eureka是一个基于REST的服务,用于定位服务,以实现云端中间层服务发现和故障转移.服务注册与发现对于微服务架构 ...

  9. SpringCloud与微服务Ⅶ --- Feign负载均衡

    官方文档:https://projects.spring.io/spring-cloud/spring-cloud.html#spring-cloud-feign 一.Feign是什么 Feign是一 ...

随机推荐

  1. iOS----------计算一段代码执行时间

    CFAbsoluteTime start = CFAbsoluteTimeGetCurrent(); //在这写入要计算时间的代码 // do something CFAbsoluteTime end ...

  2. python 生成图形验证码

    文章链接:https://mp.weixin.qq.com/s/LYUBRNallHcjnhJb1R3ZBg 日常在网站使用过程中经常遇到图形验证,今天准备自己做个图形验证码,这算是个简单的功能,也适 ...

  3. ionic3 导航的应用(页面跳转与参数传递)

    about.html(跳转页面) <ion-content padding> <ion-list> <ion-item *ngFor="let he of co ...

  4. vue.js的手脚架vue-cli项目搭建的步骤

    手脚架是什么? 众所周知,现在的前端项目发展得越渐越大,我们前端程序员要从0开始去搭建一套完整的项目很费时,所以这时候前端工程的手脚架就出现了. 我用得vue-cli也是其中之一,还有其他的我也说不清 ...

  5. Git代码管理

    持续更新中...   有道笔记链接:http://note.youdao.com/noteshare?id=10a0a86a3499f92cf26371f2698b97d2   Git网上平台 Git ...

  6. C# List集合去重使用lambda表达式

    name age sex Lucy 22 woman Lily 23 woman Tom 24 man Lucy 22 woman Lily 23 woman LiLei 25 man List< ...

  7. python3 int(整型)

    __abs__(返回绝对值) n = -5 print(n.__abs__()) #输出:5 __add__(相加,运算符:+) n = 3 print(n.__add__(5)) #输出:8 __a ...

  8. 【记录】Xmind8 Pro 激活

    摘要 XMind 是一个全功能的思维导图和头脑风暴软件,为激发灵感和创意而生.作为一款有效提升工作和生活效率的生产力工具,受到全球百千万用户的青睐. [有能力请支持正版]     在xmin下载xmi ...

  9. markdown小知识总结

    字体.字号.颜色 但如果我们想修改文字大小/颜色/字体,就要用font标签,代码如下: 宋体大小为2的字 color代表字体颜色(要用16进制颜色值),size代表文字大小,face代表字体 效果展示 ...

  10. elasticsearch系列八:ES 集群管理(集群规划、集群搭建、集群管理)

    一.集群规划 搭建一个集群我们需要考虑如下几个问题: 1. 我们需要多大规模的集群? 2. 集群中的节点角色如何分配? 3. 如何避免脑裂问题? 4. 索引应该设置多少个分片? 5. 分片应该设置几个 ...