This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//1. 开启功能@EnableScheduling | |
//2. 配置线程池 | |
//spring默认(不配置线程池)为单线程,一个任务执行完成才会执行下一个任务。 | |
@Configuration | |
public class TaskConfigure{ | |
@Bean | |
public TaskScheduler taskScheduler(){ | |
ThreadPoolTaskScheduler taskScheduler=new ThreadPoolTaskScheduler(); | |
taskScheduler.setPoolSize(20);//线程池 | |
return taskScheduler; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.springframework.beans.factory.annotation.Autowired; | |
import org.springframework.data.redis.core.RedisCallback; | |
import org.springframework.data.redis.core.RedisTemplate; | |
import org.springframework.stereotype.Component; | |
import java.util.Objects; | |
@Component("redisHelper") | |
public class RedisHelper { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
source /etc/profile | |
basedir=`dirname $0` | |
cd $basedir | |
for i in `ls -t *.jar` | |
do | |
#echo $i | |
break | |
done |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@echo off | |
setlocal enabledelayedexpansion | |
set port=30056 | |
for /f "tokens=1-5" %%a in ('netstat -ano ^| find ":%port%"') do ( | |
if "%%e%" == "" ( | |
set pid=%%d | |
) else ( | |
set pid=%%e | |
) | |
echo !pid! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sh内容: | |
source ~/.bash_profile | |
killall java | |
nohup java -jar /root/springbootdemo/springbootdemo-0.0.1-SNAPSHOT.jar > nohup.log 2>&1 & | |
执行命令 | |
sh /root/sh/restart-springboot.sh |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.springframework.beans.BeansException; | |
import org.springframework.context.ApplicationContext; | |
import org.springframework.context.ApplicationContextAware; | |
import org.springframework.stereotype.Component; | |
@Component | |
public class SpringContextUtil implements ApplicationContextAware { | |
private static ApplicationContext applicationContext; // Spring应用上下文环境 | |
/* |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import javax.sql.DataSource; | |
import org.springframework.beans.factory.annotation.Autowired; | |
import org.springframework.context.annotation.Bean; | |
import org.springframework.context.annotation.Configuration; | |
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; | |
import org.springframework.security.config.annotation.web.builders.HttpSecurity; | |
import org.springframework.security.config.annotation.web.builders.WebSecurity; | |
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//1当普通调用时,一般跳转到自定义的错误页面。 | |
//2当ajax调用时,可返回约定的数据对象,方便页面统一处理。 | |
import java.util.HashMap; | |
import java.util.Map; | |
import javax.servlet.http.HttpServletRequest; | |
import org.springframework.web.bind.annotation.ControllerAdvice; | |
import org.springframework.web.bind.annotation.ExceptionHandler; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
response.setCharacterEncoding(request.getCharacterEncoding()); | |
response.setContentType(MediaType.APPLICATION_OCTET_STREAM.toString()); | |
String realFileName = URLEncoder.encode(realFileName, StandardCharsets.UTF_8.toString()); | |
// 解决中文文件名乱码关键行 | |
response.setHeader("Content-Disposition", "attachment; filename=\"" + realFileName + "\"; filename*=utf-8''" + realFileName); | |
Path path = Paths.get(filePath+filename); | |
Files.copy(path, response.getOutputStream()); | |
response.flushBuffer(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
if [ ! -n "${LIQUIBASE_HOME+x}" ]; then | |
# echo "LIQUIBASE_HOME is not set." | |
## resolve links - $0 may be a symlink | |
PRG="$0" | |
while [ -h "$PRG" ] ; do | |
ls=`ls -ld "$PRG"` | |
link=`expr "$ls" : '.*-> \(.*\)$'` |