个人记录

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

一  创建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. C# 用户控件之温度计

    本文以一个用户控件[User Control]实现温度计的小例子,简述用户控件的相关知识,以供学习分享使用,如有不足之处,还请指正. 概述 一般而言,用户控件[User Control],是在Visu ...

  2. Android为TV端助力 eclipse build project 出现major.minor version 52.0的问题

    那些网上说的JDK什么的的问题,我求你们不要误人子弟好吗? 出现在这个的原因就是ADT也就是你的SDK manager 的Tools版本跟你的SDK版本不兼容,如果你的是SDK 23.0.2那你的To ...

  3. c#高级编程_第10版 云盘地址

    下载地址 链接:https://pan.baidu.com/s/1u8PcY4RJhRB1yfm-2XaTEQ 密码:159z

  4. 定时任务 Cron表达式

    Cron表达式由6~7项组成,中间用空格分开.从左到右依次是: 秒.分.时.日.月.周几.年(可省略) Cron表达式的值可以是数字,也可以是以下符号: "*":所有值都匹配 &q ...

  5. 关于opencv模板匹配功能的项目测试记录

    模板匹配功能介绍的很好的一篇博客:https://www.cnblogs.com/XJT2018/p/9934139.html 就如上述博客所言:“若原图像中的匹配目标发生旋转或大小变化,该算法无效. ...

  6. MySQL从查找数据库表到删除全过程

    使用DOS命令进入MySQL:mysql -u root -p   按回车键输入密码显示如下界面成功进入MySQL交互界面. 如果此时不知道MySQL有哪些数据库,使用显示所有数据库名语句:show ...

  7. spark-2.4.0-hadoop2.7-高可用(HA)安装部署

    1. 主机规划 主机名称 IP地址 操作系统 部署软件 运行进程 备注 mini01 172.16.1.11[内网] 10.0.0.11  [外网] CentOS 7.5 Jdk-8.zookeepe ...

  8. Spark SQL中列转行(UNPIVOT)的两种方法

    行列之间的互相转换是ETL中的常见需求,在Spark SQL中,行转列有内建的PIVOT函数可用,没什么特别之处.而列转行要稍微麻烦点.本文整理了2种可行的列转行方法,供参考. 本文链接:https: ...

  9. HTML5存储技术Storage

    前端存储技术localStorage是永久存储sessionStorage是一次会话存储 localStorage只支持string类型的存储 存进去的所有类型, 取出来之后都变成了string. 一 ...

  10. 【English】20190415

    approximately大约 [əˈprɑ:ksɪmətli] This install will take + minutes and requires the download of appro ...