`
taiwei.peng
  • 浏览: 228694 次
  • 性别: Icon_minigender_1
  • 来自: 深圳
社区版块
存档分类
最新评论

Spring Cloud 微服务

阅读更多
1.完整的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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.soft.customer</groupId>
<artifactId>soft-customer</artifactId>
<version>0.0.1-SNAPSHOT</version>

<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.0.RELEASE</version>
</parent>

<properties>
<java.version>1.8</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<spring-cloud.version>Finchley.M9</spring-cloud.version>
</properties>

<dependencies>
   <dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>

<!-- spring cloud config 客户端包 -->
<dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-config</artifactId>
        </dependency>
       
         <!--Spring Boot Actuator,感应服务端变化 -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>
       
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>

<!--使用 ${spring.cloud.client.ip-address} 需引用下面的包-->
<dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-commons</artifactId>
        </dependency>

<!-- spring-redis 整合包start -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>

<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-pool2</artifactId>
<version>2.6.2</version>
</dependency>
<!-- spring-redis 整合包end -->

<!-- connection pool start -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.47</version>
</dependency>

<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid-spring-boot-starter</artifactId>
<version>1.1.17</version>
</dependency>
<!-- connection pool end -->

        <!-- mybatis start -->
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis</artifactId>
<version>3.4.6</version>
</dependency>

<dependency>
<groupId>tk.mybatis</groupId>
<artifactId>mapper</artifactId>
<version>4.1.0</version>
</dependency>

<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>1.3.2</version>
</dependency>
<!-- mybatis end -->

<dependency>
<groupId>javax.persistence</groupId>
<artifactId>persistence-api</artifactId>
<version>1.0</version>
</dependency>

<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>

<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.60</version>
</dependency>

</dependencies>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>

<build>
<finalName>soft-customer</finalName>
<sourceDirectory>${basedir}/src/main/java</sourceDirectory>
<outputDirectory>${basedir}/bin/classes</outputDirectory>
<resources>
<resource>
<directory>${basedir}/src/main/java</directory>
<filtering>true</filtering>
<excludes>
<exclude>**/*.java</exclude>
</excludes>
</resource>

<directory>${basedir}/src/main/resources</directory>
<filtering>true</filtering>
<includes>
<include>*.yml</include>
<include>*.sh</include>
</includes>
<targetPath>${basedir}/target</targetPath>
</resource>
</resources>

<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.6</version>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
<mainClass>com.soft.customer.CustomerApplication</mainClass>
</manifest>
</archive>
</configuration>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.10</version>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/lib</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>

<plugin>
            <artifactId>maven-resources-plugin</artifactId>
            <version>3.0.2</version>
            <executions>
              <execution>
                <id>copy-resources</id>
                <phase>validate</phase>
                <goals>
                    <goal>copy-resources</goal>
                </goals>
                <configuration>
                    <outputDirectory>${basedir}/target/resources</outputDirectory>
                    <resources>         
                        <resource>
                            <directory>${basedir}/resources</directory>
                            <filtering>true</filtering>
                        </resource>
                    </resources>             
                </configuration>           
              </execution>
            </executions>
        </plugin>
</plugins>
</build>

</project>

2.完整的启动类
package com.soft.customer;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.web.client.RestTemplate;

import tk.mybatis.spring.annotation.MapperScan;

@SpringBootApplication(exclude = { DataSourceAutoConfiguration.class })
@MapperScan({"com.soft.customer.dao"})
@ComponentScan({"com.soft.customer.*"})
@EnableScheduling
@EnableEurekaClient
@RefreshScope
public class CustomerApplication{

private static Logger logger = LoggerFactory.getLogger(CustomerApplication.class);
   
    //开启均衡负载能力
    @LoadBalanced
    @Bean
    RestTemplate restTemplate() {
        return new RestTemplate();
    }

public static void main(String[] args) {
SpringApplication.run(CustomerApplication.class, args);
logger.info("customer start success!");
}

}

3.bootstap.yml
#http端口配置
server:
  port: 8001
  connection-timeout: 5000
  tomcat:
    max-http-post-size: -1
    max-threads: 1000
    max-connections: 1000

# Mybatis配置
mybatis:
  mapperLocations: classpath:mapper/*.xml

spring:
  application:
    name: soft-customer
  cloud:
    config:
      name: soft-customer  #文件前缀名称
      uri: http://10.45.92.98:9002/
      profile: dev
    
management:
  security:
    enabled: false
endpoints:
  refresh:
    enabled: true
               
# eureka注册中心配置
eureka:
  client:
    serviceUrl:
      defaultZone: http://${eureka.instance.hostname}:9001/eureka/
  instance:
    instance-id: ${spring.cloud.client.ip-address}:${server.port}
    prefer-ip-address: true  
    hostname: ${spring.cloud.client.ip-address}

4.soft-customer-dev.yml
spring:
  redis: 
    pool:
      max-active: -1
      max-wait: -1
      max-idle: 8
      min-idle: 0
    timeout: 0
 
  datasource:
    type: ${datasource.db1.type}
    driverClassName: ${datasource.db1.driver-class-name}
    url: jdbc:mysql://${datasource.db1.ip}:${datasource.db1.port}/policy${datasource.db1.conn-params}
    username: ${datasource.db1.username}
    password: ${datasource.db1.password}
    initial-size: 10
    max-active: 100
    min-idle: 10
    max-wait: 60000
    pool-prepared-statements: true
    max-pool-prepared-statement-per-connection-size: 20
    time-between-eviction-runs-millis: 60000
    min-evictable-idle-time-millis: 300000
    validation-query: SELECT 1 FROM DUAL
    druid:
      filter:
        config:
          enabled: true
      connection-properties: config.decrypt=${datasource.db1.decrypt};config.decrypt.key=${datasource.db1.decrypt-key}

myprops:
  # 短信过期时间
  smsExpTime: 300
  #app微信登录地址
  appWxUrl: https://api.weixin.qq.com/sns
  #app微信登录appId
  appId: wxa4409cfc1b2b44ee
  #app微信登录appSecret
  appSecret: 77965fcde9516e2dce760d944b9cd725
  #验证码开关 1开 0关
  mark: 1
  #钉钉登录地址
  dingUrl: https://oapi.dingtalk.com/sns/getuserinfo_bycode
  #钉钉登录appId
  dingAppId: dingoa4fq68g9fcfx6mqrs
  #钉钉登录Secret
  dingAppSecret: kc2CeRb7nywd7SXZ96-llQDFzjbXOL8umUUtmhgAmvxGVt70LWF69R4W5G8FnoSO
  #苹果登录地址
  appleUrl: https://appleid.apple.com
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics