Commit 44822319 by 陈文顺

apollo

parent c78812d4
package com.freemud.springbootdemo;
import com.alibaba.fastjson.support.spring.FastJsonpHttpMessageConverter4;
import com.ctrip.framework.apollo.spring.annotation.EnableApolloConfig;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
......@@ -15,6 +16,7 @@ import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter
@ComponentScan(basePackages = "com.freemud, cn.freemud")
@MapperScan(basePackages = "com.freemud.demo.mapper")
//@EnableEurekaClient
@EnableApolloConfig
public class SpringbootDemoApplication extends WebMvcConfigurerAdapter{
public static void main(String[] args) {
......
package com.freemud.springbootdemo.config;
import com.alibaba.druid.pool.DruidDataSource;
import com.ctrip.framework.apollo.Config;
import com.ctrip.framework.apollo.spring.annotation.ApolloConfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
......@@ -26,6 +28,11 @@ import java.util.stream.Collectors;
@Configuration
public class DataSourceConfig {
@ApolloConfig
private Config config;
@Bean
@Primary
@ConfigurationProperties(prefix = "datasource.druid")
......
package com.freemud.springbootdemo.config;
import com.ctrip.framework.apollo.model.ConfigChangeEvent;
import com.ctrip.framework.apollo.spring.annotation.ApolloConfigChangeListener;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.environment.EnvironmentChangeEvent;
import org.springframework.cloud.context.refresh.ContextRefresher;
import org.springframework.cloud.context.scope.refresh.RefreshScope;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
......@@ -25,11 +33,19 @@ import springfox.documentation.swagger2.annotations.EnableSwagger2;
*/
@Configuration
@EnableSwagger2
public class Swagger2 {
public class Swagger2 implements ApplicationContextAware {
private ApplicationContext applicationContext;
@Value("${swagger_enable:}")
String swaggerEnable;
@ApolloConfigChangeListener
public void onChange(ConfigChangeEvent changeEvent){
System.out.println(changeEvent.changedKeys());
}
@Bean
public Docket createRestApi() {
return new Docket(DocumentationType.SWAGGER_2)
......@@ -48,4 +64,9 @@ public class Swagger2 {
.version("1.0")
.build();
}
@Override
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
this.applicationContext = applicationContext;
}
}
spring:
application:
name: dictionary
redis:
# host: 10.20.10.212
host: 115.159.67.166
port: 5289
password: U252fnIDyfF1A1
database: 3
datasource:
initialize: false
server:
port: 9005
datasource:
druid:
url: jdbc:mysql://111.231.82.13:6630/dict?useUnicode=true&characterEncoding=utf8
driver-class: com.mysql.jdbc.Driver
username: yanfa
password: yqKjKHX.1:bv
initial-size: 1
min-idle: 1
max-active: 20
test-on-borrow: true
filters: stat
datasource2:
druid:
url: jdbc:mysql://111.231.82.13:6630/dict2?useUnicode=true&characterEncoding=utf8
driver-class: com.mysql.jdbc.Driver
username: yanfa
password: yqKjKHX.1:bv
initial-size: 1
min-idle: 1
max-active: 20
test-on-borrow: true
filters: stat
#mybatis
mybatis:
config-location: classpath:mybatis.xml
mapper-locations: classpath:mapper/*.xml
type-aliases-package: com.freemud.demo.model
#dao
mapper:
mappers: com.freemud.demo.util.MyMapper
not-empty: false
identity: MYSQL
# before: true
#pagehelper
pagehelper:
helper-dialect: mysql
reasonable: true
support-methods-arguments: true
params: count=countSql
#log
# redis:
## host: 10.20.10.212
# host: 115.159.67.166
# port: 5289
# password: U252fnIDyfF1A1
# database: 3
# datasource:
# initialize: false
#server:
# port: 9005
#datasource:
# druid:
# url: jdbc:mysql://111.231.82.13:6630/dict?useUnicode=true&characterEncoding=utf8
# driver-class: com.mysql.jdbc.Driver
# username: yanfa
# password: yqKjKHX.1:bv
# initial-size: 1
# min-idle: 1
# max-active: 20
# test-on-borrow: true
# filters: stat
#
#datasource2:
# druid:
# url: jdbc:mysql://111.231.82.13:6630/dict2?useUnicode=true&characterEncoding=utf8
# driver-class: com.mysql.jdbc.Driver
# username: yanfa
# password: yqKjKHX.1:bv
# initial-size: 1
# min-idle: 1
# max-active: 20
# test-on-borrow: true
# filters: stat
#
#
##mybatis
#mybatis:
# config-location: classpath:mybatis.xml
# mapper-locations: classpath:mapper/*.xml
# type-aliases-package: com.freemud.demo.model
#
##dao
#mapper:
# mappers: com.freemud.demo.util.MyMapper
# not-empty: false
# identity: MYSQL
## before: true
#
##pagehelper
#pagehelper:
# helper-dialect: mysql
# reasonable: true
# support-methods-arguments: true
# params: count=countSql
#
##log
logging:
config: classpath:logback.xml
......@@ -67,19 +67,19 @@ logging:
# password: admin
# ignored: /**,/swagger*,/webjars/**,/v2/**,/swagger-resources/**
swagger_enable: true
#swagger_enable: true
#eureka:
# client:
# service-url:
# defaultZone: http://localhost:10001/eureka
#apollo:
# bootstrap:
# enabled: true
# meta: http://localhost:8080
apollo:
bootstrap:
enabled: true
meta: http://localhost:8080
#apollo appId
#app:
# id: order_service
app:
id: order_service
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<springProperty scope="context"
name="springAppName"
source="spring.application.name"/>
<!-- %m输出的信息,%p日志级别,%t线程名,%d日期,%c类的全名,,,, -->
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<charset>UTF-8</charset>
<pattern>%d %p (%file:%line\)- %m%n</pattern>
</encoder>
</appender>
<appender name = "STDOUT_tid" class= "ch.qos.logback.core.ConsoleAppender" >
<layout class = "ch.qos.logback.classic.PatternLayout">
<!--<Pattern >%d{HH:mm} %-5level %logger{36} - [springAppName:${springAppName:-}, TxId : %X{X-B3-TraceId:-} , SpanId : %X{X-B3-SpanId:-}] %msg%n</Pattern >-->
<Pattern >%d{HH:mm} %-5level %logger{36} - [${springAppName}] %msg%n</Pattern >
</layout >
</appender >
<root level="info">
<appender-ref ref="STDOUT_tid"/>
</root>
</configuration>
\ No newline at end of file
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