Arganzheng's Blog

stay hungry, stay foolish

Quartz与Spring的整合-Quartz中的job如何自动注入spring容器托管的对象

问题 Quartz中的job是由Quartz框架动态创建的(配置该job的classname,通过反射创建),而job一般会依赖到配置在spring中的bean,怎样获取或者更好的自动注入这些依赖bean呢? 预期效果 我们希望达到这样的效果: /** * * 取消超时未支付订单的任务。 * * @author arganzheng */ public class CancelUnpaidOrderTask implements Job { @Autowired private AppOrderService orderService; @Override public void execute(JobExec...

Linux下如何备份旧文件

将30天前的文件打包压缩备份,然后删除原文件 今天王岩发了一个shell脚本让大家review一下: mmddnew=`date "+%Y%m%d"` basedir="/data/tomcatlog/api/reconciliationFiles/" echo ${mddnew} cd ${basedir} echo "压缩" find ./ -maxdepth 1 -type f -mtime +30 | xargs tar czvf ./${mmddnew}.tar echo "移动压缩包" mv ./${mmddnew}.tar ./bak/ echo "删除旧的文件" find ./ -maxdepth 1 -type f -mtime +30 -ex...

maven的resources插件

maven的resources插件职责是将项目的资源文件拷贝到目标目录。maven将资源划分为两类:main resources 和 test resources。因此有如下三个相应的goal: 1. resources:resources command: mvn resources:resources bound by default to the process-resources life-cycle phase copies the resources for the main source code to the main output directory the resources for your main source cod...

Spring事务配置

原理 Spring是基于proxy方式的事务实现机制。如果你的target实现了某个接口,那么Spring可以根据这个接口动态生成一个proxy,在你的service方法前后进行如下事务管理: tx.begin(); try{ target.service(); }catch(Exception e){ tx.rollback(); } tx.commit(); 而动态代理的生成方式,Spring支持两种: 如果target有实现接口,那么使用JDK动态代理 否则使用CGLIB Proxy Creates a JDK proxy when proxy interfaces are given, and a CGLI...

如何不刷新页面上传文件

场景: 一个表单页面:有很多字段,其中有一个是上传图片字段,如何提交这个表单页面。 解决方案 方案1. iframe + hidden field 为了不刷新页面,一般来说要不就是对文件标签使用iframe和单独的form来提交。提交到iframe指定的action处理完成后,将文件上传路径回写到父页面的某个字段。需要在iframe中区分是否已经上传了文件。 如:http://apitest.buy.qq.com/apitools/imgUpload.xhtml?imgName=pic <html> <head> <meta name="description" content="腾讯电商" />...

如何往HttpServletRequest中塞请求参数

需求 假如用户没有传递cooperatorId,那么默认等于uin。 常规做法是在interceptor或者filter或者action中判断如果没有cooperatorId参数,则设置到request的parameterMap中: String cooperatorId = request.getParameter("cooperatorId"); if(cooperatorId == null){ request.getParameterMap().put("cooperatorId",request.getParameter("uin")) ; } 问题 public interface ServletRequest { ...

URL encoding学习笔记

最近在搞一个Open API在线测试工具,出现一些问题,因此接触到了URL Encoding相关方面的东西。 首先要了解一下什么是URL Encoding: URL Encoding is the process of converting string into valid URL format. Valid URL format means that the URL contains only what is termed “alpha digit safe extra escape” characters. 然...

海量图片存储思考

最近在学习分布式存储和数据分析相关的东西,特别是看了Facebook的这篇论文:Finding a needle in Haystack: Facebook’s photo storage,感觉特别与阿里巴巴现在的现状类似。阿里现在的图片存储正处于Facebook的原始阶段——CDN(中美有各自的CDN) ==> imageServer(apache+squid) ==> NFS共享存储。 说明 CDN的作用 CDN只适合于缓存popular static content(images, html, css, js, etc.)。对于long tail(长尾)文件,并不适合。这就是我们上次ASC从前台dump图片,将存储搞挂的原因。faceboo...

Using Fabric to Type Less

Fabric is a tool written in Python that lets you defind tasks and execute them by running fab taskname. Fabfiles are pure Python, so you can build larger tasks out of smaller ones very easily and do just about anything you want. It’s similar to ant, but without the excessive over-engineering. from fabric.api import * import os imp...

尽量用英文写博客

原因很简单,linux下的中文输入法实在是太烂了,如果是进行大量的编辑行为(如写博客),那么即使是使用vim,带来的便利也被超烂的输入法给抵消掉了,而且vim下不断的切换输入法实在是痛苦。在我没有找到或者自己写一个好用的中文输入法之前,为了提高效率,我将尝试使用英文来表达我的意思,可能会中英文混淆或者Chiness-English,但是这是一个开始。我觉得在方向上是好的。

×