ITeye博客

2014 年文章归档

共 94 篇文章

select2 清空数据

select2.js 没有清空数据的API,下面的方法可以间接的提供该功能。 $('#memberKey').select2('data', null);

2014-12-17 11:45 · javascript · jQuery · select2

Spring JUnit 的单测中如何获取当前spring的ApplicationContext上下文

我在写单测的时候(spring环境下的单元测试)想获得当前spring的ApplicationContext上下文。我是这样实现的: import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.BeansException; import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationC…

2014-12-11 14:48 · java · Spring

Spring使用@Autowired不能注入BlockingQueue的问题

今天遇到一个问题,使用spring4配置BlockingQueue,在Java代码里面使用@Autowired注释方式注入该BlockingQueue,一直报错。 我的代码如下: @Autowired private BlockingQueue<CoreTask> alarmInnerQueue; 我的XML如下: <bean id="alarmInnerQueue" class="org.kanpiaoxue.test.concurrent.UniqueLinkedBlockingQueue"/> 说明一下,UniqueLinkedBlockingQueue 这个类是BlockingQue…

2014-12-09 14:25 · java · Spring

Spring如何注入Date类型的变量

地址: http://k2java.blogspot.com/2011/04/spring-how-to-pass-date-into-bean.html Thursday, April 14, 2011 Spring – How to pass a Date into bean property (CustomDateEditor ) Simple method may not work Generally, Spring developer are not allow to pass a date format parameter into bean property via DI. F…

2014-12-09 13:59 · java · Spring

Netty4 httpserver

