ITeye博客

GodJohnny

GodJohnny · 共 32 篇文章

SpringBoot里REST上传大数据时的大小配置

前端以REST的方式上传图片时,Sprintboot服务器出现以下异常: The multi-part request contained parameter data (excluding uploaded files) that exceeded the limit for maxPostSize set on the associated connector. 参考该链接:http://stackoverflow.com/questions/33232849/increase-http-post-maxpostsize-in-spring-boot 需要同时修改以下两个配置: 1、修改…

2017-01-12 14:43 · 评论(0)

iptables 配置略记

使用iptables配置的频率非常低,但每次都要查一下资料,还是比较麻烦的。其实命令看起来繁琐,还是有规律可记的。 首先,iptables --help 下,看下大概的命令参数。 添加进入规则: iptables -A -p --dport -j ACCEPT 其中chainname,常用的就是INPUT,OUTPUT两种,通过iptables -L 可以查看到。入口规则,填INPUT。--dport填下访问的端口。 添加出口规则: iptables -A OUTPUT -p tcp --sport 8081 -j ACCEPT 类似于入口规则,只是 -A 变成了OUTPUT,--sport…

2016-12-02 16:12 · 评论(0)

SpringMVC在INFO级别下记录请求响应日志

我们在开发、测试环境中,日志的级别通常设置为DEBUG。部署到生产环境时,别经常被设置为INFO级别,以减少日志的输出量。但DEBUG时可以看到的一些请求、响应参数,也就看不到了。为了方便排查一些线上问题,需要记录下请求、响应的参数等。 有多种方式可以实现该需求,如添加Filter,手动记录日志等。这儿使用一个简单的方式,直接将DEUBG级别时的请求、响应内容输出出来。系统是使用logback来记录日志的,直接在logbak.xml中将请求、响应处理类的日志级别调整为DEBUG即可。 <logger name="org.apache.coyote.http11.Http11InputBuff…

2016-11-15 17:05 · 评论(0)

使用RSA密钥生成JWT

