Commit 1b7d4878 by 陈文顺

spring 升级

parent 8ac63f3e
...@@ -93,5 +93,13 @@ ...@@ -93,5 +93,13 @@
</dependencies> </dependencies>
<!--<repositories>-->
<!--<repository>-->
<!--<id>central</id>-->
<!--<url>http://maven.aliyun.com/nexus/content/groups/public/</url>-->
<!--</repository>-->
<!--</repositories>-->
</project> </project>
\ No newline at end of file
from ccr.ccs.tencentyun.com/freemuddockernamespace/centos:jdk-8-cat-prod
MAINTAINER from freemud.cn by chengjun.ding (chengjun.ding@freemud.cn)
ADD target/a.jar /home/coupon/
mkdir -p /home/coupon /data
ENV JAVA_OPTS=""
ENV CAT_NAME=""
EXPOSE serverport
ENTRYPOINT [ "sh", "-c", "java -server -Xmx1g -Xms1g -XX:ParallelGCThreads=10 -XX:+UseG1GC -XX:CompileThreshold=100 -jar -Dspring.profiles.active=envprofile /home/coupon/a.jar" ]
...@@ -18,7 +18,7 @@ import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter ...@@ -18,7 +18,7 @@ import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter
@MapperScan(basePackages = "com.freemud.demo.mapper") @MapperScan(basePackages = "com.freemud.demo.mapper")
@EnableEurekaClient @EnableEurekaClient
//@EnableApolloConfig //@EnableApolloConfig
public class SpringbootDemoApplication extends WebMvcConfigurerAdapter{ public class SpringbootDemoApplication implements WebMvcConfigurer{
public static void main(String[] args) { public static void main(String[] args) {
SpringApplication.run(SpringbootDemoApplication.class, args); SpringApplication.run(SpringbootDemoApplication.class, args);
......
...@@ -31,10 +31,11 @@ public class ApolloConfig implements ApplicationContextAware { ...@@ -31,10 +31,11 @@ public class ApolloConfig implements ApplicationContextAware {
@com.ctrip.framework.apollo.spring.annotation.ApolloConfig @com.ctrip.framework.apollo.spring.annotation.ApolloConfig
private Config config; private Config config;
@ApolloConfigChangeListener @ApolloConfigChangeListener({"application", "application.yml"})
public void onChange(ConfigChangeEvent configChangeEvent){ public void onChange(ConfigChangeEvent configChangeEvent){
log.info("apollo change keys {}", configChangeEvent.changedKeys()); log.info("apollo change keys {}", configChangeEvent.changedKeys());
refreshProperties(configChangeEvent); boolean result = refreshScope.refresh("sampleConfig");
// refreshProperties(configChangeEvent);
} }
@Override @Override
......
package com.freemud.springbootdemo.config;
import com.freemud.demo.dto.ResDto;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.MethodParameter;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.server.ServerHttpRequest;
import org.springframework.http.server.ServerHttpResponse;
import org.springframework.lang.Nullable;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import org.springframework.web.servlet.mvc.method.annotation.ResponseBodyAdvice;
/**
* Created by chenwenshun on 2019/8/22.
*/
//@RestControllerAdvice
public class ResultResponseAdvice implements ResponseBodyAdvice<Object> {
@Override
public boolean supports(MethodParameter returnType, Class<? extends HttpMessageConverter<?>> converterType) {
if (returnType.getNestedParameterType().isAssignableFrom(ResponseEntity.class)){
return false;
}
return true;
}
@Nullable
@Override
public Object beforeBodyWrite(@Nullable Object body, MethodParameter returnType, MediaType selectedContentType, Class<? extends HttpMessageConverter<?>> selectedConverterType, ServerHttpRequest request, ServerHttpResponse response) {
if (body instanceof ResDto){
return body;
}
return new ResDto(body);
}
}
package com.freemud.springbootdemo.config;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.context.annotation.Configuration;
/**
* Created by chenwenshun on 2019/8/23.
*/
@Configuration
@ConfigurationProperties(prefix = "sample.config")
@RefreshScope
@Data
public class SampleConfig {
String aaa;
String bbb;
}
package com.freemud.springbootdemo.controller;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.context.request.async.DeferredResult;
import java.util.Random;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
/**
* Created by chenwenshun on 2019/8/27.
*/
@RestController
public class DeferredController {
private ExecutorService fixed_thread_pool = Executors.newFixedThreadPool(10);
Random random = new Random();
@RequestMapping(value = "/deferredresult", method = RequestMethod.GET)
public DeferredResult<ResponseEntity<String>> deferredResult() throws Exception{
DeferredResult deferredResult = new DeferredResult<ResponseEntity<String>>(5 * 1000L, new ResponseEntity<String>(HttpStatus.NOT_MODIFIED));
deferredResult.onTimeout(() -> {
System.out.printf("异步线程执行超时");
// deferredResult.setResult("线程执行超时");
// deferredResult.setResult(new ResponseEntity<String>("time out!",HttpStatus.NOT_MODIFIED));
});
deferredResult.onCompletion(() -> {
System.out.println("异步执行完毕");
});
fixed_thread_pool.execute(() -> {
try {
TimeUnit.SECONDS.sleep(random.nextInt(10));
deferredResult.setResult(new ResponseEntity<>("ok ok ok", HttpStatus.OK));
} catch (InterruptedException e) {
e.printStackTrace();
}
});
return deferredResult;
}
}
package com.freemud.springbootdemo.controller; package com.freemud.springbootdemo.controller;
import com.ctrip.framework.apollo.ConfigService;
import com.freemud.demo.cache.DictRedisCache; import com.freemud.demo.cache.DictRedisCache;
import com.freemud.demo.dto.*; import com.freemud.demo.dto.*;
import com.freemud.demo.service.IDictTypeService; import com.freemud.demo.service.IDictTypeService;
import com.freemud.springbootdemo.config.ApolloConfig;
import com.freemud.springbootdemo.config.SampleConfig;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.env.Environment;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List; import java.util.List;
/** /**
...@@ -39,20 +46,26 @@ public class DictController { ...@@ -39,20 +46,26 @@ public class DictController {
} }
@Value("${server.port}")
String serverPort;
@ApiOperation("typeCd获取字典数据") @ApiOperation("typeCd获取字典数据")
@GetMapping( value = "/dictDatas/{dictTypeCd}") @GetMapping( value = "/dictDatas/{dictTypeCd}")
public ResDto dictDatas(@PathVariable String dictTypeCd){ public ResDto dictDatas(@PathVariable String dictTypeCd){
SimpleDateFormat formatter = new SimpleDateFormat("yyyy.MM.dd hh:mm:ss:SSS");
List<DictDataDto> list = this.dictTypeService.loadDatasByTypeCd(dictTypeCd,true); List<DictDataDto> list = this.dictTypeService.loadDatasByTypeCd(dictTypeCd,true);
return new ResDto(list); ResDto resDto = new ResDto(list);
resDto.setMsg(String.format("==================>%s %s " , formatter.format(new Date()) , serverPort));
return resDto;
} }
@ApiOperation("typeCd & dataCd获取字典数据") @ApiOperation("typeCd & dataCd获取字典数据")
@GetMapping("/dictData/{dictTypeCd}/{dictCd}") @GetMapping("/dictData/{dictTypeCd}/{dictCd}")
public ResDto<DictDataDto> dictData(@PathVariable String dictTypeCd ,@PathVariable String dictCd){ public DictDataDto dictData(@PathVariable String dictTypeCd ,@PathVariable String dictCd){
DictDataDto dictDataDto = this.dictTypeService.loadDictDataByCd(dictTypeCd,dictCd,true); DictDataDto dictDataDto = this.dictTypeService.loadDictDataByCd(dictTypeCd,dictCd,true);
return new ResDto(dictDataDto); return dictDataDto;
} }
...@@ -85,6 +98,16 @@ public class DictController { ...@@ -85,6 +98,16 @@ public class DictController {
return new ResDto(); return new ResDto();
} }
@Autowired
Environment environment;
@GetMapping("/testGray")
public ResDto delete(){
ResDto resDto = new ResDto();
resDto.setMsg(environment.getProperty("server.port"));
return resDto;
}
......
...@@ -13,7 +13,7 @@ server: ...@@ -13,7 +13,7 @@ server:
port: 9005 port: 9005
datasource: datasource:
druid: druid:
url: jdbc:mysql://10.30.30.14: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
...@@ -41,6 +41,8 @@ mybatis: ...@@ -41,6 +41,8 @@ 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
configuration:
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
#dao #dao
mapper: mapper:
...@@ -55,8 +57,8 @@ pagehelper: ...@@ -55,8 +57,8 @@ pagehelper:
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 +69,32 @@ logging: ...@@ -67,19 +69,32 @@ 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
defaultZone: http://freemud:freemud123@111.231.12.200:9130/eureka/
instance:
instance-id: ${spring.cloud.client.ip-address}:${server.port}
#apollo: apollo:
# bootstrap: bootstrap:
enabled: true
# eager-load:
# enabled: true # enabled: true
# meta: http://localhost:8080 namespaces: application,architect.common,application.yml
meta: http://public-apollo-configservice-pro.freemud-big-platform.svc:8080
#apollo appId #apollo appId
#app: app:
# id: order_service id: dictionary
management:
endpoints:
web:
exposure:
include: service-registry
endpoint:
shutdown:
enabled: true
\ No newline at end of file
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: 9006
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-test1.xml
#security:
# user:
# name: admin
# password: admin
# ignored: /**,/swagger*,/webjars/**,/v2/**,/swagger-resources/**
#swagger_enable: true
eureka:
client:
service-url:
defaultZone: http://localhost:10001/eureka
instance:
metadata-map:
weight: 10
# defaultZone: http://freemud:freemud123@111.231.12.200:9130/eureka
apollo:
bootstrap:
enabled: true
namespaces: application,architect.common
meta: http://172.81.231.147
#apollo appId
app:
id: dictionary
...@@ -58,7 +58,7 @@ pagehelper: ...@@ -58,7 +58,7 @@ pagehelper:
# #
##log ##log
logging: logging:
config: classpath:logback-test.xml config: classpath:logback-test1.xml
#security: #security:
...@@ -71,17 +71,31 @@ logging: ...@@ -71,17 +71,31 @@ logging:
eureka: eureka:
client: client:
service-url: service-url:
defaultZone: http://localhost:9528/eureka # defaultZone: http://localhost:10001/eureka
defaultZone: http://freemud:freemud123@111.231.12.200:9130/eureka/
instance:
instance-id: ${spring.cloud.client.ip-address}:${server.port}
apollo: apollo:
bootstrap: bootstrap:
enabled: true enabled: true
namespaces: application,architect.common # eager-load:
# enabled: true
namespaces: application,architect.common,application.yml
meta: http://172.81.231.147 meta: http://172.81.231.147
#apollo appId #apollo appId
app: app:
id: dictionary id: dictionary
management:
endpoints:
web:
exposure:
include: service-registry
endpoint:
shutdown:
enabled: true
......
<?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:ss.SSS} %-5level %logger{36} - [${springAppName}] %msg%n</Pattern >-->
<Pattern >%date %level [%thread] %logger{10} [%file:%line] - %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