【log】解决系统日志insert 警告。原因:service事务不受spring管理。修改SysLogService交给spring管理

pull/3/head
liuhanqing 2020-12-28 22:25:46 +08:00
parent d266d52e24
commit f3b39748ee
1 changed files with 21 additions and 2 deletions

View File

@ -9,10 +9,13 @@ import cn.stylefeng.roses.kernel.log.api.pojo.log.SysLogProperties;
import cn.stylefeng.roses.kernel.log.api.threadpool.LogManagerThreadPool; import cn.stylefeng.roses.kernel.log.api.threadpool.LogManagerThreadPool;
import cn.stylefeng.roses.kernel.log.db.DbLogManagerServiceImpl; import cn.stylefeng.roses.kernel.log.db.DbLogManagerServiceImpl;
import cn.stylefeng.roses.kernel.log.db.DbLogRecordServiceImpl; import cn.stylefeng.roses.kernel.log.db.DbLogRecordServiceImpl;
import cn.stylefeng.roses.kernel.log.db.service.SysLogService;
import cn.stylefeng.roses.kernel.log.db.service.impl.SysLogServiceImpl; import cn.stylefeng.roses.kernel.log.db.service.impl.SysLogServiceImpl;
import cn.stylefeng.roses.kernel.log.file.FileLogManagerServiceImpl; import cn.stylefeng.roses.kernel.log.file.FileLogManagerServiceImpl;
import cn.stylefeng.roses.kernel.log.file.FileLogRecordServiceImpl; import cn.stylefeng.roses.kernel.log.file.FileLogRecordServiceImpl;
import cn.stylefeng.roses.kernel.log.modular.requestapi.aop.RequestApiLogRecordAop; import cn.stylefeng.roses.kernel.log.modular.requestapi.aop.RequestApiLogRecordAop;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
@ -31,6 +34,21 @@ public class GunsLogAutoConfiguration {
*/ */
public static final String SYS_LOG_PREFIX = "sys-log"; public static final String SYS_LOG_PREFIX = "sys-log";
/**
* service
*
* @return sysLogService
* @author liuhanqing
* @date 2020/12/28 22:09
*/
@Bean
@ConditionalOnMissingBean(SysLogServiceImpl.class)
@ConditionalOnProperty(prefix = SYS_LOG_PREFIX, name = "type", havingValue = "db")
public SysLogService sysLogService() {
return new SysLogServiceImpl();
}
/** /**
* *
* *
@ -49,11 +67,12 @@ public class GunsLogAutoConfiguration {
* db-file- * db-file-
* *
* @param sysLogProperties * @param sysLogProperties
* @param sysLogService service
* @author liuhanqing * @author liuhanqing
* @date 2020/12/20 13:02 * @date 2020/12/20 13:02
*/ */
@Bean @Bean
public RequestApiLogRecordAop requestApiLogRecordAop(SysLogProperties sysLogProperties) { public RequestApiLogRecordAop requestApiLogRecordAop(SysLogProperties sysLogProperties, SysLogServiceImpl sysLogService) {
// 如果类型是文件 // 如果类型是文件
if (StrUtil.isNotBlank(sysLogProperties.getType()) if (StrUtil.isNotBlank(sysLogProperties.getType())
@ -71,7 +90,7 @@ public class GunsLogAutoConfiguration {
} }
// 其他情况用数据库存储日志 // 其他情况用数据库存储日志
return new RequestApiLogRecordAop(new DbLogRecordServiceImpl(new LogManagerThreadPool(), new SysLogServiceImpl())); return new RequestApiLogRecordAop(new DbLogRecordServiceImpl(new LogManagerThreadPool(), sysLogService));
} }
/** /**