文章目录  1.common-log4j2-starter 动态获取并打印日志存储的根目录的绝对路径以及应用的访问地址 1.目录 2.log4j2.xml 配置LOG_HOME 3.LogHomePrinter.java 配置监听器 4.spring.factories 注册监听器 5.测试 1.common-log4j2-starter-demo 配置 2.启动测试 2.common-minio-starter 删除桶名的配置参数 1.MinioProperties.java 2.删除 3.common-mybatis-plus-starter 修改代码生成器 1.修改ServiceImpl的Java模板,调用框架提供的方法使用super而不是this 2.导出模板 4.common-test-starter 排除logging   
 
 
        < Propertyname = " LOG_HOME" > </ Property> package  com. sunxiansheng. log4j2. listener ; import  org. apache. logging. log4j.  LogManager ; 
import  org. apache. logging. log4j. core.  LoggerContext ; 
import  org. apache. logging. log4j. core. config.  Configuration ; 
import  org. slf4j.  Logger ; 
import  org. slf4j.  LoggerFactory ; 
import  org. springframework. boot. context. event.  ApplicationReadyEvent ; 
import  org. springframework. context.  ApplicationListener ; 
import  org. springframework. core. env.  Environment ; import  java. io.  File ; 
import  java. net.  InetAddress ; 
public  class  LogHomePrinter  implements  ApplicationListener < ApplicationReadyEvent > { private  static  final  Logger  logger =  LoggerFactory . getLogger ( LogHomePrinter . class ) ; @Override public  void  onApplicationEvent ( ApplicationReadyEvent  event)  { try  { LoggerContext  context =  ( LoggerContext )  LogManager . getContext ( false ) ; Configuration  config =  context. getConfiguration ( ) ; String  logHome =  config. getStrSubstitutor ( ) . replace ( "${LOG_HOME}" ) ; if  ( logHome ==  null  ||  logHome. isEmpty ( ) )  { logger. warn ( "未配置 LOG_HOME 属性,使用默认值或未定义!" ) ; }  else  { File  logHomeDir =  new  File ( logHome) . getCanonicalFile ( ) ; logger. info ( "日志存储的根目录为: {}" ,  logHomeDir. getAbsolutePath ( ) ) ; } Environment  environment =  event. getApplicationContext ( ) . getEnvironment ( ) ; String  ip =  InetAddress . getLocalHost ( ) . getHostAddress ( ) ; String  port =  environment. getProperty ( "server.port" ,  "8080" ) ; String  contextPath =  environment. getProperty ( "server.servlet.context-path" ,  "" ) ; if  ( ! contextPath. startsWith ( "/" ) )  { contextPath =  "/"  +  contextPath; } logger. info ( "应用访问地址: http://{}:{}{}" ,  ip,  port,  contextPath) ; }  catch  ( Exception  e)  { logger. error ( "获取日志存储根目录或应用访问地址时发生错误" ,  e) ; } } 
} 
org. springframework. context.  ApplicationListener= \
com. sunxiansheng. log4j2. listener.  LogHomePrinterlog : aspect : enable :  true  trace : enable :  true  
server : port :  8082 
 
 
 
 
## 引入宏定义
$! { define. vm} ## 设置保存名称与保存位置
$! callback. setFileName ( $tool. append ( $! { tableInfo. name} ,  "ServiceImpl.java" ) ) 
$! callback. setSavePath ( $tool. append ( $tableInfo. savePath,  "/service/impl" ) ) ## 拿到主键
#if ( ! $tableInfo. pkColumn. isEmpty ( ) ) #set ( $pk =  $tableInfo. pkColumn. get ( 0 ) ) 
#end## 包声明
#if ( $tableInfo. savePackageName) package  $! { tableInfo. savePackageName} . service. impl; 
#end## 导入相关类
import  com. sunxiansheng. mybatis. plus. base. service. impl.  SunRaysBaseServiceImpl ; 
import  $! { tableInfo. savePackageName} . convert. ${ tableInfo. name} Converter ; 
import  $! { tableInfo. savePackageName} . entity. po. ${ tableInfo. name} ; 
import  $! { tableInfo. savePackageName} . entity. req. ${ tableInfo. name} Req ; 
import  $! { tableInfo. savePackageName} . entity. vo. ${ tableInfo. name} Vo ; 
import  $! { tableInfo. savePackageName} . mapper. ${ tableInfo. name} Mapper ; 
import  $! { tableInfo. savePackageName} . mapper. plus. ${ tableInfo. name} PlusMapper ; 
import  com. sunxiansheng. mybatis. plus. page.  PageResult ; 
import  com. sunxiansheng. mybatis. plus. page.  SunPageHelper ; 
import  $! { tableInfo. savePackageName} . service. ${ tableInfo. name} Service ; 
import  org. springframework. transaction. annotation.  Transactional ; 
import  org. springframework. stereotype.  Service ; 
import  javax. annotation.  Resource ; 
import  java. util.  List ; 
@Service ( "$!tool.firstLowerCase($!{tableInfo.name})Service" ) 
public  class  $! { tableInfo. name} ServiceImpl extends  SunRaysBaseServiceImpl < $! { tableInfo. name} PlusMapper ,  $! { tableInfo. name} ,  $pk. type> implements  $! { tableInfo. name} Service  { @Resource private  $! { tableInfo. name} Mapper  ${ tool. firstLowerCase ( $! { tableInfo. name} ) } Mapper ; public  $! { tableInfo. name} ServiceImpl ( $! { tableInfo. name} PlusMapper  mybatisPlusMapper)  { super . setMybatisPlusMapper ( mybatisPlusMapper) ; } @Override @Transactional ( rollbackFor =  Exception . class )  public  PageResult < $! { tableInfo. name} Vo >  listPage ( $! { tableInfo. name} Req  $! tool. firstLowerCase ( $! { tableInfo. name} ) Req )  { $! { tableInfo. name}  po =  $! { tableInfo. name} Converter . INSTANCE . convertReq2Po ( $! tool. firstLowerCase ( $! { tableInfo. name} ) Req ) ; PageResult < $! { tableInfo. name} Vo >  paginate =  SunPageHelper . paginate ( $! tool. firstLowerCase ( $! { tableInfo. name} ) Req . getPageNo ( ) , $! tool. firstLowerCase ( $! { tableInfo. name} ) Req . getPageSize ( ) , ( )  ->  super . count ( po) , ( offset,  limit)  ->  { List < $! { tableInfo. name} >  ${ tool. firstLowerCase ( $! { tableInfo. name} ) } List  = ${ tool. firstLowerCase ( $! { tableInfo. name} ) } Mapper . queryPage ( po,  offset,  limit) ; return  $! { tableInfo. name} Converter . INSTANCE . convertPoList2VoList ( ${ tool. firstLowerCase ( $! { tableInfo. name} ) } List ) ; } ) ; return  paginate; } 
}