天天看點

Spring Cloud規範實戰

Spring cloud 架建構立規範文檔

版本1.0

作者:阿伏(王伏芃)

目錄

1. 建立規範的目的 3

2.模闆源碼位置 3

3.系統架構圖 3

4.路由服務Zuul Server 4

5.MybatisGeneratorPlus生成器 9

6.業務應用服務SpringBoot Server 15

6.1 服務啟動方法: 16

6.2 @EnableCaching 17

6.3 @EnableScheduling 18

6.4@EnableFeignClients(basePackages="com.pay.api.client") 19

6.5 @ComponentScan(basePackages = "com.pay.api") 19

6.6 @ServletComponentScan 20

6.7 @EnableCircuitBreaker 20

6.8 @EnableHystrixDashboard 21

6.9 @EnableDiscoveryClient 22

6.10 @EnableSwagger2 22

7.注冊中心服務Eureka Server 24

7.1 在pom.xml裡添加依賴: 24

7.2 在bootstrap.yml裡面配置如此: 25

7.3 EurekaServerApplication.java 25

7.4 運作時界面如下 26

8.全鍊路監控服務Zipkin Server 26

8.1 pom.xml 26

8.2 Bootstrap.yml 27

8.3 ZipkinServerApplication.java 27

8.4 用戶端sleuth配置 28

9.配置服務Config Server 29

9.1. Pom.xml 29

9.2. ConfigServerApplication.java 29

9.3. Config server 的yml的配置 30

9.4. Client端的Pom.xml 30

9.5 Client端的在代碼中的使用 31

9.6 Client端的yml中的配置: 31

10.各種命名規範 31

10.1變量命名規範。 31

10.2 強制要求所有魔法值全部用KeyCommon這個類裡的屬性來替代。 32

10.3 所有抛出的異常在TemplateErrorCode裡面定義。 32

10.4 方法名命名規範 32

11. 模闆使用方法 33

11.1 從git上面下載下傳代碼,檢視章節2。 33

11.2用STS打開。STS下載下傳位址在http://spring.io/tools/sts 33

11.3 配置好maven和jdk 34

11.3 導入template源碼 37

11.4 重命名模闆裡面的檔案夾名稱或者更改目錄結構,改成自己要的包名。 41

11.5 把com.caituo.template替換成自己的包名。 41

11.6 啟動方法 42

12.附上之前做的一整套架構。 44

13.阿裡巴巴的P3C标準 45

13.1. P3C标準的pdf文檔 45

13.2.P3C的Eclipse插件安裝辦法及啟動檢查 45

1. 建立規範的目的

是為了統一規格,提高代碼的可讀性,系統的易用性,可維護性。

本規範作為搭建spring cloud的指導文檔。確定照着搭建就能成功。

2.模闆源碼位置

在公司的gitlab上面。

http://10.66.1.168:10080/wangfupeng/pay-template.git

如果沒有權限,請聯系胡立開([email protected]),趙超([email protected])

3.系統架構圖

下面是介紹各種伺服器和各種應用。

4.路由服務Zuul Server

代碼目錄如圖所示:

其中bootstrap.yml裡面的

spring:

  config:

    location: classpath:/${ENV:dev}/

這個注釋說明,通過環境變量來讀取ENV的值來決定在哪個目錄裡面找着application.yml

application.yml裡配置如下:

  application:

    name: zuul

server:

  port: 8020

eureka:

  client:

    service-url:

      defaultZone: http://localhost:8010/eureka/

