Commit b80e53fd by 陈文顺

spring 升级

parent 44822319
...@@ -58,7 +58,7 @@ ...@@ -58,7 +58,7 @@
<dependency> <dependency>
<groupId>com.github.pagehelper</groupId> <groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper-spring-boot-starter</artifactId> <artifactId>pagehelper-spring-boot-starter</artifactId>
<version>${mapper.version}</version> <version>1.2.5</version>
</dependency> </dependency>
</dependencies> </dependencies>
......
...@@ -4,12 +4,12 @@ ...@@ -4,12 +4,12 @@
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<parent> <!--<parent>-->
<groupId>org.springframework.boot</groupId> <!--<groupId>org.springframework.boot</groupId>-->
<artifactId>spring-boot-starter-parent</artifactId> <!--<artifactId>spring-boot-starter-parent</artifactId>-->
<version>1.5.10.RELEASE</version> <!--<version>1.5.10.RELEASE</version>-->
<relativePath/> <!-- lookup parent from repository --> <!--<relativePath/> &lt;!&ndash; lookup parent from repository &ndash;&gt;-->
</parent> <!--</parent>-->
<groupId>com.freemud.demo</groupId> <groupId>com.freemud.demo</groupId>
<artifactId>spring-demo-parent</artifactId> <artifactId>spring-demo-parent</artifactId>
...@@ -27,16 +27,36 @@ ...@@ -27,16 +27,36 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version> <java.version>1.8</java.version>
<spring-cloud.version>Edgware.SR2</spring-cloud.version> <spring.boot.version>2.1.4.RELEASE</spring.boot.version>
<spring-cloud.version>Greenwich.SR1</spring-cloud.version>
<mybatis3.version>1.3.2</mybatis3.version> <mybatis3.version>1.3.2</mybatis3.version>
<mapper.version>1.1.1</mapper.version> <mapper.version>1.1.1</mapper.version>
<elasticSearch.version>3.1.5.RELEASE</elasticSearch.version> <elasticSearch.version>3.1.5.RELEASE</elasticSearch.version>
<maven.compiler.source>${java.version}</maven.compiler.source>
<maven.compiler.target>${java.version}</maven.compiler.target>
<mysql.version>5.1.43</mysql.version>
</properties> </properties>
<dependencyManagement> <dependencyManagement>
<dependencies> <dependencies>
<dependency> <dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>${spring.boot.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>io.springfox</groupId> <groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId> <artifactId>springfox-swagger2</artifactId>
<version>2.7.0</version> <version>2.7.0</version>
......
...@@ -67,9 +67,20 @@ ...@@ -67,9 +67,20 @@
<dependency> <dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId> <artifactId>spring-boot-starter-web</artifactId>
<!--<exclusions>-->
<!--<exclusion>-->
<!--<groupId>org.springframework.boot</groupId>-->
<!--<artifactId>spring-boot-starter-tomcat</artifactId>-->
<!--</exclusion>-->
<!--</exclusions>-->
</dependency> </dependency>
<!--<dependency>--> <!--<dependency>-->
<!--<groupId>org.springframework.boot</groupId>-->
<!--<artifactId>spring-boot-starter-jetty</artifactId>-->
<!--</dependency>-->
<!--<dependency>-->
<!--<groupId>org.springframework.data</groupId>--> <!--<groupId>org.springframework.data</groupId>-->
<!--<artifactId>spring-data-elasticsearch</artifactId>--> <!--<artifactId>spring-data-elasticsearch</artifactId>-->
<!--</dependency>--> <!--</dependency>-->
...@@ -135,7 +146,7 @@ ...@@ -135,7 +146,7 @@
<dependency> <dependency>
<groupId>com.ctrip.framework.apollo</groupId> <groupId>com.ctrip.framework.apollo</groupId>
<artifactId>apollo-client</artifactId> <artifactId>apollo-client</artifactId>
<version>1.1.0</version> <version>1.4.0</version>
</dependency> </dependency>
<dependency> <dependency>
...@@ -152,6 +163,14 @@ ...@@ -152,6 +163,14 @@
<plugin> <plugin>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId> <artifactId>spring-boot-maven-plugin</artifactId>
<version>${spring.boot.version}</version>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin> </plugin>
</plugins> </plugins>
</build> </build>
......
...@@ -16,7 +16,7 @@ import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter ...@@ -16,7 +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 //@EnableApolloConfig
public class SpringbootDemoApplication extends WebMvcConfigurerAdapter{ public class SpringbootDemoApplication extends WebMvcConfigurerAdapter{
public static void main(String[] args) { public static void main(String[] args) {
......
...@@ -3,24 +3,17 @@ package com.freemud.springbootdemo.config; ...@@ -3,24 +3,17 @@ 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.Config;
import com.ctrip.framework.apollo.spring.annotation.ApolloConfig; 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.boot.autoconfigure.jdbc.DataSourceBuilder;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.jdbc.DataSourceBuilder;
import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.jdbc.DataSourceBuilder;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.context.ApplicationContext;
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 org.springframework.context.annotation.Primary; import org.springframework.context.annotation.Primary;
import org.springframework.core.io.Resource;
import javax.sql.DataSource; import javax.sql.DataSource;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.stream.Collectors;
/** /**
* Created by chenwenshun on 2018/8/31. * Created by chenwenshun on 2018/8/31.
...@@ -28,13 +21,15 @@ import java.util.stream.Collectors; ...@@ -28,13 +21,15 @@ import java.util.stream.Collectors;
@Configuration @Configuration
public class DataSourceConfig { public class DataSourceConfig {
private ApplicationContext applicationContext;
@ApolloConfig @ApolloConfig
private Config config; private Config config;
@Bean @Bean
@Primary @Primary
@RefreshScope
@ConfigurationProperties(prefix = "datasource.druid") @ConfigurationProperties(prefix = "datasource.druid")
public DataSource dataSource_0(){ public DataSource dataSource_0(){
return DataSourceBuilder.create() return DataSourceBuilder.create()
......
...@@ -2,8 +2,10 @@ package com.freemud.springbootdemo.config; ...@@ -2,8 +2,10 @@ package com.freemud.springbootdemo.config;
import com.ctrip.framework.apollo.model.ConfigChangeEvent; import com.ctrip.framework.apollo.model.ConfigChangeEvent;
import com.ctrip.framework.apollo.spring.annotation.ApolloConfigChangeListener; import com.ctrip.framework.apollo.spring.annotation.ApolloConfigChangeListener;
import com.ctrip.framework.apollo.spring.annotation.EnableApolloConfig;
import org.springframework.beans.BeansException; import org.springframework.beans.BeansException;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.cloud.context.environment.EnvironmentChangeEvent; import org.springframework.cloud.context.environment.EnvironmentChangeEvent;
import org.springframework.cloud.context.refresh.ContextRefresher; import org.springframework.cloud.context.refresh.ContextRefresher;
import org.springframework.cloud.context.scope.refresh.RefreshScope; import org.springframework.cloud.context.scope.refresh.RefreshScope;
...@@ -11,6 +13,7 @@ import org.springframework.context.ApplicationContext; ...@@ -11,6 +13,7 @@ import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware; 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 org.springframework.context.annotation.Scope;
import springfox.documentation.builders.ApiInfoBuilder; import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors; import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors; import springfox.documentation.builders.RequestHandlerSelectors;
...@@ -35,17 +38,23 @@ import springfox.documentation.swagger2.annotations.EnableSwagger2; ...@@ -35,17 +38,23 @@ import springfox.documentation.swagger2.annotations.EnableSwagger2;
@EnableSwagger2 @EnableSwagger2
public class Swagger2 implements ApplicationContextAware { public class Swagger2 implements ApplicationContextAware {
private final RefreshScope refreshScope;
private ApplicationContext applicationContext; private ApplicationContext applicationContext;
@Value("${swagger_enable:}") @Value("${swagger_enable:}")
String swaggerEnable; String swaggerEnable;
@ApolloConfigChangeListener public Swagger2(RefreshScope refreshScope) {
this.refreshScope = refreshScope;
}
@ApolloConfigChangeListener(interestedKeys = {"swagger_enable"})
public void onChange(ConfigChangeEvent changeEvent){ 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)
......
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-test.xml
#security: #security:
...@@ -76,10 +76,10 @@ logging: ...@@ -76,10 +76,10 @@ logging:
apollo: apollo:
bootstrap: bootstrap:
enabled: true enabled: true
meta: http://localhost:8080 meta: http://212.129.229.203
#apollo appId #apollo appId
app: app:
id: order_service id: dictionary
...@@ -15,7 +15,8 @@ ...@@ -15,7 +15,8 @@
<appender name = "STDOUT_tid" class= "ch.qos.logback.core.ConsoleAppender" > <appender name = "STDOUT_tid" class= "ch.qos.logback.core.ConsoleAppender" >
<layout class = "ch.qos.logback.classic.PatternLayout"> <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:${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 > <!--<Pattern >%d{HH:mm:ss.SSS} %-5level %logger{36} - [${springAppName}] %msg%n</Pattern >-->
<Pattern >%date %level [%thread] %logger{10} [%file:%line] - %msg%n</Pattern >
</layout > </layout >
</appender > </appender >
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
<appender name = "STDOUT_tid" class= "ch.qos.logback.core.ConsoleAppender" > <appender name = "STDOUT_tid" class= "ch.qos.logback.core.ConsoleAppender" >
<layout class = "ch.qos.logback.classic.PatternLayout"> <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:${springAppName:-}, TxId : %X{X-B3-TraceId:-} , SpanId : %X{X-B3-SpanId:-}] %msg%n</Pattern >-->
<Pattern >%d{HH:mm} %-5level %logger{36} - [spring-demo,%X{X-B3-TraceId:-},%X{X-B3-SpanId:-}] %msg%n</Pattern > <Pattern >%d{HH:mm:ss.SSS} %-5level %logger{36} - [spring-demo,%X{X-B3-TraceId:-},%X{X-B3-SpanId:-}] %msg%n</Pattern >
</layout > </layout >
</appender > </appender >
......
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