在内部系统上调用基础服务时,在基础服务上加上OAuth验证,基于Spring boot OAuth2.0实现,采用JsonWebToken的方式。accessToken由调用者自己生成,基于RSA生成私钥签名,基础服务公钥验证。 accessToken的生成采用开源的JJWT实现,基础服务的OAuth由spring-security-oauth2框架来自动实现(见: http://godjohnny.iteye.com/blog/2320220 )。 生成accessToken的步骤: 1、生成密钥库文件。 使用keytool。具体过程略。 2、使用该密钥文件生成accessToken 2.…

2016-10-26 18:08 · 评论(1)

Spring使用FastJson作为消息转换器时,不能使用Swagger的问题

因为Fast作为JSON的序列化与反序列化一些优点,在项目中使用了FastJson库的FastJsonHttpMessageConverter4 作为Spring的消息转换器,可替换后,发现http://localhost:8081/swagger-ui.html页面能打开,但API内容都不见了。但v2/api-docs倒是能打开。 替换回Spring默认的Jackson2,页面打开正常。经过抓包,发现使用不同的转换器时,页面打开请求的URL是不同的。使用FastJson时,到swagger-resources/configuration/ui请求后,就结束了。而默认的Jackson2在此之…

2016-10-25 09:18 · 评论(1)

SpringMVC相关的杂记

一、Spring Boot:定制HTTP消息转换器 http://www.jianshu.com/p/ffe56d9553fd

2016-10-24 15:09 · 评论(0)

swagger/springfox 使用杂记

参考资料: http://heidloff.net/article/usage-of-swagger-2-0-in-spring-boot-applications-to-document-apis/ http://jakubstas.com/spring-jersey-swagger-create-documentation/#.WAcMhvl96Cp http://springfox.github.io/springfox/ 备忘几个常用的注解: 1、@ApiIgnore 用于屏蔽一些不想在文档中显示的接口 2、tag的使用 有一些接口定义,写在不同的Controller中,但在文档中想…

2016-10-19 14:07 · 评论(0)

Spring boot 启动时间非常长的问题

一次项目实施过程中,发现线上的Spring boot在启动时,耗时非常长。在日志中发现这样的情况: o.a.c.util.SessionIdGeneratorBase : Creation of SecureRandom instance for session ID generation using [sha1prng] took [170,241] milliseconds. 查找相关资料,发现是随机数生成器的问题。需要在启动命令里加上 -Djava.security.egd=file:/dev/./urandom

2016-09-20 16:44 · 评论(0)

Gradle打包可直接运行的spring-boot应用

参考资料: https://spring.io/guides/gs/spring-boot-docker/ 首先,修改build.gradle,在dependencies中添加gradle-docker: dependencies { classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}") [b]classpath('se.transmode.gradle:gradle-docker:1.2')[/b] } 再添加插件: apply plugin: 'spring-boot' […

2016-09-02 14:50 · 评论(0)

基于SpringSecurityOAuth2构建SSO

参考资料: http://www.ruanyifeng.com/blog/2014/05/oauth_2_0.html http://projects.spring.io/spring-security-oauth/docs/oauth2.html https://tools.ietf.org/html/rfc6749 https://tools.ietf.org/html/rfc6750 http://tutorials.jenkov.com/oauth2/index.html http://stackoverflow.com/questions/12296017/how-to-valid…

2016-08-25 21:58 · spring · Security · 评论(0)

Spring Security实现自定义验证的两种方式及Restful登录验证

在现实项目中,经常出现用户登录验证时,需要验证除了用户名、密码外的其他项,或额外的验证逻辑。当使用Spring Security框架时,就需要修改默认的验证方式。当以form表单方式登录时,可以有两种方式实现,任意实现一种即可。以Restful的方式提交JSON格式参数登录时或Restful,form方式混用时,可以两种方式结合使用。 第一种方式,自定义AuthenticationProvider。这种方式在authenticate(Authentication authentication)方法中实现验证逻辑。supports方法返回true,才会执行authenticate方法。 实现完…

2016-08-25 21:40 · spring · Security · 评论(0)

升级CentOS内核

参考资料: http://my.oschina.net/denglz/blog/487332?p={{page}} http://elrepo.org/tiki/tiki-index.php 网上有不少升级CentOS内核的文章,如《CentOS 6.5 升级内核到 3.10.28》,大部分都是下载源码编译,有点麻烦。 在yum的ELRepo源中,有mainline(3.13.1)、long-term(3.10.28)这2个内核版本,考虑到long-term更稳定,会长期更新,所以选择这个版本。 1、导入public key rpm --import https://www.elrepo.o…

2016-08-22 11:56 · 评论(0)

SpringMVC被初始化两次的问题

项目部署到生产服上后,发现一个定时器任务的Bean在指定时间连续执行了两次。加日志调试发现这个Bean被初始化了两次,再进一步添加日志调试发现Web的启动类,也就是AbstractAnnotationConfigDispatcherServletInitializer的子类也被执行了两次。而在开发环境的IDE中测试时,则没有这种现象。于是怀疑是Tomcat的问题,但开发环境与生产环境的版本一致,只有开发环境中对Tomcat对根路径做了修改。 参照:http://www.lxway.com/206659492.htm 提供的方法: 方法1:不配置根路径访问 方法2:将路径已出webapp目录,…

2016-07-08 08:52 · JAVA · tomcat · spring s · 评论(0)

Intellij Ideal创建基于Gradle的Spring boot项目

使用Intellij Ideal中Create new project --> Spring Initializr创建一个基于Spring boot的项目。但默认的这个项目是基于eclipse的,需要修改下build.gradle: 1 删除最底部关于eclipse的classpath部分 2 我这边的网络压根连不上repo1.maven.org/maven2。因此,修改了两处repositories为如下格式: repositories { //mavenCentral() maven { url "http://repo2.maven.org/maven2/" } } 再在Gradle …

2016-07-08 08:51 · 评论(0)

XCode生成真机、模拟器动态库的脚本

参考自:http://www.jianshu.com/p/1cb4c4fe5481 Sets the target folders and the final framework product. 如果工程名称和Framework的Target名称不一样的话,要自定义FMKNAME 例如: FMK_NAME = "MyFramework" FMK_NAME=${PROJECT_NAME} Install dir will be the final output to the framework. The following line create it in the root folder …

2016-07-01 15:20 · 评论(0)