zuul: 

  routes:

    api-a:

      path: /service-a/**

      serviceId: service-a

    api-b:

      path: /service-b/**

      serviceId: service-b

  sensitive-headers:  #設定忽略的頭資訊,設定為空能解決會話保持問題

  add-host-header: true #設為true才能保持Host頭資訊處理正确

#這表示,我們不希望 /hello 接口被路由,調用 "/service-a"會跳轉到"service-a"服務。路由必須配置一個可以被指定為"ant路徑比對原則"的"path",是以"/service-a/"隻能比對一個層級, 但"/service-a/*"可以比對多級.

Ant比對規則表

Wildcard Description  

? 比對任何單字元  

* 比對0或者任意數量的字元  

** 比對0或者更多的目錄

Pom.xml裡面的配置如此:

<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>

<groupId>org.springframework.boot</groupId>

<artifactId>spring-boot-starter-parent</artifactId>

<version>1.5.4.RELEASE</version>

<relativePath /> <!-- lookup parent from repository -->

</parent>

<modelVersion>4.0.0</modelVersion>

<groupId>com.caituo.server</groupId>

<artifactId>zuul</artifactId>

<version>66602</version>

<packaging>jar</packaging>

<name>zuul</name>

<url>http://maven.apache.org</url>

<properties>

<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>

<java.version>1.8</java.version>

<spring-cloud.version>Dalston.SR1</spring-cloud.version>

</properties>

<dependencies>

<dependency>

<groupId>org.springframework.cloud</groupId>

<artifactId>spring-cloud-starter-zuul</artifactId>

</dependency>

</dependencies>

<dependencyManagement>

<artifactId>spring-cloud-dependencies</artifactId>

<version>${spring-cloud.version}</version>

<type>pom</type>

<scope>import</scope>

</dependencyManagement>

</project>

然後在ZuulApplication.java裡面寫上如下代碼就行了。

package com.caituo.server;

import org.springframework.boot.SpringApplication;

import org.springframework.boot.web.servlet.ServletComponentScan;

import org.springframework.cloud.client.SpringCloudApplication;

import org.springframework.cloud.netflix.zuul.EnableZuulProxy;

import org.springframework.context.annotation.Bean;

import com.caituo.server.filter.MyZuulFilter;

@SpringCloudApplication

@EnableZuulProxy

@ServletComponentScan

public class ZuulApplication {

    public static void main(String[] args) {

        SpringApplication.run(ZuulApplication.class, args);

    }

    @Bean

    public MyZuulFilter getZuulFilter(){

        return new MyZuulFilter();

}

當然還有其他進階用法,就具體問題具體分析了

5.MybatisGeneratorPlus生成器

目錄結構如圖

使用方法:

1.右鍵Pom.xml->Run As->Maven Install

2. 在template裡面找着generatorConfig.xml。如圖所示。

3. 然後編輯。

在這裡改連接配接字元串。

<jdbcConnection driverClass="com.mysql.jdbc.Driver"

connectionURL="jdbc:mysql://10.66.1.32:3306/payment" 

userId="ssc"

password="ssc">

</jdbcConnection>

然後找着<table tableName=

然後編輯,複制,粘貼真個<table></table>标簽

編輯成自己要的東東。

一般自己有幾張表,就寫複制粘貼幾張表。

其餘的别改,儲存後。

Pom.xml->右鍵->Run As->Maven build…

複制下面指令進入Goals裡面

-Dfile.encoding=UTF-8 -Dmybatis.generator.overwrite=true mybatis-generator:generate -e -X

點Run

好了,生成器會自動幫助生成Model, ModelExample, Mapper, Service, Controller. 包括@RequestMapping注解,swagger注釋和文檔。Cache的注解。

規範點:

1.Mysql裡所有字段必須勾上非空。(暫緩推行)

如圖所示。下面的軟體是Navicat,如果用SqlYog軟體也類似。

強制要求在插入字段時,必須設定一個值。

2. 所有的字段都要上索引,除了Blob字段。

3. 用mybatisGenerator生成器一次性生成所有代碼,後期不允許自己寫SQL語句。(暫緩推行)

有特殊要求比如join之類的跨表查詢,用循環周遊來解決。

這樣做好處:

1.把程式員從架構層面解放出來,專心實作業務代碼。

2.各種資料表層面解耦。

3.提高代碼可讀性。

4.後期維護很容易。

5.把操作資料庫變成操作對象一樣容易。

6.後期做其他微服務改造很容易。

6.業務應用服務SpringBoot Server

目錄結構如圖所示:

6.1 服務啟動方法:

@SpringBootApplication

@EnableCaching

@EnableScheduling

@EnableFeignClients(basePackages = "com.pay.api.client")

@ComponentScan(basePackages = "com.pay.api")

@EnableCircuitBreaker

@EnableHystrixDashboard

@EnableSwagger2

@EnableDiscoveryClient

public class Application {

public static void main(String[] args) {

SpringApplication.run(Application.class, args);

6.2 @EnableCaching

打開緩存标志, 打開之後,我們可以這麼使用Cache

    @Cacheable(value = "cache:card", key = "'cache:card:get:id:'+#id")

    public Card get(Integer id) {

        return cardMapper.selectByPrimaryKey(id);

    @CacheEvict(value = "cache:card", key = "'cache:card:get:id:'+#card.getId()")

    public Integer update(Card card) {

        return cardMapper.updateByPrimaryKeySelective(card);

要求再pom裡面配置:

      <groupId>org.springframework.boot</groupId>

      <artifactId>spring-boot-starter-cache</artifactId>

同時要實作2個類

@Component

public class RedisCacheManager implements CacheManager, DisposableBean {

@Autowired

@Qualifier("myRedisCache")

private Cache cache;

@Override

public void destroy() throws Exception {

cache.clear();

public Cache getCache(String name) {

return cache;

public Collection<String> getCacheNames() {

return null;

@Component("myRedisCache")

public class RedisCache implements Cache {

public static final Logger logger = LoggerFactory.getLogger(ShardedRedisCache.class);

……

public ValueWrapper get(Object key) {

//主要是在這裡實作get方法

public void put(Object key, Object value) {

//主要在這裡實作put方法

public <T> T get(Object key, Class<T> type) {

public void evict(Object key) {

//主要在這裡實作删除方法

……其餘方法略

6.3 @EnableScheduling

打開Schedule标志

然後我們就可以在方法上面加上

@Scheduled(fixedRate = 1000)

來顯式的聲明這個方法是個定時任務。其餘的進階表達式要具體情況具體分析

這個要在xml裡面配置

<task:scheduler id="taskScheduler" pool-size="30" />

然後把xml加載進來

可以用如下方式加載

@Configuration

@ImportResource("classpath:/applicationContext.xml")

public class XmlConfiguration {

最後application.java上面要加上

6.4@EnableFeignClients(basePackages="com.pay.api.client")

意思是會掃描包com.pay.api.client下面的所有feign的遠端調用代碼

在這裡聲明了,就能夠和在本地調用服務一樣請求遠端伺服器了。

例如

@FeignClient(name = "tencentIMClient", url = "http://www.qq.com")

public interface TencentIMClient {

    @RequestMapping(method = {RequestMethod.POST}, value = {"/v4/openim/sendmsg"})

    String openimSendmsg(

        @RequestBody OpenimSendMsgRequest request,

        @RequestParam("identifier") String identifier,

        @RequestParam("sdkappid") int sdkAppId,

        @RequestParam("contenttype") String contentType,

        @RequestParam("random") int random,

        @RequestParam("usersig") String usersig

        );

注意,如果url沒有指定,會去eureka伺服器上面去查找name值的應用,然後通路後面對應的@RequestMapping對應的路徑裡的值

如果定義了url則是通路以url開頭的網址

其中還可以指定一些其他的屬性。

6.5 @ComponentScan(basePackages = "com.pay.api")

意思是掃描所有包名是com.pay.api下面的所有class,比對所有AOP,注冊成bean

6.6 @ServletComponentScan

在 SpringBootApplication 上使用@ServletComponentScan 注解後,Servlet、Filter、Listener 可以直接通過 @WebServlet、@WebFilter、@WebListener 注解自動注冊,無需其他代碼。

例如:

@WebServlet(urlPatterns="/xs/myservlet", description="Servlet的說明") 

public class MyServlet2 extends HttpServlet{ 

@WebServlet還有一個屬性是name,在不指定name的情況下,name預設值為類全路徑

再例如:用這個filter來解決跨域問題。

@WebFilter(filterName="corsFilter",urlPatterns="/*")

public class CorsFilter implements Filter{  

    public void doFilter(ServletRequest request, ServletResponse servletResponse,  

            FilterChain chain) throws IOException, ServletException {

            HttpServletResponse response = (HttpServletResponse) servletResponse;  

            response.setHeader("Access-Control-Allow-Origin", "*");

            response.setHeader("Access-Control-Allow-Methods", "POST, GET, OPTIONS, DELETE");  

            response.setHeader("Access-Control-Max-Age", "3600");

            response.setHeader("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept, token");  

            chain.doFilter(request, response);

    }  

其餘的還有一些進階應用,要具體情況具體分析了

6.7 @EnableCircuitBreaker

這個是打開斷路器的功能。

1. 引入Hystrix的依賴包

    <groupId>org.springframework.cloud</groupId>

    <artifactId>spring-cloud-starter-hystrix</artifactId>

2. bootstrap.yml中加上這個配置

#逾時500毫秒, 基礎服務運作逾時。用于feign的中斷

hystrix:

  command.default.execution.isolation.thread.timeoutInMilliseconds: 5000 //設定預設逾時時間

  threadpool.default.coreSize: 50

  threadpool.default.maximumSize: 60

  threadpool.default.maxQueueSize: 40

#打開feign的斷路器,可以在feign調用時使用逾時熔斷

feign:

  hystrix:

    enabled: true

3. 再要斷路的地方上面加上這個AOP

@HystrixCommand(fallbackMethod = “fallback”, //要在同一個類裡面寫這個方法fallback(), 參數和傳回對象要完全和下面的方法一緻

commandProperties = {

@HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds", value = "16666"),//逾時時間

@HystrixProperty(name = "circuitBreaker.requestVolumeThreshold", value = "26"),//設定一個滑動視窗内觸發熔斷的最少請求量,預設20。

@HystrixProperty(name = "circuitBreaker.sleepWindowInMilliseconds", value = "6000") },//設定觸發熔斷後,拒絕請求後多長時間開始嘗試再次執行。預設5000ms。

threadPoolProperties = {

@HystrixProperty(name = "coreSize", value = "10")})//設定線程池的core size,這是最大的并發執行數量。預設10

6.8 @EnableHystrixDashboard

運作Hystrix儀表闆需要在spring boot主類上标注@EnableHystrixDashboard。然後通路/ hystrix檢視儀表盤,在hystrix用戶端應用使用/hystrix.stream監控。

6.9 @EnableDiscoveryClient

開啟服務發現,自動往eureka伺服器上注冊自己的api來友善其他應用在eureka上查找相關服務。

需要在bootstrap.yml中配置

#打開eureka的注冊查找位址

  instance:

    lease-expiration-duration-in-seconds: 30

    lease-renewal-interval-in-seconds: 10

    serviceUrl:

      defaultZone: http://localhost:8761/eureka

6.10 @EnableSwagger2

通過注解EnableSwagger2聲明Swagger的可用性。Swagger是一個規範和完整的架構,用于生成、描述、調用和可視化 RESTful 風格的 Web 服務。總體目标是使用戶端和檔案系統作為伺服器以同樣的速度來更新。檔案的方法,參數和模型緊密內建到伺服器端的代碼,允許API來始終保持同步。步驟如下:

6.10.1. 添加maven依賴,需要在系統的pom中添加如下依賴:

   <groupId>io.springfox</groupId>

   <artifactId>springfox-swagger2</artifactId>

   <version>2.6.1</version>

   <artifactId>springfox-swagger-ui</artifactId>

6.10.2. 添加swagger配置檔案,配置檔案如下:

public class SwaggerConfig {

    public Docket api() {

        return new Docket(DocumentationType.SWAGGER_2)

                .select()  // 選擇那些路徑和api會生成document

                .apis(RequestHandlerSelectors.any()) // 對所有api進行監控或者可以用.apis(RequestHandlerSelectors.basePackage("com.fpfpp.server.controller"))

                .paths(PathSelectors.any()) // 對所有路徑進行監控

                .build();

6.10.3. 在Controller上面加

@Api(description = "增删改查清單Card")

@RestController

在方法上面加上@ApiOperation("查詢Card")

在參數上面加上@ApiParam(value = "id")

示例如下:

@RequestMapping(value = "/v1/card", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)

public class CardController implements Logging {

    public static final Logger logger = LoggerFactory.getLogger(CardController.class);

    @Autowired

    private CardService cardService;

    @ApiOperation("查詢Card")

    @RequestMapping(value = "/{id}", method = RequestMethod.GET)

    public SimpleResponse get(@ApiParam(value = "id") @PathVariable Integer id) {

        return SimpleResponse.success(cardService.get(id));

6.10.4最後檢視swagger-ui

請通路http://hostname/rootpath/swagger-ui.html

7.注冊中心服務Eureka Server

7.1 在pom.xml裡添加依賴:

<artifactId>spring-cloud-starter-eureka-server</artifactId>

7.2 在bootstrap.yml裡面配置如此:

  port: 16661 #服務端口

    name: eureka-server

    preferIpAddress: true

    ipAddress: ${EUREKA_IPADDRESS:10.200.120.8}

    lease-renewal-interval-in-seconds: 6

    lease-expiration-duration-in-seconds: 6

    instanceId: ${spring.cloud.client.ipAddress}:${server.port}

  server:

    enable-self-preservation: false

    eviction-interval-timer-in-ms: 6666

    register-with-eureka: true #是否将eureka自身作為應用注冊到eureka注冊中心

    fetch-registry: true #為true時,可以啟動,但報異常:Cannot execute request on any known server

      defaultZone: ${EUREKA_DEFAULTZONE:http://10.200.120.8:16661/eureka/,http://10.200.110.8:16661/eureka/} 

7.3 EurekaServerApplication.java

最後應用程式是這麼寫,run起來就是一個eureka 伺服器

上面的配置說明是個eureka叢集。

@EnableEurekaServer

public class EurekaServerApplication {

        SpringApplication.run(EurekaServerApplication.class, args);

7.4 運作時界面如下

其他還有一些進階用法,就具體問題具體分析了

8.全鍊路監控服務Zipkin Server

8.1 pom.xml

      <groupId>org.springframework.cloud</groupId>

      <artifactId>spring-cloud-starter-eureka-server</artifactId>

      <groupId>io.zipkin.java</groupId>

      <artifactId>zipkin-server</artifactId>

      <artifactId>zipkin-autoconfigure-ui</artifactId>

<groupId>io.zipkin.java</groupId>

      <artifactId>zipkin-storage-mysql</artifactId>

      <version>1.19.0</version>

      <artifactId>spring-boot-starter-jdbc</artifactId>

      <groupId>mysql</groupId>

      <artifactId>mysql-connector-java</artifactId>

8.2 Bootstrap.yml

  port: ${SERVER_PORT:16662}

  rabbitmq:

    host: ${RABBIT_HOST:localhost}

  datasource:

    url: jdbc:mysql://${SERVER_NAME:rm-uf637082fw6y68ufh.mysql.rds.aliyuncs.com}:${SERVER_PORT:3306}/${DATABASE_NAME:zipkin_91pay}

    username: ${MYSQL_USERNAME:payservice}

    password: ${MYSQL_PASSWORD:ADdKN0oZIQYH}

    # Switch this on to create the schema on startup:

    schema: classpath:/mysql.sql

    initialize: false

    continueOnError: true

  zipkin:

    base-url: http://${ZIPKIN_URL:10.200.110.8}:${ZIPKIN_PORT:16662}

  sleuth:

zipkin:

  storage:

    type: mysql

8.3 ZipkinServerApplication.java

最後加上這幾個,就跑起來就好了。

@EnableZipkinServer

public class ZipkinServerApplication {

        SpringApplication.run(ZipkinServerApplication.class, args);

    public MySQLStorage mySQLStorage(DataSource datasource) {

        return MySQLStorage.builder().datasource(datasource).executor(Runnable::run).build();

8.4 用戶端sleuth配置

然後用戶端要使用zipkin server需要在bootstrap.yml配置裡面加上。

bootstrap.yml

#zipkin

spring.zipkin.enabled=true

spring.zipkin.baseUrl=http://172.20.67.15:16662

spring.sleuth.sampler.percentage=0.1

Pom.xml裡面加上

Pom.xml

<artifactId>spring-cloud-starter-sleuth</artifactId>

就可爽爽的使用sleuth往zipkin裡面發資料啦。

8.5 運作時界面如下。

9.配置服務Config Server

9.1. Pom.xml

    <dependency>

        <groupId>org.springframework.cloud</groupId>

        <artifactId>spring-cloud-config-server</artifactId>

    </dependency>

        <artifactId>spring-cloud-starter-eureka</artifactId>

9.2. ConfigServerApplication.java

@EnableConfigServer

@EnableEurekaClient

@EnableAutoConfiguration

public class ConfigServerApplication {

SpringApplication.run(PayConfigServerApplication.class, args);

9.3. Config server 的yml的配置

  port: 10663

      #eureka服務注冊位址

      defaultZone: http://172.20.67.15:10661/eureka/

# git管理配置

  cloud:

    config:

      server:

        git:

          #git倉庫位址

          uri: http://10.66.1.168:10080/91Pay/config-server

          #搜尋路徑配成變量,這樣不同用戶端會請求自己的目錄名

          searchPaths: '{application}'

          username: [email protected]

          password: Fff66p66p66p

    name: config-server

management:

  security:

enabled: false

如果有必要可以把config server配置到eureka上去也是支援的。

9.4. Client端的Pom.xml

<artifactId>spring-cloud-starter-config</artifactId>

9.5 Client端的在代碼中的使用

在使用時用

@Value("${lucky-word}") 

String luckyWord;

把值注入進變量就好。

9.6 Client端的yml中的配置:

環境資源的命名規則由以下的三個參數确定:

{application}映射到Config用戶端的spring.application.name屬性

{profile}映射到Config用戶端的spring.profiles.active屬性,可以用來區分環境,比如dev,test,produce等等

{label}映射到Git伺服器的commit id,分支名稱或者tag,預設值為master

是以配置如下:

spring.application.name=accountServer

spring.profiles.active=dev

spring.cloud.config.label=master

spring.cloud.config.uri=http://localhost:8888

如果spring.cloud.config.uri沒有配置,然後從eureka上面去發現config server也是可以的。

這樣就是到configserver上的master分支上的accountServer目錄裡面的accountServer-dev.yml上面去找資料了。

10.各種命名規範

10.1變量命名規範。

強制要求所有變量命名用類名首字母小寫,然後在後面加上适當含義 。

比如

JedisPool jedisPool 合規

JedisPool jedisPoolForAccountServer. 合規

JedisPool hcc     不合規

10.2 強制要求所有魔法值全部用KeyCommon這個類裡的屬性來替代。

比如.andIsAdminEqualTo(true).andStatusEqualTo("40");

要改成

.andIsAdminEqualTo(true).andStatusEqualTo(KeyCommon.STATUS_COMPLETE_VERIFY);

然後在KeyCommon裡面寫一個

public static final String STATUS_COMPLETE_VERIFY = "40";

10.3 所有抛出的異常在TemplateErrorCode裡面定義。

使用方式用throw new 

TemplateException(TemplateErrorCode.LIMIT_PROGRAM_AOP_PREFERENCE_ERROR);

在要抛出異常的地方抛出異常即可。

10.4 方法名命名規範

用有意義的英文單詞來做命名。遵從駝峰标志。

11. 模闆使用方法

11.1 從git上面下載下傳代碼,檢視章節2。

11.2用STS打開。STS下載下傳位址在http://spring.io/tools/sts

下載下傳後,解壓縮。運作STS.exe

11.3 配置好maven和jdk

Maven的Settings.xml配置如下

已經删除了無用的注釋和沒有用的元件。

<?xml version="1.0" encoding="UTF-8"?>

<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"

          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

          xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">

  <localRepository>c:/java/maven/repository6</localRepository>

  <pluginGroups>

  </pluginGroups>

  <servers>

  </servers> 

  <proxies>

  </proxies>

  <mirrors>

    <mirror>

      <id>Fff666666</id>

      <mirrorOf>central</mirrorOf>

      <name>Maven Repository Caituo</name>

      <url>http://10.66.1.40:8081/nexus/content/groups/public/</url>

    </mirror>

  </mirrors>

  <profiles>

    <profile>

      <id>caituo</id>

      <repositories>

        <repository>

          <id>caituo</id>

          <name>Caituo Repositories Group</name>

          <url>http://10.66.1.40:8081/nexus/content/groups/public/</url>

 <snapshots>

<enabled>true</enabled>

 </snapshots>

        </repository>

      </repositories>

    </profile>

  </profiles>

  <activeProfiles>

    <activeProfile>caituo</activeProfile>

  </activeProfiles>

</settings>

11.3 導入template源碼

Maven Update一下下載下傳相應的jar包。

隻要你配的nexus伺服器是10.66.1.40. 能確定加載成功,沒有報異常。

11.4 重命名模闆裡面的檔案夾名稱或者更改目錄結構,改成自己要的包名。

11.5 把com.caituo.template替換成自己的包名。

要全部都替換。

11.6 啟動方法

開發時的啟動方法就時Application.java->右鍵->Debug As->Java Application

在伺服器上面啟動方法是:

1. 先maven install成一個jar包假設名字叫zzzzzz-66601.jar

2. 在secureCRT用sz指令上傳至伺服器。如果沒有sz可以用yum install lrzsz安裝。

3. 用這個指令運作起來就好了。

nohup java –jar zzzzzz-66601.jar –-ENV=prod >/dev/null &

如果java沒有找着,可以帶上java的全路徑。

12.附上之前做的一整套架構。

其中有幾個不足:

1. Redis版本低2.8.7,沒法做Cluster,如果用redis cluster(版本3.0+)就可以不用shardedJedisPool。其實差不多。

2. ElasticSearch對大資料量查詢(傳回資料10000條+)支援很差。對小資料量查詢(傳回資料100條以内)支援非常好。

13.阿裡巴巴的P3C标準

13.1. P3C标準的pdf文檔

13.2.P3C的Eclipse插件安裝辦法及啟動檢查

1. Help->Install New Software

輸入https://p3c.alibaba.com/plugin/eclipse/update, 按回車,選中插件,

點Next->Next->I Accept -> Finish

重新開機STS

再右鍵選中項目。會出來一個

點選開始掃描。

掃描結果在P3C Results裡面有

要把所有的提示全部清除掉

更改時在目前STS裡改會很慢,建議再起一個沒有裝P3C的STS來改。

P3C隻是在掃描代碼時使用。