Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
zhangjian1949
microservices-platform
提交
eca52068
microservices-platform
项目概览
zhangjian1949
/
microservices-platform
与 Fork 源项目一致
Fork自
zlt2000 / microservices-platform
通知
6
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
microservices-platform
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
eca52068
编写于
2月 22, 2020
作者:
zlt2000
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
优化日志数据库配置类
上级
6b3a30ea
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
19 addition
and
9 deletion
+19
-9
zlt-commons/zlt-log-spring-boot-starter/src/main/java/com/central/log/config/LogAutoConfigure.java
...rc/main/java/com/central/log/config/LogAutoConfigure.java
+11
-1
zlt-commons/zlt-log-spring-boot-starter/src/main/java/com/central/log/properties/AuditLogProperties.java
...n/java/com/central/log/properties/AuditLogProperties.java
+0
-5
zlt-commons/zlt-log-spring-boot-starter/src/main/java/com/central/log/properties/LogDbProperties.java
...main/java/com/central/log/properties/LogDbProperties.java
+3
-0
zlt-commons/zlt-log-spring-boot-starter/src/main/java/com/central/log/service/impl/DbAuditServiceImpl.java
...java/com/central/log/service/impl/DbAuditServiceImpl.java
+5
-3
未找到文件。
zlt-commons/zlt-log-spring-boot-starter/src/main/java/com/central/log/config/LogAutoConfigure.java
浏览文件 @
eca52068
package
com.central.log.config
;
import
com.central.log.properties.AuditLogProperties
;
import
com.central.log.properties.LogDbProperties
;
import
com.central.log.properties.TraceProperties
;
import
com.zaxxer.hikari.HikariConfig
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnClass
;
import
org.springframework.boot.context.properties.EnableConfigurationProperties
;
import
org.springframework.context.annotation.Configuration
;
/**
* 日志自动配置
...
...
@@ -12,5 +16,11 @@ import org.springframework.boot.context.properties.EnableConfigurationProperties
*/
@EnableConfigurationProperties
({
TraceProperties
.
class
,
AuditLogProperties
.
class
})
public
class
LogAutoConfigure
{
/**
* 日志数据库配置
*/
@Configuration
@ConditionalOnClass
(
HikariConfig
.
class
)
@EnableConfigurationProperties
(
LogDbProperties
.
class
)
public
static
class
LogDbAutoConfigure
{}
}
zlt-commons/zlt-log-spring-boot-starter/src/main/java/com/central/log/properties/AuditLogProperties.java
浏览文件 @
eca52068
...
...
@@ -27,9 +27,4 @@ public class AuditLogProperties {
* 日志记录类型(logger/redis/db/es)
*/
private
String
logType
;
/**
* 数据源配置
* logType=db时生效(非必须),如果不配置则使用当前数据源
*/
private
LogDbProperties
datasource
=
new
LogDbProperties
();
}
zlt-commons/zlt-log-spring-boot-starter/src/main/java/com/central/log/properties/LogDbProperties.java
浏览文件 @
eca52068
...
...
@@ -3,9 +3,11 @@ package com.central.log.properties;
import
com.zaxxer.hikari.HikariConfig
;
import
lombok.Getter
;
import
lombok.Setter
;
import
org.springframework.boot.context.properties.ConfigurationProperties
;
/**
* 日志数据源配置
* logType=db时生效(非必须),如果不配置则使用当前数据源
*
* @author zlt
* @date 2020/2/8
...
...
@@ -15,5 +17,6 @@ import lombok.Setter;
*/
@Setter
@Getter
@ConfigurationProperties
(
prefix
=
"zlt.audit-log.datasource"
)
public
class
LogDbProperties
extends
HikariConfig
{
}
zlt-commons/zlt-log-spring-boot-starter/src/main/java/com/central/log/service/impl/DbAuditServiceImpl.java
浏览文件 @
eca52068
...
...
@@ -2,10 +2,12 @@ package com.central.log.service.impl;
import
com.central.log.model.Audit
;
import
com.central.log.properties.AuditLogProperties
;
import
com.central.log.properties.LogDbProperties
;
import
com.central.log.service.IAuditService
;
import
com.zaxxer.hikari.HikariDataSource
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.lang3.StringUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnClass
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnProperty
;
import
org.springframework.jdbc.core.JdbcTemplate
;
...
...
@@ -33,10 +35,10 @@ public class DbAuditServiceImpl implements IAuditService {
private
final
JdbcTemplate
jdbcTemplate
;
public
DbAuditServiceImpl
(
AuditLogProperties
auditLog
Properties
,
DataSource
dataSource
)
{
public
DbAuditServiceImpl
(
@Autowired
(
required
=
false
)
LogDbProperties
logDb
Properties
,
DataSource
dataSource
)
{
//优先使用配置的日志数据源,否则使用默认的数据源
if
(
StringUtils
.
isNotEmpty
(
auditLogProperties
.
getDatasource
()
.
getJdbcUrl
()))
{
dataSource
=
new
HikariDataSource
(
auditLogProperties
.
getDatasource
()
);
if
(
logDbProperties
!=
null
&&
StringUtils
.
isNotEmpty
(
logDbProperties
.
getJdbcUrl
()))
{
dataSource
=
new
HikariDataSource
(
logDbProperties
);
}
this
.
jdbcTemplate
=
new
JdbcTemplate
(
dataSource
);
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录