https://github.com/getwingm/Micro-Service-Skeleton
https://github.com/getwingm/yiiu单点登录
https://github.com/getwingm/SpringBoot-vue
分类目录归档:Java开发
oauth2例子
oauth的springcloud的oauth例子。
https://github.com/getwingm/spring-security-oauth2-example
Prometheus开源监控告警解决方案
Prometheus是由 SoundCloud 开源监控告警解决方案2015 年在 github 上开源以来,已经吸引了 很多大公司的使用.
joda时间库
在java中,时间计算是比较痛苦的,因此有人封装了一个牛逼的时间库,用过的人都说很简单。
http://www.joda.org/joda-time/
基于rbac的开源
角色权限系统
————–
基于spring-boot和shiro的分布式权限管理系统。 旨在将权限系统和业务系统分离
https://github.com/wzypandaking/rbac-shiro
——————————-
node
https://github.com/optimalbits/node_acl
https://github.com/ciaranj/node-oauth
https://github.com/lidianhao123/egg-rbac 这是egg的框架
—egg———-的cms
https://github.com/MrMoveon/nodecms.git
javacv相关
javacv是一款基于opencv的java版视觉处理库,同时也集成了ffmpeg,非常适合java服务端处理数据。当然c++服务端,依旧推荐使用opencv+ffmpeg了。
以下是javacv的rtmp/rtsp的直播例子,也可搜索关键字“javacv开发详解”。
https://blog.csdn.net/eguid_1/article/details/51659578
https://blog.csdn.net/column/details/12986.html
顺便说一下,直播方案之一是:nginx+nginx-rtmp-module+ffmpeg可快速拾搭建直播流媒体服务器。
springboot的启动脚本配置
springboot启动与停止的最基本的脚本配置
#!/bin/sh path_current=`pwd` path_script=$(cd "$(dirname "$0")"; pwd) mode=$1 app_process=`ps -ef | grep "waypal-tracker-server.jar"| grep -v grep` case "$mode" in 'start') echo "it's ready to start op...." if test -n "$app_process"; then echo "" echo "$app_process" echo "" else cd $path_script #进入脚本所在目录下,目的是使springboot的config目录生效。 nohup java -jar $path_script/bin/waypal-tracker-server.jar logPath=$HOME/waypalers.cn/tracker/data > /dev/null 2>&1 & cd $path_current fi echo 'success to start.' ;; 'stop') echo "it's ready to check process..." if test -n "$app_process"; then echo "had find app process informaton" echo $app_process | awk '{print ($2)}' | xargs kill -9 fi echo 'success to kill.' ;; *) basename=`basename "$0"` echo "Usage: $basename {start|stop} [ server options ]" exit 1 ;; esac exit 1 |
springboot的外部配置文件
springboot允许以下四种方式加载配置文件,其优先级如下:
http://docs.spring.io/spring-boot/docs/current-SNAPSHOT/reference/htmlsingle/#boot-features-external-config
spring boot允许你自定义一个application.properties文件,然后放在以下的地方,来重写spring boot的环境变量或者定义你自己环境变量
1.当前目录的 “/config”的子目录下
2.当前目录下
3.classpath根目录的“/config”包下
4.classpath的根目录下
springboot跳过测试
springboot的默认配置下,使用[mvn package]指令打包,会进行单元测试的检查,可以选择直接跳过单元测试。
mvn install -DskipTests 或 mvn install -Dmaven.test.skip=true |
如何判断是否为中国IP
亚洲所有相关分配的IP段可以从 http://ftp.apnic.net/apnic/stats/apnic/delegated-apnic-latest 查询。
从里面解释后即可实现判断IP是否为中国。
import java.io.InputStream; import java.nio.charset.StandardCharsets; import java.util.Collections; import java.util.List; import java.util.Map; import org.apache.commons.io.IOUtils; import org.apache.commons.lang3.StringUtils; import org.assertj.core.util.Lists; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import com.google.common.collect.Maps; public class IpUtil { private static final String FILE_NAME = "delegated-apnic-latest"; // 只存放属于中国的ip段 private static Map<Integer, List<int[]>> chinaIps = Maps.newHashMap(); static { init(); } public static void init() { try { // ip格式: add1.add2.add3.add4 // key为 : add1*256+add2 // value为int[2]: int[0]存的add3*256+add4的开始ip int[4]存的结束ip Map<Integer, List<int[]>> map = Maps.newHashMap(); InputStream input = Thread.currentThread().getContextClassLoader().getResourceAsStream(FILE_NAME); List<String> lines = IOUtils.readLines(input, StandardCharsets.UTF_8); for (String line : lines) { if (line.startsWith("apnic|CN|ipv4|")) { // 只处理属于中国的ipv4地址 String[] strs = line.split("\\|"); String ip = strs[3]; String[] add = ip.split("\\."); int count = Integer.valueOf(strs[4]); int startIp = Integer.parseInt(add[0]) * 256 + Integer.parseInt(add[1]); while (count > 0) { if (count >= 65536) { // add1,add2 整段都是中国ip chinaIps.put(startIp, Collections.EMPTY_LIST); count -= 65536; startIp += 1; } else { int[] ipRange = new int[2]; ipRange[0] = Integer.parseInt(add[2]) * 256 + Integer.parseInt(add[3]); ipRange[1] = ipRange[0] + count; count -= count; List<int[]> list = map.get(startIp); if (list == null) { list = Lists.newArrayList(); map.put(startIp, list); } list.add(ipRange); } } } } chinaIps = map; } catch (Exception e) { logger.error("ERROR", e); } } public static boolean isChinaIp(String ip) { if (StringUtils.isEmpty(ip)) { return false; } String[] strs = ip.split("\\."); if (strs.length != 4) { return false; } int key = Integer.valueOf(strs[0]) * 256 + Integer.valueOf(strs[1]); List<int[]> list = chinaIps.get(key); if (list == null) { return false; } if (list.size() == 0) { // 整段都是中国ip return true; } int ipValue = Integer.valueOf(strs[2]) * 256 + Integer.valueOf(strs[3]); for (int[] ipRange : list) { if (ipValue >= ipRange[0] && ipValue <= ipRange[1]) { return true; } } return false; } private static final Logger logger = LoggerFactory.getLogger(IpUtil.class); } |