Commit 44822319 by 陈文顺

apollo

parent c78812d4
package com.freemud.springbootdemo; package com.freemud.springbootdemo;
import com.alibaba.fastjson.support.spring.FastJsonpHttpMessageConverter4; import com.alibaba.fastjson.support.spring.FastJsonpHttpMessageConverter4;
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;
...@@ -15,6 +16,7 @@ import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter ...@@ -15,6 +16,7 @@ import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter
@ComponentScan(basePackages = "com.freemud, cn.freemud") @ComponentScan(basePackages = "com.freemud, cn.freemud")
@MapperScan(basePackages = "com.freemud.demo.mapper") @MapperScan(basePackages = "com.freemud.demo.mapper")
//@EnableEurekaClient //@EnableEurekaClient
@EnableApolloConfig
public class SpringbootDemoApplication extends WebMvcConfigurerAdapter{ public class SpringbootDemoApplication extends WebMvcConfigurerAdapter{
public static void main(String[] args) { public static void main(String[] args) {
......
package com.freemud.springbootdemo.config; package com.freemud.springbootdemo.config;
import com.alibaba.druid.pool.DruidDataSource; 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.Autowired;
import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
...@@ -26,6 +28,11 @@ import java.util.stream.Collectors; ...@@ -26,6 +28,11 @@ import java.util.stream.Collectors;
@Configuration @Configuration
public class DataSourceConfig { public class DataSourceConfig {
@ApolloConfig
private Config config;
@Bean @Bean
@Primary @Primary
@ConfigurationProperties(prefix = "datasource.druid") @ConfigurationProperties(prefix = "datasource.druid")
......
package com.freemud.springbootdemo.config; 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.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.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder; import springfox.documentation.builders.ApiInfoBuilder;
...@@ -25,11 +33,19 @@ import springfox.documentation.swagger2.annotations.EnableSwagger2; ...@@ -25,11 +33,19 @@ import springfox.documentation.swagger2.annotations.EnableSwagger2;
*/ */
@Configuration @Configuration
@EnableSwagger2 @EnableSwagger2
public class Swagger2 { public class Swagger2 implements ApplicationContextAware {
private ApplicationContext applicationContext;
@Value("${swagger_enable:}") @Value("${swagger_enable:}")
String swaggerEnable; String swaggerEnable;
@ApolloConfigChangeListener
public void onChange(ConfigChangeEvent changeEvent){
System.out.println(changeEvent.changedKeys());
}
@Bean @Bean
public Docket createRestApi() { public Docket createRestApi() {
return new Docket(DocumentationType.SWAGGER_2) return new Docket(DocumentationType.SWAGGER_2)
...@@ -48,4 +64,9 @@ public class Swagger2 { ...@@ -48,4 +64,9 @@ public class Swagger2 {
.version("1.0") .version("1.0")
.build(); .build();
} }
@Override
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
this.applicationContext = applicationContext;
}
} }
spring: spring:
application: application:
name: dictionary name: dictionary
redis: # redis:
# host: 10.20.10.212 ## host: 10.20.10.212
host: 115.159.67.166 # host: 115.159.67.166
port: 5289 # port: 5289
password: U252fnIDyfF1A1 # password: U252fnIDyfF1A1
database: 3 # database: 3
datasource: # datasource:
initialize: false # initialize: false
server: #server:
port: 9005 # port: 9005
datasource: #datasource:
druid: # druid:
url: jdbc:mysql://111.231.82.13:6630/dict?useUnicode=true&characterEncoding=utf8 # url: jdbc:mysql://111.231.82.13:6630/dict?useUnicode=true&characterEncoding=utf8
driver-class: com.mysql.jdbc.Driver # driver-class: com.mysql.jdbc.Driver
username: yanfa # username: yanfa
password: yqKjKHX.1:bv # password: yqKjKHX.1:bv
initial-size: 1 # initial-size: 1
min-idle: 1 # min-idle: 1
max-active: 20 # max-active: 20
test-on-borrow: true # test-on-borrow: true
filters: stat # filters: stat
#
datasource2: #datasource2:
druid: # druid:
url: jdbc:mysql://111.231.82.13:6630/dict2?useUnicode=true&characterEncoding=utf8 # url: jdbc:mysql://111.231.82.13:6630/dict2?useUnicode=true&characterEncoding=utf8
driver-class: com.mysql.jdbc.Driver # driver-class: com.mysql.jdbc.Driver
username: yanfa # username: yanfa
password: yqKjKHX.1:bv # password: yqKjKHX.1:bv
initial-size: 1 # initial-size: 1
min-idle: 1 # min-idle: 1
max-active: 20 # max-active: 20
test-on-borrow: true # test-on-borrow: true
filters: stat # filters: stat
#
#
#mybatis ##mybatis
mybatis: #mybatis:
config-location: classpath:mybatis.xml # config-location: classpath:mybatis.xml
mapper-locations: classpath:mapper/*.xml # mapper-locations: classpath:mapper/*.xml
type-aliases-package: com.freemud.demo.model # type-aliases-package: com.freemud.demo.model
#
#dao ##dao
mapper: #mapper:
mappers: com.freemud.demo.util.MyMapper # mappers: com.freemud.demo.util.MyMapper
not-empty: false # not-empty: false
identity: MYSQL # identity: MYSQL
# before: true ## before: true
#
#pagehelper ##pagehelper
pagehelper: #pagehelper:
helper-dialect: mysql # helper-dialect: mysql
reasonable: true # reasonable: true
support-methods-arguments: true # support-methods-arguments: true
params: count=countSql # params: count=countSql
#
#log ##log
logging: logging:
config: classpath:logback.xml config: classpath:logback.xml
...@@ -67,19 +67,19 @@ logging: ...@@ -67,19 +67,19 @@ logging:
# password: admin # password: admin
# ignored: /**,/swagger*,/webjars/**,/v2/**,/swagger-resources/** # ignored: /**,/swagger*,/webjars/**,/v2/**,/swagger-resources/**
swagger_enable: true #swagger_enable: true
#eureka: #eureka:
# client: # client:
# service-url: # service-url:
# defaultZone: http://localhost:10001/eureka # defaultZone: http://localhost:10001/eureka
#apollo: apollo:
# bootstrap: bootstrap:
# enabled: true enabled: true
# meta: http://localhost:8080 meta: http://localhost:8080
#apollo appId #apollo appId
#app: app:
# id: order_service 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