作者 朱兆平

spring boot admin 应用监控 & zipkin 调用链监控

springboot与cloud版本适配优化
... ... @@ -74,5 +74,5 @@ Class-Path: connector.jar druid-spring-boot-starter-1.1.9.jar spring-b
.0.BUILD-20190114.050029-1386.jar jersey-client-1.19.1.jar joda-time-
2.10.1.jar com.ibm.mq.jmqi.jar eureka-client-1.9.8.jar compactmap-1.2
.1.jar spring-core-5.1.4.RELEASE.jar spring-beans-5.1.4.RELEASE.jar
Main-Class: com.tianbo.warehouse.WarehouseApplication
Main-Class: com.tianbo.warehouse.BootApplication
... ...
... ... @@ -6,18 +6,28 @@ server:
servlet:
context-path: ${SERVER_CONTEXTPATH:}
spring:
devtools:
add-properties: false
profiles:
active: dev
mvc:
#静态资源,设置上传文件的访问,
static-path-pattern: /**
boot:
admin:
client:
url: http://192.168.1.63:16666
password: vmvnv1v2
zipkin:
base-url: http://192.168.1.63:9411
sleuth:
sampler:
probability: 0.1
resources:
static-locations: classpath:/META-INF/resources/,classpath:/static,classpath:/resources/,file:${web.upload-path}
application:
name: hqpt-user-center
name: cloud-user-centerV2
redis:
host: 192.168.1.53
# host: 192.168.43.78
... ... @@ -54,11 +64,7 @@ spring:
url: jdbc:mysql://118.31.66.166:3306/HQPT_USER?useUnicode=true&characterEncoding=utf8
username: 110
password: QAHqCJf2kFYCLirM
driver-class-name: com.mysql.jdbc.Driver
max-idle: 10
max-wait: 10000
min-idle: 5
initial-size: 5
driver-class-name: com.mysql.cj.jdbc.Driver
#配置初始化大小/最小/最大
druid:
initial-size: 1
... ... @@ -78,6 +84,11 @@ spring:
test-on-borrow: false
test-on-return: false
default-auto-commit: true
# tomcat:
# max-wait: 10
# max-idle: 10000
# min-idle: 5
# initial-size: 5
eureka:
instance:
... ... @@ -86,17 +97,29 @@ eureka:
prefer-ip-address: true
instance-id: ${spring.cloud.client.ip-address}:${server.port}
hostname: ${spring.cloud.client.ip-address}
lease-renewal-interval-in-seconds: 15
lease-expiration-duration-in-seconds: 45
client:
#eureka注册中心服务器地址
service-url:
# defaultZone: http://127.0.0.1:12345/eureka/
defaultZone: http://192.168.1.53:12345/eureka/
# defaultZone: http://192.168.43.78:12345/eureka/
registry-fetch-interval-seconds: 30
lease-renewal-interval-in-seconds: 15
lease-expiration-duration-in-seconds: 45
management:
endpoints:
enabled-by-default: true
web:
exposure:
include: ["*"]
endpoint:
health:
show-details: always
shutdown:
enabled: true
mybatis:
mapper-locations: classpath:mapping/*.xml
type-aliases-package: com.tianbo.warehouse.model
... ...
... ... @@ -25,7 +25,7 @@
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
<!--此日志appender是为开发使用,只配置最底级别,控制台输出的日志级别是大于或等于此级别的日志信息-->
<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
<level>trace</level>
<level>INFO</level>
</filter>
<encoder>
<Pattern>${CONSOLE_LOG_PATTERN}</Pattern>
... ...
FROM java:8u111
VOLUME /tmp
ADD /target/warehouse-0.0.1-SNAPSHOT.jar app.jar
EXPOSE 8002
ENTRYPOINT ["java","-jar","/app.jar"]
# Ubuntu 时区
RUN cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
\ No newline at end of file
... ...
... ... @@ -6,7 +6,7 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.0.BUILD-SNAPSHOT</version>
<version>2.1.9.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.tianbo</groupId>
... ... @@ -17,7 +17,7 @@
<properties>
<java.version>1.8</java.version>
<spring-cloud.version>Greenwich.BUILD-SNAPSHOT</spring-cloud.version>
<spring-cloud.version>Greenwich.SR3</spring-cloud.version>
<fastjson_version>1.2.28</fastjson_version>
<lombok_sersion>1.18.6</lombok_sersion>
<swagger2_version>2.9.2</swagger2_version>
... ... @@ -38,6 +38,7 @@
<!--<groupId>org.springframework.boot</groupId>-->
<!--<artifactId>spring-boot-devtools</artifactId>-->
<!--<optional>true</optional>-->
<!--<scope>runtime</scope>-->
<!--</dependency>-->
<!--有WEBSOCKET包 包含了spring-boot-starter-web 和spring-boot-starter包 有这个包不要引入这俩包-->
<dependency>
... ... @@ -59,10 +60,10 @@
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
<!--<dependency>-->
<!--<groupId>org.springframework.boot</groupId>-->
<!--<artifactId>spring-boot-starter-thymeleaf</artifactId>-->
<!--</dependency>-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>io.jsonwebtoken</groupId>
<artifactId>jjwt</artifactId>
... ... @@ -204,6 +205,20 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-zipkin</artifactId>
</dependency>
<dependency>
<groupId>de.codecentric</groupId>
<artifactId>spring-boot-admin-starter-client</artifactId>
<version>2.1.6</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
</dependencies>
... ... @@ -226,6 +241,7 @@
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<includeSystemScope>true</includeSystemScope>
<fork>true</fork>
</configuration>
</plugin>
<!-- mybatis generator 自动生成代码插件 -->
... ... @@ -239,6 +255,23 @@
<verbose>true</verbose>
</configuration>
</plugin>
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<id>gen-webadmin</id>
<phase>package</phase>
<configuration>
<tasks>
<copy todir="docker" file="target/${project.artifactId}-${project.version}.${project.packaging}" />
</tasks>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
... ...
... ... @@ -26,6 +26,8 @@
* 前后端完全分离
* 前端登录验证后,每次访问系统通过在头部携带带有JWT token的Authorization:Bearer "Tokens字符窜"访问系统
* 相关集成资料 [SpringBoot使用SpringSecurity搭建基于非对称加密的JWT及前后端分离的搭建](https://blog.csdn.net/lhc0512/article/details/80563160)
* 集成spring cloud gateway
* 路由识别及访问权限放在gateway里面处理
* 已集成mybatis、mybatisGenerator、pageHelper
* 集成定时任务框架
* 目前在IMF框架中使用,打开IMF_Task里面的定时任务注释就可以启动IMF客户端功能
... ... @@ -34,4 +36,6 @@
* 集成lombok,简化部分代码录入,比如实体类,方便实体及表结构修改,敏捷开发必用,使用方法见[lombok集成使用说明](https://jingyan.baidu.com/article/0a52e3f4e53ca1bf63ed725c.html)
)
* 集成了单文件、多文件上传接口
* 集成了swagger2,开发环境开启此POM配置,生产环境记得去掉。包冲突问题看POM配置文件注释。[接口访问测试地址](http://localhost:7003/swagger-ui.html)
\ No newline at end of file
* 集成了swagger2,开发环境开启此POM配置,生产环境记得去掉。包冲突问题看POM配置文件注释。[接口访问测试地址](http://localhost:7003/swagger-ui.html)
* 集成spring boot admin 应用监控 & zipkin 调用链监控
... ...
Manifest-Version: 1.0
Class-Path: thymeleaf-extras-java8time-3.0.4.RELEASE.jar springfox-swa
gger-common-2.9.2.jar commons-math-2.2.jar attoparser-2.0.5.RELEASE.j
ar spring-cloud-netflix-eureka-client-2.1.5.BUILD-20191219.032215-243
.jar netty-buffer-4.1.42.Final.jar bcpkix-jdk15on-1.64.jar aspectjwea
ver-1.9.4.jar spring-cloud-starter-netflix-eureka-client-2.1.5.BUILD-
20191219.032239-243.jar logback-core-1.2.3.jar slf4j-api-1.7.28.jar s
pring-context-5.2.0.RELEASE.jar mybatis-3.4.6.jar classmate-1.5.0.jar
jackson-datatype-jsr310-2.10.0.jar spring-security-crypto-5.2.0.RELE
ASE.jar mapstruct-1.2.0.Final.jar antlr-2.7.7.jar jboss-logging-3.4.1
.Final.jar springfox-schema-2.9.2.jar spring-aop-5.2.0.RELEASE.jar sp
ring-plugin-core-1.2.0.RELEASE.jar tomcat-embed-core-9.0.27.jar thyme
leaf-spring5-3.0.11.RELEASE.jar spring-jcl-5.2.0.RELEASE.jar HikariCP
-3.4.1.jar jersey-core-1.19.1.jar commons-jxpath-1.3.jar spring-boot-
starter-validation-2.2.0.BUILD-20191016.163457-711.jar jettison-1.3.7
.jar spring-boot-starter-tomcat-2.2.0.BUILD-20191016.163456-712.jar g
uice-4.1.0.jar commons-codec-1.11.jar jackson-module-parameter-names-
2.10.0.jar lettuce-core-5.2.0.RELEASE.jar spring-websocket-5.2.0.RELE
ASE.jar spring-data-keyvalue-2.2.0.RELEASE.jar spring-boot-starter-2.
2.0.BUILD-20191016.163501-711.jar netflix-commons-util-0.3.0.jar xmlp
ull-1.1.3.1.jar stax-api-1.0.1.jar netty-codec-4.1.42.Final.jar druid
-1.1.9.jar spring-oxm-5.2.0.RELEASE.jar jsr311-api-1.1.1.jar spring-b
oot-starter-thymeleaf-2.2.0.BUILD-20191016.163455-712.jar ribbon-tran
sport-2.3.0.jar commons-lang-2.6.jar commons-io-2.6.jar spring-data-c
ommons-2.2.0.RELEASE.jar jackson-annotations-2.10.0.jar logback-class
ic-1.2.3.jar pagehelper-spring-boot-autoconfigure-1.2.5.jar dom4j-2.1
.0.jar servo-core-0.12.21.jar springfox-core-2.9.2.jar mysql-connecto
r-java-8.0.18.jar log4j-to-slf4j-2.12.1.jar ribbon-loadbalancer-2.3.0
.jar spring-cloud-starter-netflix-archaius-2.1.5.BUILD-20191219.03222
9-243.jar jsqlparser-1.0.jar netty-handler-4.1.42.Final.jar antlr-run
time-3.4.jar springfox-swagger-ui-2.9.2.jar mybatis-spring-boot-start
er-1.3.2.jar pagehelper-5.1.4.jar tomcat-embed-websocket-9.0.27.jar s
pring-boot-starter-json-2.2.0.BUILD-20191016.163444-713.jar jackson-c
ore-2.10.0.jar bcprov-jdk15on-1.64.jar springfox-spi-2.9.2.jar mybati
s-spring-1.3.2.jar netflix-infix-0.3.0.jar reactor-core-3.3.0.RELEASE
.jar snakeyaml-1.25.jar jakarta.validation-api-2.0.1.jar spring-secur
ity-core-5.2.0.RELEASE.jar spring-security-config-5.2.0.RELEASE.jar c
ommons-collections-3.2.2.jar jackson-databind-2.10.0.jar ribbon-core-
2.3.0.jar spring-boot-starter-websocket-2.2.0.BUILD-20191016.163500-7
11.jar eureka-core-1.9.13.jar eureka-client-1.9.13.jar netty-common-4
.1.42.Final.jar rxnetty-servo-0.4.9.jar unbescape-1.1.6.RELEASE.jar r
xjava-1.3.8.jar gson-2.8.6.jar mybatis-spring-boot-autoconfigure-1.3.
2.jar druid-spring-boot-starter-1.1.9.jar ribbon-eureka-2.3.0.jar spr
ing-boot-starter-data-redis-2.2.0.BUILD-20191016.163436-713.jar sprin
g-cloud-commons-2.1.5.BUILD-20191219.033001-243.jar spring-boot-confi
guration-processor-2.2.0.BUILD-20191016.163408-713.jar spring-cloud-c
ontext-2.1.5.BUILD-20191219.032901-243.jar spring-boot-starter-jdbc-2
.2.0.BUILD-20191016.163441-713.jar httpcore-4.4.12.jar commons-config
uration-1.8.jar xpp3_min-1.1.4c.jar spring-plugin-metadata-1.2.0.RELE
ASE.jar jackson-datatype-jdk8-2.10.0.jar reactive-streams-1.0.3.jar j
ersey-apache-client4-1.19.1.jar httpclient-4.5.10.jar spring-cloud-ne
tflix-ribbon-2.1.5.BUILD-20191219.031914-243.jar spring-boot-autoconf
igure-2.2.0.BUILD-20191016.163400-713.jar HdrHistogram-2.1.9.jar spri
ng-security-rsa-1.0.9.RELEASE.jar jjwt-0.7.0.jar spring-core-5.2.0.RE
LEASE.jar netflix-eventbus-0.3.0.jar spring-cloud-starter-netflix-rib
bon-2.1.5.BUILD-20191219.032234-243.jar spring-cloud-netflix-archaius
-2.1.5.BUILD-20191219.031847-243.jar spring-context-support-5.2.0.REL
EASE.jar spring-boot-starter-logging-2.2.0.BUILD-20191016.163447-713.
jar hystrix-core-1.5.18.jar ojdbc6-11.2.0.4.0-atlassian-hosted.jar sp
ring-boot-starter-web-2.2.0.BUILD-20191016.163459-711.jar spring-clou
d-netflix-hystrix-2.1.5.BUILD-20191219.031954-243.jar stax2-api-4.2.j
ar pagehelper-spring-boot-starter-1.2.5.jar stringtemplate-3.2.1.jar
spring-expression-5.2.0.RELEASE.jar javax.inject-1.jar spring-cloud-s
tarter-2.1.5.BUILD-20191219.033020-243.jar spring-boot-starter-aop-2.
2.0.BUILD-20191016.163422-713.jar spring-messaging-5.2.0.RELEASE.jar
spring-security-web-5.2.0.RELEASE.jar spring-web-5.2.0.RELEASE.jar je
rsey-client-1.19.1.jar netty-transport-4.1.42.Final.jar ribbon-2.3.0.
jar woodstox-core-5.2.1.jar springfox-swagger2-2.9.2.jar xstream-1.4.
11.1.jar guava-20.0.jar hibernate-validator-6.0.17.Final.jar jakarta.
annotation-api-1.3.5.jar aopalliance-1.0.jar jaxen-1.2.0.jar jul-to-s
lf4j-1.7.28.jar spring-tx-5.2.0.RELEASE.jar spring-webmvc-5.2.0.RELEA
SE.jar byte-buddy-1.10.1.jar fastjson-1.2.28.jar swagger-annotations-
1.5.20.jar thymeleaf-3.0.11.RELEASE.jar log4j-api-2.12.1.jar spring-b
eans-5.2.0.RELEASE.jar tomcat-embed-el-9.0.27.jar rxnetty-0.4.9.jar r
ibbon-httpclient-2.3.0.jar springfox-spring-web-2.9.2.jar archaius-co
re-0.7.6.jar swagger-models-1.5.20.jar spring-boot-2.2.0.BUILD-201910
16.163506-711.jar spring-data-redis-2.2.0.RELEASE.jar spring-jdbc-5.2
.0.RELEASE.jar spring-boot-starter-security-2.2.0.BUILD-20191016.1634
54-713.jar netty-resolver-4.1.42.Final.jar rxnetty-contexts-0.4.9.jar
joda-time-2.10.4.jar netflix-statistics-0.1.1.jar
Main-Class: com.tianbo.warehouse.WarehouseApplication
... ...
... ... @@ -5,6 +5,7 @@ import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;
@ConfigurationProperties(prefix = "tianbo.security")
@Component
public class SecurityProperties {
/**
... ...
... ... @@ -42,6 +42,7 @@ public class MyAuthenticationSuccessHandler extends SavedRequestAwareAuthenticat
@Autowired
private PermissionService permissionService;
private RequestCache requestCache = new HttpSessionRequestCache();
@Autowired
... ...
package com.tianbo.warehouse.util;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.actuate.health.CompositeHealthIndicator;
import org.springframework.data.redis.core.BoundListOperations;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Component;
... ...
... ... @@ -7,7 +7,6 @@ import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.context.web.WebAppConfiguration;
@RunWith(SpringRunner.class)
@WebAppConfiguration
//解决mvn clean package打包项目websocketjavax.websocket.server.ServerContainer not available报错的问题
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
public class WarehouseApplicationTests {
... ...