作者 kgy

fear:配置文件整理

# 该镜像需要依赖的基础镜像
FROM java:8
# 指定维护者的名字
MAINTAINER kgy(kgy0809@163.com)
# 将当前目录下的jar包复制到docker容器的/目录下
ADD synthesize_energy_api-1.0-SNAPSHOT.jar /synthesize_energy_api-1.0-SNAPSHOT.jar
# 声明服务运行在8000端口
EXPOSE 10086
# 指定docker容器启动时运行jar包
ENTRYPOINT ["java", "-jar","/synthesize_energy_api-1.0-SNAPSHOT.jar"]
... ...
package com.synthesize_energy.item.config;
import org.springframework.stereotype.Component;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.annotation.WebListener;
@WebListener
@Component
public class MyContextListener implements ServletContextListener {
private SSHConnection conexionssh;
public MyContextListener() {
super();
}
@Override
public void contextInitialized(ServletContextEvent arg0) {
// 建立连接
System.out.println("Context initialized ... !\n\n\n");
try {
conexionssh = new SSHConnection();
conexionssh.SSHConnection();
System.out.println("\n\n\n成功建立SSH连接!\n\n\n");
} catch (Throwable e) {
System.out.println("\n\n\nSSH连接失败!\n\n\n");
e.printStackTrace(); // error connecting SSH server
}
}
@Override
public void contextDestroyed(ServletContextEvent arg0) {
// 断开连接
System.out.println("Context destroyed ... !\n\n\n");
try {
conexionssh.closeSSH(); // disconnect
System.out.println("\n\n\n成功断开SSH连接!\n\n\n");
} catch (Exception e) {
e.printStackTrace();
System.out.println("\n\n\n断开SSH连接出错!\n\n\n");
}
}
}
package com.synthesize_energy.item.config;
import com.jcraft.jsch.JSch;
import com.jcraft.jsch.Session;
public class SSHConnection {
String user = "root";
// 服务器登录名
String password = "bronet888!";
// 登陆密码
String host = "119.3.13.8";
//服务器公网IP
int port = 22;
// 跳板机ssh开放的接口 默认端口 22
int local_port = 3307;
// 这个是本地的端口,很重要!!!选取一个没有占用的port即可
String remote_host = "1f692e5a3458475ea270448f4d3bfde5in01.internal.cn-east-2.mysql.rds.myhuaweicloud.com";
// 要访问的mysql所在的host 服务器局域网IP(127.0.0.1也行)
int remote_port = 3306;
// 服务器上数据库端口号
Session session = null;
public void SSHConnection() throws Exception{
try {
JSch jsch = new JSch();
session = jsch.getSession(user, host, port);
session.setPassword(password);
session.setConfig("StrictHostKeyChecking", "no");
// 日志打印自己脑补
session.connect();
session.setPortForwardingL(local_port, remote_host, remote_port);
} catch (Exception e) {
// do something
}
}
public void closeSSH () throws Exception
{
this.session.disconnect();
}
}
... ... @@ -47,11 +47,8 @@ spring:
master:
driver-class-name: com.mysql.jdbc.Driver
url: jdbc:mysql://localhost:3307/synthesize_energy?useUnicode=true&&characterEncoding=utf8&useSSL=false&serverTimezone=UTC
username: db136s1ehvo1yn73
password: cxz307311SJK
redis:
host: 182.92.205.118
port: 6379
username: root
password: root
banner:
charset: utf-8
image:
... ...
... ... @@ -49,9 +49,6 @@ spring:
url: jdbc:mysql://localhost:3306/synthesize_energy?useUnicode=true&&characterEncoding=utf8&useSSL=false&serverTimezone=UTC
username: root
password: root
redis:
host: 182.92.205.118
port: 6379
banner:
charset: utf-8
image:
... ...
... ... @@ -46,12 +46,9 @@ spring:
datasource:
master:
driver-class-name: com.mysql.jdbc.Driver
url: jdbc:mysql://1f692e5a3458475ea270448f4d3bfde5in01.internal.cn-east-2.mysql.rds.myhuaweicloud.com:3306/synthesize_energy?useUnicode=true&&characterEncoding=utf8&useSSL=false&serverTimezone=UTC
username: db136s1ehvo1yn73
password: cxz307311SJK
redis:
host: 182.92.205.118
port: 6379
url: jdbc:mysql://127.0.0.1:3306/synthesize_energy?useUnicode=true&&characterEncoding=utf8&useSSL=false&serverTimezone=UTC
username: root
password: root
# mybatis-plus相关配置
mybatis-plus:
# xml扫描,多个目录用逗号或者分号分隔(告诉 Mapper 所对应的 XML 文件位置)
... ... @@ -82,7 +79,7 @@ naturalResources:
num3: 3780
num4: 0.13 #增值税率
web:
upload-path: /wwww/service/nginx/nginx-1.16.1/html/images
upload-path: /wwww/service/nginx/nginx-1.16.1/html/images # 服务器对应路径
#upload-path: E:/image
task:
pool:
... ...