个人记录

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

一  创建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设计模式]:工厂模式(3)

    简单工厂模式是由一个方法来决定到底要创建哪个类的实例, 而这些实例经常都拥有相同的接口. 这种模式主要用在所实例化的类型在编译期并不能确定, 而是在执行期决定的情况. 说的通俗点,就像公司茶水间的饮料 ...

  2. Salesforce 超大量数据导入优化策略

    本文参考自以下系列文章: 1 2 3 4 5 6 超大量数据导入优化策略 Salesforce和很多其他系统都可以很好的协作.在协作过程中,数据的导入导出便成为了一个关键的步骤. 当客户的业务量非常大 ...

  3. Android ION内存分配

    The Android ION memory allocator 英文原文 ION heaps ION设计的目标 为了避免内存碎片化,或者为一些有着特殊内存需求的硬件,比如GPUs.display c ...

  4. dede 采集到数据后,发布日期变为本地日期解决方法

    找到dede目录下的co_export.php 大概在170行左右 //获取时间和标题 $pubdate = $sortrank = time(); $title = $row->title; ...

  5. mysql免安装版初次使用

    在自己电脑上安装一个mysql数据库并启动,碰到一些问题,总结一下 1.下载免安装版mysql数据库,百度下载了了5.7.25版本 2.在bin文件夹下找到my-defaults.ini文件,我这没有 ...

  6. mysql 从一个表中查询,插入到另一个表中

    insert into table1(field1) select field1 from table2; ;

  7. Go语言学习笔记-函数部分(三)

    函数部分 函数基本组成:关键字func.函数名.参数列表.返回值.函数体.返回语句 例子: func Add(int a, int b) (return int, err error){ ....函数 ...

  8. centos7搭建ftp

    1.检查安装vsftpd软件 rpm –qa |grep vsftpd 这里显示已经安装了,我们来卸载它重新安装 卸载vsftpd命令 rpm –e 文件名 显示卸载完成 安装vsftpd命令 Yum ...

  9. Django学习开发--笔记一(从零开始)

    创建django项目注: 首先需在python中下载django 命令:pip install django1.任意文件中创建django项目 diango-admin startproject my ...

  10. Myeclipse、eclipse安装lombok

    Lombok简介 Lombok是一个可以通过简单的注解形式来帮助我们简化消除一些必须有但显得很臃肿的Java代码的工具,通过使用对应的注解,可以在编译源码的时候生成对应的方法.官方地址:https:/ ...