问题总结
解决go包无法拉取
换一个国内能访问的代理地址:https://goproxy.cn
go env -w GOPROXY=https://goproxy.cn
springboot项目docker部署
1.本地项目打包
2.编写Dockerfile文件
# Docker image for springboot file run
# VERSION 0.0.1
# Author: eangulee
# 基础镜像使用java
FROM java:8
# 作者
MAINTAINER linmumu <linmumu@gmail.com>
# VOLUME 指定了临时文件目录为/tmp。
# 其效果是在主机 /var/lib/docker 目录下创建了一个临时文件,并链接到容器的/tmp
VOLUME /tmp
# 将jar包添加到容器中并更名为async.jar
ADD sassj-0.1.0.jar test.jar
# 运行jar包
RUN bash -c 'touch /test.jar'
ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/test.jar"]
3.mkdir docker 创建文件夹
4.将Dockerfile文件和jar包置于相同文件夹下
5.docker build -t springbootredis . 创建镜像并指定镜像名
6.docker run -d --name=asyncredis -p 9988:9988 springbootredis
7.docker logs -f 容器id 查看日志
url转文件下载
public void checkDownload(String url, HttpServletResponse response) {
HttpURLConnection conn = null;
try {
File file = new File(url);
// 取得文件的后缀名。
String ext = file.getName().substring(file.getName().lastIndexOf(".") + 1).toLowerCase();
StringBuffer buffername = new StringBuffer(url.substring(url.lastIndexOf("/") + 1));
String filename = buffername.toString();
URL path = new URL(url);
conn = (HttpURLConnection) path.openConnection();
conn.setRequestMethod("GET");
conn.setConnectTimeout(5 * 1000);
InputStream fis = conn.getInputStream();// 通过输入流获取数据
byte[] buffer = readInputStream(fis);
if (null != buffer && buffer.length > 0) {
// 清空response
response.reset();
// 设置response的Header
response.addHeader("Content-Disposition", "attachment;filename=" + new String((filename).getBytes("GBK"), "ISO8859_1"));
response.addHeader("Content-Length", "" + buffer.length);
OutputStream toClient = response.getOutputStream();
response.setContentType("application/octet-stream");
toClient.write(buffer);
toClient.flush();
toClient.close();
}
} catch (IOException ex) {
ex.printStackTrace();
} finally {
if (conn != null) {
conn.disconnect();
}
}
}
private byte[] readInputStream(InputStream fis) throws IOException {
ByteArrayOutputStream outStream = new ByteArrayOutputStream();
byte[] buffer = new byte[1024];
int len = 0;
while ((len = fis.read(buffer)) != -1) {
outStream.write(buffer, 0, len);
}
fis.close();
return outStream.toByteArray();
}
获取linux Ip
private String getLinuxLocalIp() throws SocketException {
String ip = "";
try {
for (Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces(); en.hasMoreElements();) {
NetworkInterface intf = en.nextElement();
String name = intf.getName();
if (!name.contains("docker") && !name.contains("lo")) {
for (Enumeration<InetAddress> enumIpAddr = intf.getInetAddresses(); enumIpAddr.hasMoreElements();) {
InetAddress inetAddress = enumIpAddr.nextElement();
if (!inetAddress.isLoopbackAddress()) {
String ipaddress = inetAddress.getHostAddress().toString();
if (!ipaddress.contains("::") && !ipaddress.contains("0:0:")
&& !ipaddress.contains("fe80")) {
ip = ipaddress.replace(".","");
}
}
}
}
}
} catch (SocketException ex) {
ip = "127.0.0.1";
ex.printStackTrace();
}
return ip;
}
3532

被折叠的 条评论
为什么被折叠?



