Commit 96821097 by lixian7

改成Apollo配置

parent 3730afe5
...@@ -29,12 +29,6 @@ ...@@ -29,12 +29,6 @@
<groupId>org.springframework.cloud</groupId> <groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId> <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency> </dependency>
<dependency>
<groupId>com.ctrip.framework.apollo</groupId>
<artifactId>apollo-client</artifactId>
<version>${appllo.version}</version>
</dependency>
<dependency> <dependency>
<groupId>com.hikcreate.edl.pub.web.mobile</groupId> <groupId>com.hikcreate.edl.pub.web.mobile</groupId>
<artifactId>domain</artifactId> <artifactId>domain</artifactId>
...@@ -48,7 +42,7 @@ ...@@ -48,7 +42,7 @@
<dependency> <dependency>
<groupId>com.hikcreate.edl.common</groupId> <groupId>com.hikcreate.edl.common</groupId>
<artifactId>sdk</artifactId> <artifactId>sdk</artifactId>
<version>1.9-SNAPSHOT</version> <version>${parent.version}</version>
</dependency> </dependency>
</dependencies> </dependencies>
......
package com.hikcreate.edl.pub.web.mobile.api; package com.hikcreate.edl.pub.web.mobile.api;
import com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceAutoConfigure;
import com.ctrip.framework.apollo.spring.annotation.EnableApolloConfig;
import org.mybatis.spring.annotation.MapperScan; import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication; import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient; import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.cloud.openfeign.EnableFeignClients; import org.springframework.cloud.openfeign.EnableFeignClients;
@SpringBootApplication(scanBasePackages = "com.hikcreate.edl.pub.web.mobile") @SpringBootApplication(scanBasePackages = "com.hikcreate.edl.pub.web.mobile",exclude = DruidDataSourceAutoConfigure.class)
@MapperScan(basePackages = "com.hikcreate.edl.pub.web.mobile.infra.data.mapper") @MapperScan(basePackages = "com.hikcreate.edl.pub.web.mobile.infra.data.mapper")
@EnableDiscoveryClient @EnableDiscoveryClient
@EnableFeignClients @EnableFeignClients("com.hikcreate")
@EnableEurekaClient
@EnableApolloConfig
public class ApiApplication { public class ApiApplication {
public static void main(String[] args) { public static void main(String[] args) {
......
server.port=60201
#数据源配置
spring.datasource.url=jdbc:mysql://10.197.236\
.152:3306/edl_public?serverTimezone=GMT%2B8&useUnicode=true&characterEncoding=utf-8&useAffectedRows=true&useSSL\
=false&zeroDateTimeBehavior=convertToNull
spring.datasource.username = root
spring.datasource.password = 123456
spring.datasource.type=com.alibaba.druid.pool.DruidDataSource
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
# 连接池配置
# 初始化时建立物理连接的个数。初始化发生在显示调用init方法,或者第一次getConnection时
spring.datasource.druid.initial-size = 0
# 最大连接池数量
spring.datasource.druid.max-active = 80
spring.datasource.druid.min-idle = 2
# 获取连接时最大等待时间,单位毫秒。配置了maxWait之后,缺省启用公平锁,并发效率会有所下降,如果需要可以通过配置useUnfairLock属性为true使用非公平锁。
spring.datasource.druid.max-wait = 8000
# 使用非公平锁。
spring.datasource.druid.use-unfair-lock = true
# 是否缓存preparedStatement,也就是PSCache。PSCache对支持游标的数据库性能提升巨大,比如说oracle。
# 在mysql5.5以下的版本中没有PSCache功能,建议关闭掉。5.5及以上版本有PSCache,建议开启。
spring.datasource.druid.pool-prepared-statements = true
# 为每个连接缓存的preparedStatement的最大数量
spring.datasource.druid.max-pool-prepared-statement-per-connection-size = 20
# 要启用PSCache,必须配置大于0,当大于0时,poolPreparedStatements自动触发修改为true。在Druid中,不会存在Oracle下PSCache占用内存过多的问题,可以把这个数值配置大一些,比如说100
spring.datasource.druid.max-open-prepared-statements = 100
# 设置SQL的执行超时时间,单位:秒。当SQL超时会直接被取消掉并且抛出QLTimeoutException异常。底层调用jdbc Statement对象的void setQueryTimeout(int seconds)方法
spring.datasource.druid.validation-query-timeout = -1
# 用来检测连接是否有效的sql,要求是一个查询语句。如果validationQuery为null,testOnBorrow、testOnReturn、testWhileIdle都不会起作用
spring.datasource.druid.validation-query = SELECT NOW()
# 申请连接时执行validationQuery检测连接是否有效,做了这个配置会降低性能。
spring.datasource.druid.test-on-borrow = false
# 归还连接时执行validationQuery检测连接是否有效,做了这个配置会降低性能。
spring.datasource.druid.test-on-return = false
# 申请连接的时候检测,如果空闲时间大于timeBetweenEvictionRunsMillis,执行validationQuery检测连接是否有效。建议配置为true,不影响性能,并且保证安全性。
spring.datasource.druid.test-while-idle = true
# 连接池中的minIdle数量以内的连接,空闲时间超过minEvictableIdleTimeMillis,则会执行keepAlive操作。
spring.datasource.druid.keep-alive = true
# 执行查询的超时时间(秒),执行Statement对象时如果超过此时间,则抛出SQLException
spring.datasource.druid.query-timeout = 5
# 执行一个事务的超时时间(秒),执行Statement对象时判断是否为事务,如果是且此项未设置,则使用queryTimeout
spring.datasource.druid.transaction-query-timeout = 10
#有两个含义:
# 1) Destroy线程会检测连接的间隔时间,如果连接空闲时间大于等于minEvictableIdleTimeMillis则关闭物理连接。
# 2) testWhileIdle的判断依据,详细看testWhileIdle属性的说明
spring.datasource.druid.time-between-eviction-runs-millis = 45000
# spring.druid.time-between-log-stats-millis = 1000
# 连接保持空闲而不被驱逐的最小时间 (30*60*1000=30分钟)
spring.datasource.druid.min-evictable-idle-time-millis = 90000
# 每隔timeBetweenEvictionRunsMillis进行一次shrink(连接池大小收缩),shrink之后检测是否强制关闭连接时长大于removeAbandonedTimeoutMillis的连接
spring.datasource.druid.remove-abandoned = true
# 一个连接从被连接到被关闭之间的最大生命周期
spring.datasource.druid.remove-abandoned-timeout = 1800
# spring.druid.filters = #配置多个英文逗号分隔
# 监控配置
spring.datasource.druid.filter.stat.log-slow-sql = true
spring.datasource.druid.filter.stat.slow-sql-millis = 1000
#mybatis配置
mybatis-plus.mapperLocations = classpath*:**/mapper/**/*Mapper.xml
mybatis-plus.configuration.log-impl = org.apache.ibatis.logging.stdout.StdOutImpl
#eureka配置
eureka.client.serviceUrl.defaultZone = http://10.197.236.100:8761/eureka
eureka.client.healthcheck.enabled = true
eureka.instance.lease-renewal-interval-in-seconds = 5
eureka.instance.lease-expiration-duration-in-seconds = 10
eureka.instance.preferIpAddress = false
eureka.instance.instance-id = ${eureka.instance.hostname}:${spring.application.name}:${server.port}
# 应用ID(在Apollo服务端新增项目添加的应用ID)
app:
id: park
# apollo-configService地址
apollo:
meta: http://10.197.236.187:7070
bootstrap:
enabled: true
namespaces: Java.park-eureka,Java.park-redis,Java.park-feign,Java.park-mysql,extend
eagerLoad:
enabled: true
\ No newline at end of file
# 应用ID(在Apollo服务端新增项目添加的应用ID)
app:
id: park
# apollo-configService地址
apollo:
meta: http://10.197.236.187:7070
bootstrap:
enabled: true
namespaces: Java.park-local-eureka,Java.park-redis,Java.park-feign,Java.park-mysql,extend
eagerLoad:
enabled: true
\ No newline at end of file
spring.profiles.active=dev
spring.application.name=park
...@@ -44,6 +44,26 @@ ...@@ -44,6 +44,26 @@
<version>${hutoll.version}</version> <version>${hutoll.version}</version>
</dependency> </dependency>
<!--Apollo Start-->
<dependency>
<groupId>com.ctrip.framework.apollo</groupId>
<artifactId>apollo-client</artifactId>
<version>1.6.0</version>
</dependency>
<!--Apollo End-->
<!--多数据源支持 Start-->
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>dynamic-datasource-spring-boot-starter</artifactId>
<version>2.5.4</version>
</dependency>
<!--多数据源支持 End-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
</dependencies> </dependencies>
......
package com.hikcreate.edl.pub.web.mobile.infra.core.config;
import com.ctrip.framework.apollo.model.ConfigChangeEvent;
import com.ctrip.framework.apollo.spring.annotation.ApolloConfigChangeListener;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.context.scope.refresh.RefreshScope;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
/**
* @author zhaodong5
* @create 2019/10/21 17:47
*/
@Slf4j
@Component
public class RefreshConfig {
@Resource
private RefreshScope refreshScope;
@ApolloConfigChangeListener(value = {"extend"})
public void onChange(ConfigChangeEvent changeEvent) {
refreshScope.refreshAll();
}
}
\ No newline at end of file
...@@ -11,7 +11,7 @@ import org.springframework.web.bind.annotation.RequestBody; ...@@ -11,7 +11,7 @@ import org.springframework.web.bind.annotation.RequestBody;
/** /**
* 短信feign * 短信feign
*/ */
@FeignClient( value = "${biz.feign.service.sms}", path = "sms" ) @FeignClient( value = "edl-pub-service-sms", path = "sms" )
public interface SmsFeign { public interface SmsFeign {
@PostMapping( {"send"} ) @PostMapping( {"send"} )
Result<Void> send( @RequestBody SendMicReq var1 ); Result<Void> send( @RequestBody SendMicReq var1 );
......
...@@ -20,11 +20,11 @@ ...@@ -20,11 +20,11 @@
<properties> <properties>
<java.version>1.8</java.version> <java.version>1.8</java.version>
<spring-cloud.version>Hoxton.SR5</spring-cloud.version> <spring-cloud.version>Hoxton.SR5</spring-cloud.version>
<appllo.version>1.6.0</appllo.version>
<mybatis.version>3.3.2</mybatis.version> <mybatis.version>3.3.2</mybatis.version>
<mysql.version>8.0.20</mysql.version> <mysql.version>5.1.46</mysql.version>
<hutoll.version>5.3.7</hutoll.version> <hutoll.version>5.3.7</hutoll.version>
<druid.version>1.1.22</druid.version> <druid.version>1.1.22</druid.version>
<apollo.version>1.6.0</apollo.version>
</properties> </properties>
<modules> <modules>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment