Spring md5加密工具
String md5Result = org.springframework.util.DigestUtils.md5DigestAsHex("待加密字符串".getBytes());
从Spring容器中随时获取request
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
HttpServletRequest request = ((ServletRequestAttributes)RequestContextHolder.getRequestAttributes()).getRequest();
spring 允许跨域访问
//在controller方法中添加@CrossOrigin注解即可
@CrossOrigin
@RequestMapping("/hello")
public String hello(){
return "hello";
}
使用spring注解读取配置文件内容
@Vaule("${XXXConfig}")
private String XXXConfig ;
解决迭代过程中springboot打包jar文件过大
1. 首先将依赖导出:mvn dependency:copy-dependencies
2.运行:mvn dependency:tree 分析项目依赖树
3.用正则查找复制出所有依赖包的groupId
4.将groupId列表粘贴到excel中去重(数据-去除重复项)
5.修改maven打包配置如下:
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<layout>ZIP</layout>
<excludeGroupIds>
org.springframework.boot,
...
</excludeGroupIds>
</configuration>
</plugin>
</plugins>
6.运行:nohup java -Dloader.path=lib/ -Dspring.profiles.active=prod -jar xxx.jar &
备注:win系统可能无法正常运行,linux测试正常