nf:mod:1.数据库配置调整2.打印应用启动的服务器信息
This commit is contained in:
parent
519ea854d5
commit
0605dd4b36
@ -1,8 +1,20 @@
|
|||||||
package com.ruoyi;
|
package com.ruoyi;
|
||||||
|
|
||||||
|
import com.ruoyi.common.utils.DefaultProfileUtil;
|
||||||
|
import com.ruoyi.common.utils.SpringContextUtils;
|
||||||
|
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;
|
import org.springframework.boot.SpringApplication;
|
||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
|
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
|
||||||
|
import org.springframework.context.ApplicationContext;
|
||||||
|
import org.springframework.core.env.Environment;
|
||||||
|
|
||||||
|
import java.lang.invoke.MethodHandles;
|
||||||
|
import java.net.InetAddress;
|
||||||
|
import java.net.UnknownHostException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 启动程序
|
* 启动程序
|
||||||
@ -12,19 +24,49 @@ import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
|
|||||||
@SpringBootApplication(exclude = { DataSourceAutoConfiguration.class })
|
@SpringBootApplication(exclude = { DataSourceAutoConfiguration.class })
|
||||||
public class RuoYiApplication
|
public class RuoYiApplication
|
||||||
{
|
{
|
||||||
|
//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)
|
public static void main(String[] args)
|
||||||
{
|
{
|
||||||
// System.setProperty("spring.devtools.restart.enabled", "false");
|
// System.setProperty("spring.devtools.restart.enabled", "false");
|
||||||
SpringApplication.run(RuoYiApplication.class, args);
|
//SpringApplication.run(RuoYiApplication.class, args);
|
||||||
System.out.println("(♥◠‿◠)ノ゙ 若依启动成功 ლ(´ڡ`ლ)゙ \n" +
|
//System.out.println("(♥◠‿◠)ノ゙ 若依启动成功 ლ(´ڡ`ლ)゙ \n" +
|
||||||
" .-------. ____ __ \n" +
|
// " .-------. ____ __ \n" +
|
||||||
" | _ _ \\ \\ \\ / / \n" +
|
// " | _ _ \\ \\ \\ / / \n" +
|
||||||
" | ( ' ) | \\ _. / ' \n" +
|
// " | ( ' ) | \\ _. / ' \n" +
|
||||||
" |(_ o _) / _( )_ .' \n" +
|
// " |(_ o _) / _( )_ .' \n" +
|
||||||
" | (_,_).' __ ___(_ o _)' \n" +
|
// " | (_,_).' __ ___(_ o _)' \n" +
|
||||||
" | |\\ \\ | || |(_,_)' \n" +
|
// " | |\\ \\ | || |(_,_)' \n" +
|
||||||
" | | \\ `' /| `-' / \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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -6,9 +6,9 @@ spring:
|
|||||||
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:
|
||||||
# 从数据源开关/默认关闭
|
# 从数据源开关/默认关闭
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
<?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" />
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user