/** * <pre> * AjaxResult.java * @author kanpiaoxue<br> * @version 1.0 * Create Time 2014年12月4日 下午6:01:05<br> * Description : ajax请求结果 * </pre> */ public class AjaxResult { private int code; private String message; private Object body; public static AjaxResult SUCCESS = new AjaxResult(0, "success");…

2014-12-04 19:12 · java · Netty

spring ehcache 单测报错:ehcache具有相同的名称的解决方案

地址: http://www.captaindebug.com/2012/09/spring-31-caching-and-ehcache.html#.VHPs-568eCk Tuesday, 25 September 2012 Spring 3.1: Caching and EhCache If you look around the web for examples of using Spring 3.1’s built in caching then you’ll usually bump into Spring’s SimpleCacheManager , which the Guy…

2014-11-25 10:44 · java · Spring · ehcache

如何在程序中使用classpath里面的文件呢?

Resource resource = new ClassPathResource("ehcache-console.xml"); 上面的这段代码,使用了classpath里面的一个Ehcache的xml配置文件。为了达到这个目的,我使用了spring提供的 org.springframework.core.io.Resource 接口以及它的一个实现类。

2014-11-19 17:42 · java · Spring

easyui datagrid 添加toolbar

[ { text: '增加', iconCls: 'icon-add', handler: function () { } }, { text: '修改', iconCls: 'icon-edit', handler: function () { } }, { text: '删除', iconCls: 'icon-remove', handler: function () { } }, { text: '查看', handler: function () { } }, '-', { text: '刷新', iconCls: 'icon-reload', handler: function (…

2014-11-13 16:27 · javascript · jQuery · easyui

select2 插件的选项无法选中

select2 是一个可以自动补全的插件。 官网地址: http://ivaynberg.github.io/select2/ 使用“Loading Remote Data”的例子,利用ajax从服务器端获得json数据,展现在select2上面。 发现一个问题:不能选择这些选项。 原始代码如下: $('#searchTasksSelectId').select2({ width : 450, placeholder : '任务名称/资源名称', minimumInputLength : 1, ajax : { // instead of writing the function to ex…

2014-11-07 15:52 · javascript · jQuery · select2

Configuration can't be altered once the class has been compiled or used

使用Spring org.springframework.jdbc.core.simple.SimpleJdbcInsert获得table的元数据的时候,报错: org.springframework.dao.InvalidDataAccessApiUsageException: Configuration can't be altered once the class has been compiled or used 找了资料,是这么说的: 写道 compiled means you have instantiated a simpleJdbcInsert instance and se…

2014-11-05 19:31 · java · Spring

eclipse tomcat server的console乱码问题

在eclipse启动tomcat的是否,我发现log4j打印出来的汉字是乱码。我的workspace的编码确实是UTF-8,我的文件编码,JSP编码都是UTF-8,为何启动eclipse启动tomcat依然乱码呢。 我找到了解决办法。 解决问题之前,如图: 解决的办法:进入eclipse配置tomcat的地方,给JVM添加参数 -Dfile.encoding=UTF-8 (myeclipse的截图) 这样之后,console就不乱码了。如图:

2014-11-05 17:42 · eclipse · tomcat

maven指定单测的测试类

mvn -Dtest=Random*Test clean test mvn -Dtest=RandomGeratorTest,AccountCaptchaServiceTest clean test mvn -Dtest=Random*Test,AccountCaptchaServiceTest clean test

2014-11-04 15:14 · maven

如何启动eclipse时提示选择工作空间

我们使用eclipse的时候一般都是使用一个默认的workspace,但是当我们经常需要在启动eclipse的时候指定workspace,就需要它启动的时候给出提示,进行workspace的选择。该如何设置呢?如下: 写道 Window -> Preferences -> General -> Startup and Shuodown -> Prompt for workspace on startup

2014-11-03 21:23 · eclipse

Spring整合JUnit4测试使用注解引入多个配置文件

我们使用spring写junit单测的时候,有的时候我们的spring配置文件只有一个。我们在类的注释上面会这样写: @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(locations = "classpath*:spring-ctx-application.xml") 但有的时候我们的项目很复杂,其中的spring配置文件被拆分成了多个,这样该如何写上面这段单测代码而引入多个配置文件呢?如下: @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration…

2014-11-03 15:16 · java · Spring · junit

jetty: 请求的操作无法在使用用户映射区域打开的文件上执行

eclipse中的maven运行jetty的时候: run:jetty 以后,发现静态资源文件修改后无法保存,eclipse提示 “请求的操作无法在使用用户映射区域打开的文件上执行”。如图: ========================================== 这是因为jetty里面对使用的文件进行了缓存。 解决方法如下: 版本:jetty 6 打开自己的maven本地仓库 .m2\repository\org\mortbay\jetty\jetty\6.1.22 修改 jetty-6.1.22.jar 中 org/mortbay/jetty/webapp/webdefaul…

2014-10-30 14:26 · eclipse · maven · jetty

关于系统中使用多个PropertyPlaceholderConfigurer的配置

应用自: http://seraph115.iteye.com/blog/435165 ================================================================================ 多数的鲜为人知方法都是因为有着罕见的应用,就比如说Spring中PropertyPlaceholderConfigurer这个类,它是用来解析Java Properties属性文件值,并提供在spring配置期间替换使用属性值。接下来让我们逐渐的深入其配置。 基本的使用方法是:(1) Xml代码 <bean id="propertyConfigu…

2014-10-22 16:27 · Spring

eclipse打开文件所在的本地文件夹

我们在使用eclipse编码的时候需要打开该文件所在的本地磁盘的文件夹,很不方便。这里有款eclipse的插件,能方便的做到这点。 OpenExplorer https://github.com/samsonw/OpenExplorer/downloads 将下载之后的jar放在eclipse的plugins文件夹或者dropins文件夹下,重启eclipse就可以使用了。 当你想定位eclipse中某个文件在磁盘上面的文件夹的时候,只要你选择该文件,鼠标右键里面就含有“OpenExplorer”的菜单。

2014-10-22 09:13 · eclipse

RestTemplate访问Protobuf

使用RestTemplate访问google的protobuf的例子。其实很简单,Client端的代码如下: RestTemplate restTemplate = new RestTemplate(); byte[] rs = restTemplate.getForObject(url, byte[].class, args); ProtobufResult.PBResult obj = ProtobufResult.PBResult.parseFrom(rs); RestTemplate的另一种声明,使用spring的xml,利用HttpClient的高级功能。 <bean id="re…

2014-09-28 15:05 · java · Spring · REST · protobuf · RestTemplate

Window7定时任务配置

附件中有具体的操作方法和图示。

2014-09-26 17:14 · windows

基于base64的简单加密/解密程序(不安全,因为base64是通用的)

我们在WEB程序中经常会用到加密解密一些内容。下面给出一个简单的加密解密程序。 不安全,因为base64是通用的。但是对于简单的混淆是可以使用的。如果要高强度的加密,应该选择加密算法,如:DES 等。 该程序使用了Google的Guava框架。 https://code.google.com/p/guava-libraries/ import com.google.common.base.Charsets; import com.google.common.base.Preconditions; import com.google.common.base.Strings; import co…

2014-09-20 10:17 · java · 经验 · guava