nf:mod:1.数据库配置调整2.打印应用启动的服务器信息
This commit is contained in:
@ -1,30 +1,72 @@
|
|||||||
package com.ruoyi;
|
package com.ruoyi;
|
||||||
|
|
||||||
import org.springframework.boot.SpringApplication;
|
import com.ruoyi.common.utils.DefaultProfileUtil;
|
||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
import com.ruoyi.common.utils.SpringContextUtils;
|
||||||
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
|
import org.apache.commons.logging.Log;
|
||||||
|
import org.apache.commons.logging.LogFactory;
|
||||||
/**
|
import org.slf4j.Logger;
|
||||||
* 启动程序
|
import org.slf4j.LoggerFactory;
|
||||||
*
|
import org.springframework.boot.SpringApplication;
|
||||||
* @author ruoyi
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
*/
|
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
|
||||||
@SpringBootApplication(exclude = { DataSourceAutoConfiguration.class })
|
import org.springframework.context.ApplicationContext;
|
||||||
public class RuoYiApplication
|
import org.springframework.core.env.Environment;
|
||||||
{
|
|
||||||
public static void main(String[] args)
|
import java.lang.invoke.MethodHandles;
|
||||||
{
|
import java.net.InetAddress;
|
||||||
// System.setProperty("spring.devtools.restart.enabled", "false");
|
import java.net.UnknownHostException;
|
||||||
SpringApplication.run(RuoYiApplication.class, args);
|
|
||||||
System.out.println("(♥◠‿◠)ノ゙ 若依启动成功 ლ(´ڡ`ლ)゙ \n" +
|
/**
|
||||||
" .-------. ____ __ \n" +
|
* 启动程序
|
||||||
" | _ _ \\ \\ \\ / / \n" +
|
*
|
||||||
" | ( ' ) | \\ _. / ' \n" +
|
* @author ruoyi
|
||||||
" |(_ o _) / _( )_ .' \n" +
|
*/
|
||||||
" | (_,_).' __ ___(_ o _)' \n" +
|
@SpringBootApplication(exclude = { DataSourceAutoConfiguration.class })
|
||||||
" | |\\ \\ | || |(_,_)' \n" +
|
public class RuoYiApplication
|
||||||
" | | \\ `' /| `-' / \n" +
|
{
|
||||||
" | | \\ / \\ / \n" +
|
//private static final Log logger = LogFactory.getLog(MethodHandles.lookup().lookupClass());
|
||||||
" ''-' `'-' `-..-' ");
|
private static final Logger syslog = LoggerFactory.getLogger(RuoYiApplication.class);
|
||||||
}
|
public static void main(String[] args)
|
||||||
}
|
{
|
||||||
|
// System.setProperty("spring.devtools.restart.enabled", "false");
|
||||||
|
//SpringApplication.run(RuoYiApplication.class, args);
|
||||||
|
//System.out.println("(♥◠‿◠)ノ゙ 若依启动成功 ლ(´ڡ`ლ)゙ \n" +
|
||||||
|
// " .-------. ____ __ \n" +
|
||||||
|
// " | _ _ \\ \\ \\ / / \n" +
|
||||||
|
// " | ( ' ) | \\ _. / ' \n" +
|
||||||
|
// " |(_ o _) / _( )_ .' \n" +
|
||||||
|
// " | (_,_).' __ ___(_ o _)' \n" +
|
||||||
|
// " | |\\ \\ | || |(_,_)' \n" +
|
||||||
|
// " | | \\ `' /| `-' / \n" +
|
||||||
|
// " | | \\ / \\ / \n" +
|
||||||
|
// " ''-' `'-' `-..-' ");
|
||||||
|
appEnvInfo(args);
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* @Description: 打印应用启动环境信息
|
||||||
|
* @Author: libiao
|
||||||
|
* @Date: 2021/10/17 19:40
|
||||||
|
* @param args:
|
||||||
|
* @return: void
|
||||||
|
**/
|
||||||
|
public static void appEnvInfo(String[] args){
|
||||||
|
SpringApplication app = new SpringApplication(RuoYiApplication.class);
|
||||||
|
DefaultProfileUtil.addDefaultProfile(app);
|
||||||
|
ApplicationContext appc = app.run(args);
|
||||||
|
Environment env = appc.getEnvironment();
|
||||||
|
String ip = "localhost";
|
||||||
|
try {
|
||||||
|
ip = InetAddress.getLocalHost().getHostAddress();
|
||||||
|
} catch (UnknownHostException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
syslog.info("\n----------------------------------------------------------\n\t" +
|
||||||
|
"Application '{}' is running! Access URLs:\n\t" +
|
||||||
|
"Local: \t\thttp://{}:{}\n\t" +
|
||||||
|
"----------------------------------------------------------",
|
||||||
|
env.getProperty("spring.profiles.active"),ip,
|
||||||
|
env.getProperty("server.port"));
|
||||||
|
syslog.info("程序启动完成!");
|
||||||
|
SpringContextUtils.setStaticApplicationContext(appc);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -0,0 +1,18 @@
|
|||||||
|
package com.ruoyi.common.utils;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 系统参数相关Key
|
||||||
|
*/
|
||||||
|
public class ConfigConstant {
|
||||||
|
/**
|
||||||
|
* 云存储配置KEY
|
||||||
|
*/
|
||||||
|
public final static String CLOUD_STORAGE_CONFIG_KEY = "CLOUD_STORAGE_CONFIG_KEY";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 运行环境
|
||||||
|
*/
|
||||||
|
public static final String SPRING_PROFILE_DEVELOPMENT = "dev";
|
||||||
|
public static final String SPRING_PROFILE_TEST = "uat";
|
||||||
|
public static final String SPRING_PROFILE_PRODUCTION = "prd";
|
||||||
|
}
|
@ -0,0 +1,42 @@
|
|||||||
|
package com.ruoyi.common.utils;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.springframework.boot.SpringApplication;
|
||||||
|
import org.springframework.core.env.Environment;
|
||||||
|
|
||||||
|
public class DefaultProfileUtil {
|
||||||
|
|
||||||
|
private static final String SPRING_PROFILE_DEFAULT = "spring.profiles.default";
|
||||||
|
|
||||||
|
private DefaultProfileUtil(){
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set a default to use when no profile is configured.
|
||||||
|
*
|
||||||
|
* @param app the spring application
|
||||||
|
*/
|
||||||
|
public static void addDefaultProfile(SpringApplication app) {
|
||||||
|
Map<String, Object> defProperties = new HashMap<String, Object>();
|
||||||
|
/*
|
||||||
|
* The default profile to use when no other profiles are defined
|
||||||
|
* This cannot be set in the <code>application.yml</code> file.
|
||||||
|
* See https://github.com/spring-projects/spring-boot/issues/1219
|
||||||
|
*/
|
||||||
|
defProperties.put(SPRING_PROFILE_DEFAULT, ConfigConstant.SPRING_PROFILE_DEVELOPMENT);
|
||||||
|
app.setDefaultProperties(defProperties);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the profiles that are applied else get default profiles.
|
||||||
|
*/
|
||||||
|
public static String[] getActiveProfiles(Environment env) {
|
||||||
|
String[] profiles = env.getActiveProfiles();
|
||||||
|
if (profiles.length == 0) {
|
||||||
|
return env.getDefaultProfiles();
|
||||||
|
}
|
||||||
|
return profiles;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,60 @@
|
|||||||
|
package com.ruoyi.common.utils;
|
||||||
|
|
||||||
|
import org.apache.commons.lang3.Validate;
|
||||||
|
import org.springframework.beans.BeansException;
|
||||||
|
import org.springframework.context.ApplicationContext;
|
||||||
|
import org.springframework.context.ApplicationContextAware;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Spring Context 工具类
|
||||||
|
*
|
||||||
|
* @author libiao
|
||||||
|
* @date 2021-10-17
|
||||||
|
*/
|
||||||
|
@Component
|
||||||
|
public class SpringContextUtils implements ApplicationContextAware {
|
||||||
|
public static ApplicationContext applicationContext;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setApplicationContext(ApplicationContext applicationContext)
|
||||||
|
throws BeansException {
|
||||||
|
SpringContextUtils.applicationContext = applicationContext;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void setStaticApplicationContext(ApplicationContext applicationContext)
|
||||||
|
throws BeansException {
|
||||||
|
SpringContextUtils.applicationContext = applicationContext;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Object getBean(String name) {
|
||||||
|
return applicationContext.getBean(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 从静态变量applicationContext中取得Bean, 自动转型为所赋值对象的类型.
|
||||||
|
*/
|
||||||
|
public static <T> T getBean(String name, Class<T> requiredType) {
|
||||||
|
return applicationContext.getBean(name, requiredType);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 检查ApplicationContext不为空.
|
||||||
|
*/
|
||||||
|
private static void assertContextInjected() {
|
||||||
|
Validate.validState(applicationContext != null, "applicaitonContext属性未注入, 请在applicationContext.xml中定义SpringContextHolder.");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean containsBean(String name) {
|
||||||
|
return applicationContext.containsBean(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean isSingleton(String name) {
|
||||||
|
return applicationContext.isSingleton(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Class<? extends Object> getType(String name) {
|
||||||
|
return applicationContext.getType(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -1,57 +1,57 @@
|
|||||||
# 数据源配置
|
# 数据源配置
|
||||||
spring:
|
spring:
|
||||||
datasource:
|
datasource:
|
||||||
type: com.alibaba.druid.pool.DruidDataSource
|
type: com.alibaba.druid.pool.DruidDataSource
|
||||||
driverClassName: com.mysql.cj.jdbc.Driver
|
driverClassName: com.mysql.cj.jdbc.Driver
|
||||||
druid:
|
druid:
|
||||||
# 主库数据源
|
# 主库数据源
|
||||||
master:
|
master:
|
||||||
url: jdbc:mysql://localhost:3306/ry-vue?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
|
url: jdbc:mysql://localhost:3306/shopee_erp?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
|
||||||
username: root
|
username: shopee_erp
|
||||||
password: password
|
password: shopee_erp123
|
||||||
# 从库数据源
|
# 从库数据源
|
||||||
slave:
|
slave:
|
||||||
# 从数据源开关/默认关闭
|
# 从数据源开关/默认关闭
|
||||||
enabled: false
|
enabled: false
|
||||||
url:
|
url:
|
||||||
username:
|
username:
|
||||||
password:
|
password:
|
||||||
# 初始连接数
|
# 初始连接数
|
||||||
initialSize: 5
|
initialSize: 5
|
||||||
# 最小连接池数量
|
# 最小连接池数量
|
||||||
minIdle: 10
|
minIdle: 10
|
||||||
# 最大连接池数量
|
# 最大连接池数量
|
||||||
maxActive: 20
|
maxActive: 20
|
||||||
# 配置获取连接等待超时的时间
|
# 配置获取连接等待超时的时间
|
||||||
maxWait: 60000
|
maxWait: 60000
|
||||||
# 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒
|
# 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒
|
||||||
timeBetweenEvictionRunsMillis: 60000
|
timeBetweenEvictionRunsMillis: 60000
|
||||||
# 配置一个连接在池中最小生存的时间,单位是毫秒
|
# 配置一个连接在池中最小生存的时间,单位是毫秒
|
||||||
minEvictableIdleTimeMillis: 300000
|
minEvictableIdleTimeMillis: 300000
|
||||||
# 配置一个连接在池中最大生存的时间,单位是毫秒
|
# 配置一个连接在池中最大生存的时间,单位是毫秒
|
||||||
maxEvictableIdleTimeMillis: 900000
|
maxEvictableIdleTimeMillis: 900000
|
||||||
# 配置检测连接是否有效
|
# 配置检测连接是否有效
|
||||||
validationQuery: SELECT 1 FROM DUAL
|
validationQuery: SELECT 1 FROM DUAL
|
||||||
testWhileIdle: true
|
testWhileIdle: true
|
||||||
testOnBorrow: false
|
testOnBorrow: false
|
||||||
testOnReturn: false
|
testOnReturn: false
|
||||||
webStatFilter:
|
webStatFilter:
|
||||||
enabled: true
|
enabled: true
|
||||||
statViewServlet:
|
statViewServlet:
|
||||||
enabled: true
|
enabled: true
|
||||||
# 设置白名单,不填则允许所有访问
|
# 设置白名单,不填则允许所有访问
|
||||||
allow:
|
allow:
|
||||||
url-pattern: /druid/*
|
url-pattern: /druid/*
|
||||||
# 控制台管理用户名和密码
|
# 控制台管理用户名和密码
|
||||||
login-username: ruoyi
|
login-username: ruoyi
|
||||||
login-password: 123456
|
login-password: 123456
|
||||||
filter:
|
filter:
|
||||||
stat:
|
stat:
|
||||||
enabled: true
|
enabled: true
|
||||||
# 慢SQL记录
|
# 慢SQL记录
|
||||||
log-slow-sql: true
|
log-slow-sql: true
|
||||||
slow-sql-millis: 1000
|
slow-sql-millis: 1000
|
||||||
merge-sql: true
|
merge-sql: true
|
||||||
wall:
|
wall:
|
||||||
config:
|
config:
|
||||||
multi-statement-allow: true
|
multi-statement-allow: true
|
@ -1,93 +1,93 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<configuration>
|
<configuration>
|
||||||
<!-- 日志存放路径 -->
|
<!-- 日志存放路径 -->
|
||||||
<property name="log.path" value="/home/ruoyi/logs" />
|
<property name="log.path" value="./logs" />
|
||||||
<!-- 日志输出格式 -->
|
<!-- 日志输出格式 -->
|
||||||
<property name="log.pattern" value="%d{HH:mm:ss.SSS} [%thread] %-5level %logger{20} - [%method,%line] - %msg%n" />
|
<property name="log.pattern" value="%d{HH:mm:ss.SSS} [%thread] %-5level %logger{20} - [%method,%line] - %msg%n" />
|
||||||
|
|
||||||
<!-- 控制台输出 -->
|
<!-- 控制台输出 -->
|
||||||
<appender name="console" class="ch.qos.logback.core.ConsoleAppender">
|
<appender name="console" class="ch.qos.logback.core.ConsoleAppender">
|
||||||
<encoder>
|
<encoder>
|
||||||
<pattern>${log.pattern}</pattern>
|
<pattern>${log.pattern}</pattern>
|
||||||
</encoder>
|
</encoder>
|
||||||
</appender>
|
</appender>
|
||||||
|
|
||||||
<!-- 系统日志输出 -->
|
<!-- 系统日志输出 -->
|
||||||
<appender name="file_info" class="ch.qos.logback.core.rolling.RollingFileAppender">
|
<appender name="file_info" class="ch.qos.logback.core.rolling.RollingFileAppender">
|
||||||
<file>${log.path}/sys-info.log</file>
|
<file>${log.path}/sys-info.log</file>
|
||||||
<!-- 循环政策:基于时间创建日志文件 -->
|
<!-- 循环政策:基于时间创建日志文件 -->
|
||||||
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
|
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
|
||||||
<!-- 日志文件名格式 -->
|
<!-- 日志文件名格式 -->
|
||||||
<fileNamePattern>${log.path}/sys-info.%d{yyyy-MM-dd}.log</fileNamePattern>
|
<fileNamePattern>${log.path}/sys-info.%d{yyyy-MM-dd}.log</fileNamePattern>
|
||||||
<!-- 日志最大的历史 60天 -->
|
<!-- 日志最大的历史 60天 -->
|
||||||
<maxHistory>60</maxHistory>
|
<maxHistory>60</maxHistory>
|
||||||
</rollingPolicy>
|
</rollingPolicy>
|
||||||
<encoder>
|
<encoder>
|
||||||
<pattern>${log.pattern}</pattern>
|
<pattern>${log.pattern}</pattern>
|
||||||
</encoder>
|
</encoder>
|
||||||
<filter class="ch.qos.logback.classic.filter.LevelFilter">
|
<filter class="ch.qos.logback.classic.filter.LevelFilter">
|
||||||
<!-- 过滤的级别 -->
|
<!-- 过滤的级别 -->
|
||||||
<level>INFO</level>
|
<level>INFO</level>
|
||||||
<!-- 匹配时的操作:接收(记录) -->
|
<!-- 匹配时的操作:接收(记录) -->
|
||||||
<onMatch>ACCEPT</onMatch>
|
<onMatch>ACCEPT</onMatch>
|
||||||
<!-- 不匹配时的操作:拒绝(不记录) -->
|
<!-- 不匹配时的操作:拒绝(不记录) -->
|
||||||
<onMismatch>DENY</onMismatch>
|
<onMismatch>DENY</onMismatch>
|
||||||
</filter>
|
</filter>
|
||||||
</appender>
|
</appender>
|
||||||
|
|
||||||
<appender name="file_error" class="ch.qos.logback.core.rolling.RollingFileAppender">
|
<appender name="file_error" class="ch.qos.logback.core.rolling.RollingFileAppender">
|
||||||
<file>${log.path}/sys-error.log</file>
|
<file>${log.path}/sys-error.log</file>
|
||||||
<!-- 循环政策:基于时间创建日志文件 -->
|
<!-- 循环政策:基于时间创建日志文件 -->
|
||||||
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
|
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
|
||||||
<!-- 日志文件名格式 -->
|
<!-- 日志文件名格式 -->
|
||||||
<fileNamePattern>${log.path}/sys-error.%d{yyyy-MM-dd}.log</fileNamePattern>
|
<fileNamePattern>${log.path}/sys-error.%d{yyyy-MM-dd}.log</fileNamePattern>
|
||||||
<!-- 日志最大的历史 60天 -->
|
<!-- 日志最大的历史 60天 -->
|
||||||
<maxHistory>60</maxHistory>
|
<maxHistory>60</maxHistory>
|
||||||
</rollingPolicy>
|
</rollingPolicy>
|
||||||
<encoder>
|
<encoder>
|
||||||
<pattern>${log.pattern}</pattern>
|
<pattern>${log.pattern}</pattern>
|
||||||
</encoder>
|
</encoder>
|
||||||
<filter class="ch.qos.logback.classic.filter.LevelFilter">
|
<filter class="ch.qos.logback.classic.filter.LevelFilter">
|
||||||
<!-- 过滤的级别 -->
|
<!-- 过滤的级别 -->
|
||||||
<level>ERROR</level>
|
<level>ERROR</level>
|
||||||
<!-- 匹配时的操作:接收(记录) -->
|
<!-- 匹配时的操作:接收(记录) -->
|
||||||
<onMatch>ACCEPT</onMatch>
|
<onMatch>ACCEPT</onMatch>
|
||||||
<!-- 不匹配时的操作:拒绝(不记录) -->
|
<!-- 不匹配时的操作:拒绝(不记录) -->
|
||||||
<onMismatch>DENY</onMismatch>
|
<onMismatch>DENY</onMismatch>
|
||||||
</filter>
|
</filter>
|
||||||
</appender>
|
</appender>
|
||||||
|
|
||||||
<!-- 用户访问日志输出 -->
|
<!-- 用户访问日志输出 -->
|
||||||
<appender name="sys-user" class="ch.qos.logback.core.rolling.RollingFileAppender">
|
<appender name="sys-user" class="ch.qos.logback.core.rolling.RollingFileAppender">
|
||||||
<file>${log.path}/sys-user.log</file>
|
<file>${log.path}/sys-user.log</file>
|
||||||
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
|
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
|
||||||
<!-- 按天回滚 daily -->
|
<!-- 按天回滚 daily -->
|
||||||
<fileNamePattern>${log.path}/sys-user.%d{yyyy-MM-dd}.log</fileNamePattern>
|
<fileNamePattern>${log.path}/sys-user.%d{yyyy-MM-dd}.log</fileNamePattern>
|
||||||
<!-- 日志最大的历史 60天 -->
|
<!-- 日志最大的历史 60天 -->
|
||||||
<maxHistory>60</maxHistory>
|
<maxHistory>60</maxHistory>
|
||||||
</rollingPolicy>
|
</rollingPolicy>
|
||||||
<encoder>
|
<encoder>
|
||||||
<pattern>${log.pattern}</pattern>
|
<pattern>${log.pattern}</pattern>
|
||||||
</encoder>
|
</encoder>
|
||||||
</appender>
|
</appender>
|
||||||
|
|
||||||
<!-- 系统模块日志级别控制 -->
|
<!-- 系统模块日志级别控制 -->
|
||||||
<logger name="com.ruoyi" level="info" />
|
<logger name="com.ruoyi" level="info" />
|
||||||
<!-- Spring日志级别控制 -->
|
<!-- Spring日志级别控制 -->
|
||||||
<logger name="org.springframework" level="warn" />
|
<logger name="org.springframework" level="warn" />
|
||||||
|
|
||||||
<root level="info">
|
<root level="info">
|
||||||
<appender-ref ref="console" />
|
<appender-ref ref="console" />
|
||||||
</root>
|
</root>
|
||||||
|
|
||||||
<!--系统操作日志-->
|
<!--系统操作日志-->
|
||||||
<root level="info">
|
<root level="info">
|
||||||
<appender-ref ref="file_info" />
|
<appender-ref ref="file_info" />
|
||||||
<appender-ref ref="file_error" />
|
<appender-ref ref="file_error" />
|
||||||
</root>
|
</root>
|
||||||
|
|
||||||
<!--系统用户操作日志-->
|
<!--系统用户操作日志-->
|
||||||
<logger name="sys-user" level="info">
|
<logger name="sys-user" level="info">
|
||||||
<appender-ref ref="sys-user"/>
|
<appender-ref ref="sys-user"/>
|
||||||
</logger>
|
</logger>
|
||||||
</configuration>
|
</configuration>
|
Reference in New Issue
Block a user