Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
B
basic-api-boot
概览
概览
详情
活动
周期分析
版本库
存储库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
Basic
basic-api-boot
Commits
c3352821
提交
c3352821
authored
2月 23, 2024
作者:
方治民
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat: 新增 sentry, springboot admin client & actuator 相关配置及测试用例
上级
9103e6eb
隐藏空白字符变更
内嵌
并排
正在显示
8 个修改的文件
包含
108 行增加
和
12 行删除
+108
-12
build.gradle
app/build.gradle
+11
-0
ActuatorConfiguration.java
...ain/java/com/yiring/app/config/ActuatorConfiguration.java
+27
-0
GlobalExceptionHandler.java
...in/java/com/yiring/app/config/GlobalExceptionHandler.java
+7
-2
ExampleController.java
...in/java/com/yiring/app/web/example/ExampleController.java
+2
-2
application-dev-postgresql.yml
app/src/main/resources/application-dev-postgresql.yml
+2
-0
application-monitor.yml
app/src/main/resources/application-monitor.yml
+44
-0
application.yml
app/src/main/resources/application.yml
+2
-2
build.gradle
build.gradle
+13
-6
没有找到文件。
app/build.gradle
浏览文件 @
c3352821
apply
plugin:
"com.gorylenko.gradle-git-properties"
group
=
'com.yiring'
version
=
'0.0.1-SNAPSHOT'
...
...
@@ -12,11 +14,20 @@ bootJar {
enabled
=
true
}
springBoot
{
buildInfo
()
}
dependencies
{
implementation
'org.springframework.boot:spring-boot-starter-web'
implementation
'org.springframework.boot:spring-boot-starter-data-jpa'
implementation
'org.springframework.boot:spring-boot-starter-validation'
// Spring Boot Admin Client
implementation
'de.codecentric:spring-boot-admin-starter-client'
// Sentry
implementation
"io.sentry:sentry-spring-boot-starter-jakarta"
// 💬 Mock/Test Env
runtimeOnly
'com.h2database:h2'
// 💬 Prod/Dev Env
...
...
app/src/main/java/com/yiring/app/config/ActuatorConfiguration.java
0 → 100644
浏览文件 @
c3352821
/* (C) 2024 YiRing, Inc. */
package
com
.
yiring
.
app
.
config
;
import
org.springframework.boot.actuate.audit.InMemoryAuditEventRepository
;
import
org.springframework.boot.actuate.web.exchanges.HttpExchangeRepository
;
import
org.springframework.boot.actuate.web.exchanges.InMemoryHttpExchangeRepository
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
/**
* @author Jim
*/
@Configuration
public
class
ActuatorConfiguration
{
@Bean
public
HttpExchangeRepository
httpExchangeRepository
()
{
InMemoryHttpExchangeRepository
repository
=
new
InMemoryHttpExchangeRepository
();
repository
.
setCapacity
(
100
);
return
repository
;
}
@Bean
public
InMemoryAuditEventRepository
repository
()
{
return
new
InMemoryAuditEventRepository
();
}
}
app/src/main/java/com/yiring/app/config/GlobalExceptionHandler.java
浏览文件 @
c3352821
...
...
@@ -4,6 +4,7 @@ package com.yiring.app.config;
import
com.yiring.common.core.I18n
;
import
com.yiring.common.core.Result
;
import
com.yiring.common.core.Status
;
import
io.sentry.Sentry
;
import
lombok.RequiredArgsConstructor
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.core.annotation.Order
;
...
...
@@ -35,7 +36,11 @@ public class GlobalExceptionHandler {
@ResponseStatus
(
code
=
HttpStatus
.
INTERNAL_SERVER_ERROR
)
@ExceptionHandler
(
Exception
.
class
)
public
Result
<
String
>
defaultErrorHandler
(
Exception
e
)
{
log
.
error
(
e
.
getMessage
(),
e
);
return
Result
.
no
(
Status
.
INTERNAL_SERVER_ERROR
,
e
);
try
{
log
.
error
(
e
.
getMessage
(),
e
);
return
Result
.
no
(
Status
.
INTERNAL_SERVER_ERROR
,
e
);
}
finally
{
Sentry
.
captureException
(
e
);
}
}
}
app/src/main/java/com/yiring/app/web/example/ExampleController.java
浏览文件 @
c3352821
...
...
@@ -15,7 +15,6 @@ import com.yiring.common.annotation.RateLimiter;
import
com.yiring.common.core.I18n
;
import
com.yiring.common.core.Result
;
import
com.yiring.common.core.Status
;
import
com.yiring.common.exception.BusinessException
;
import
com.yiring.common.param.IdParam
;
import
com.yiring.common.param.PageParam
;
import
com.yiring.common.service.FileManageService
;
...
...
@@ -75,7 +74,8 @@ public class ExampleController {
@Operation
(
summary
=
"测试失败"
)
@GetMapping
(
"fail"
)
public
Result
<
String
>
fail
()
{
throw
BusinessException
.
i18n
(
"Code.1"
);
// throw BusinessException.i18n("Code.1");
throw
new
RuntimeException
(
"test fail"
);
}
@SaCheckLogin
...
...
app/src/main/resources/application-dev-postgresql.yml
浏览文件 @
c3352821
...
...
@@ -74,4 +74,6 @@ logging:
org.hibernate.type.descriptor.sql.BasicBinder
:
trace
# request log
com.yiring.common.aspect.RequestAspect
:
info
file
:
path
:
./logs
# ----------------------------------------------
app/src/main/resources/application-monitor.yml
0 → 100644
浏览文件 @
c3352821
server
:
address
:
127.0.0.1
# Sentry
sentry
:
# https://sentry.yiring.com
# basic-api
dsn
:
https://fec8292ec19b34fd541c75f907fcec9b@sentry.yiring.com/2
traces-sample-rate
:
1.0
debug
:
false
# Spring Boot Admin Client Config
spring
:
boot
:
admin
:
client
:
url
:
http://127.0.0.1:18891
username
:
admin
password
:
spa.developer@Yiring.com
# Spring Boot Actuator
management
:
server
:
port
:
8182
endpoints
:
web
:
exposure
:
include
:
"
*"
endpoint
:
health
:
show-details
:
always
mappings
:
enabled
:
false
info
:
build
:
enabled
:
true
git
:
enabled
:
true
env
:
enabled
:
true
java
:
enabled
:
true
os
:
enabled
:
true
app/src/main/resources/application.yml
浏览文件 @
c3352821
# 通过 gradle processResources 注入构建版本号
app
:
version
:
${version}
server
:
address
:
127.0.0.1
port
:
8081
servlet
:
context-path
:
/api
...
...
@@ -17,7 +17,7 @@ spring:
max-file-size
:
1024MB
max-request-size
:
1048MB
profiles
:
include
:
auth, conf-patch
include
:
auth, conf-patch
, monitor
active
:
dev-postgresql
# DEBUG
...
...
build.gradle
浏览文件 @
c3352821
...
...
@@ -2,12 +2,14 @@ plugins {
id
'java'
id
'java-library'
// https://start.spring.io
id
'org.springframework.boot'
version
'3.2.
2
'
id
'org.springframework.boot'
version
'3.2.
3
'
id
'org.graalvm.buildtools.native'
version
'0.9.28'
// https://plugins.gradle.org/plugin/io.spring.dependency-management
id
'io.spring.dependency-management'
version
'1.1.4'
// https://plugins.gradle.org/plugin/com.diffplug.spotless
id
"com.diffplug.spotless"
version
"6.25.0"
// https://plugins.gradle.org/plugin/com.gorylenko.gradle-git-properties
id
"com.gorylenko.gradle-git-properties"
version
"2.4.1"
}
ext
{
...
...
@@ -29,6 +31,10 @@ ext {
// FIXED: 版本号不兼容,暂时去掉
springBootAdminVersion
=
'3.2.1'
// Sentry
// https://central.sonatype.com/artifact/io.sentry/sentry-spring-boot-starter-jakarta
sentryVersion
=
'7.4.0'
// Dependencies
// https://central.sonatype.com/artifact/com.github.xiaoymin/knife4j-openapi3-jakarta-spring-boot-starter
knife4jOpen3Version
=
'4.5.0'
...
...
@@ -37,7 +43,7 @@ ext {
// https://central.sonatype.com/artifact/cn.dev33/sa-token-spring-boot3-starter
saTokenVersion
=
'1.37.0'
// https://central.sonatype.com/artifact/cn.hutool/hutool-core
hutoolVersion
=
'5.8.2
5
'
hutoolVersion
=
'5.8.2
6
'
// https://central.sonatype.com/artifact/com.alibaba.fastjson2/fastjson2
fastJsonVersion
=
'2.0.46'
// https://central.sonatype.com/artifact/com.xuxueli/xxl-job-core
...
...
@@ -45,11 +51,11 @@ ext {
// https://central.sonatype.com/artifact/com.squareup.okhttp3/okhttp
okhttpVersion
=
'4.12.0'
// https://central.sonatype.com/artifact/io.minio/minio
minioVersion
=
'8.5.
7
'
minioVersion
=
'8.5.
8
'
// https://central.sonatype.com/artifact/io.hypersistence/hypersistence-utils-hibernate-63
hibernateTypesVersion
=
'3.7.
1
'
hibernateTypesVersion
=
'3.7.
3
'
// https://central.sonatype.com/artifact/org.hibernate.orm/hibernate-spatial
hibernateSpatialVersion
=
'6.4.
2
.Final'
hibernateSpatialVersion
=
'6.4.
4
.Final'
// https://central.sonatype.com/artifact/org.locationtech.jts/jts-core
jtsVersion
=
'1.19.0'
// https://central.sonatype.com/artifact/com.github.liaochong/myexcel
...
...
@@ -68,8 +74,8 @@ allprojects {
mavenLocal
()
// Nexus
// maven { url 'http://10.111.102.83:8081/repository/aliyun-maven/' }
maven
{
url
'https://maven.aliyun.com/repository/public'
}
maven
{
url
'https://mirrors.cloud.tencent.com/nexus/repository/maven-public/'
}
maven
{
url
'https://maven.aliyun.com/repository/public'
}
mavenCentral
()
}
...
...
@@ -101,6 +107,7 @@ subprojects {
imports
{
mavenBom
"org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}"
mavenBom
"de.codecentric:spring-boot-admin-dependencies:${springBootAdminVersion}"
mavenBom
"io.sentry:sentry-bom:${sentryVersion}"
}
}
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论