个人记录

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

一  创建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. js中的new()到底做了些什么??

    要创建 Person 的新实例,必须使用 new 操作符.以这种方式调用构造函数实际上会经历以下 4个步骤:(1) 创建一个新对象:(2) 将构造函数的作用域赋给新对象(因此 this 就指向了这个新 ...

  2. arcgis api 3.x for js 入门开发系列五地图态势标绘(附源码下载)

    前言 关于本篇功能实现用到的 api 涉及类看不懂的,请参照 esri 官网的 arcgis api 3.x for js:esri 官网 api,里面详细的介绍 arcgis api 3.x 各个类 ...

  3. IDEA工具教程

    刚从myeclipse工具转成IntelliJ IDEA工具,在“传智播客*黑马程序员”学习了相关操作和配置,因此整理在该文章中.   文章大纲 教程文档下载地址 链接:https://pan.bai ...

  4. MySQL如何判别InnoDB表是独立表空间还是共享表空间

    InnoDB采用按表空间(tablespace)的方式进行存储数据, 默认配置情况下会有一个初始大小为10MB, 名字为ibdata1的文件, 该文件就是默认的表空间文件(tablespce file ...

  5. Java - String 的字面量、常量池、构造函数和intern()函数

    一.内存中的 String 对象 Java 的堆和栈 对于基本数据类型变量和对象的引用,也就是局部变量表属于栈内存: 而通过 new 关键字和 constructor 创建的对象存放在堆内存: 直接的 ...

  6. netcat的简单使用(一)

    简单写一下netcat这个强悍的工具,主要是怕自己忘了 功能大致这些个,有遗漏的欢迎私信补充 1.侦听模式/传输模式 2.telnet/获取banner信息 3.传输文本信息 4.传输文件/目录 5. ...

  7. new 和 newInstance 的区别

    初始化一个类,生成一个实例的时候:newInstance() 和 new 有什么区别? 用newInstance与用new是区别的,区别在于创建对象的方式不一样,前者是使用类加载机制,那么为什么会有两 ...

  8. Python面试笔记二

    一.算法 1.归并排序 2.快速排序 3.算法复杂度 4.哈希表数据结构 二.数据库 1.设计一个用户关注系统的数据库表 1.设计一个用户关注系统的数据库表,写三个相关的SQL语句两张表,一张user ...

  9. redis.clients.jedis.exceptions.JedisDataException: ERR invalid DB index

    添加redis配置文件, 启动后,调用报错  redis.clients.jedis.exceptions.JedisDataException: ERR invalid DB index ERR i ...

  10. 关于模块安装及cmd安装pip3模块失败的 Read timed out.的补救方法

    自己在安装pip中的request模块时,安装到一半老是报错.我看了下报错的代码最后一句写的是 Read timed out. 就是读取超时,从网上查了一下,原因是由于中国的网比较慢,下载超时.需要在 ...