随笔分类 - spring
摘要:http://docs.spring.io/spring/docs/2.0.x/reference/beans.html#beans-factory-scopesIn Spring, bean scope is used to decide which type of bean instance should be return from Spring container back to the caller.5 types of bean scopes supported :singleton – Return a single bean instance per Spring IoC co
阅读全文
摘要:一.Ehcache简介 EhCache是一个纯Java的进程内缓存框架,具有如下特点: 1. 快速简单,非常容易和应用集成。 2.支持多种缓存策略 。 3. 缓存数据有两级:内存和磁盘,因此无需担心容量问题 。 4. 缓存数据会在虚拟机重启的过程中写入磁盘 。 5. 可以通过RMI、可插入API等方式进行分布式缓存。 6. 具有缓存和缓存管理器的侦听接口 。 7. 支持多缓存管理器实例,以及一个实例的多个缓存区域 等特点。 二.Ehcache配置的相关参数 Ehcache的配置很灵活,官方提供的配置方式有好几种,你可以通过声明配置、在xml中配置、在程序里配置或者调用构...
阅读全文
摘要:我们以前要进行单元测试,必须先得到ApplicationContext对象,再通过它得到业务对象,非常麻烦,重复代码也多.基于spring3的单元测试很好的解决了这个问题 基于spring3的单元测试主要用到了下面几个注解 @ContextConfiguration指定配置文件的路径,这个注解用在类上 @Resource 往测试类注入bean,这个bean必须在配置文件中配置,这个注解用在属性或set方法上 @Repeat指定测试方法重复执行的次数,用在测试方法上@Timed指定测试方法在多长时间执行完,如果在指定时间测试方法没有执行完,会抛异常 测试类除了可以使用以上的注解,同时要继承Abs
阅读全文
摘要:TransactionTemplate的源码如下:public class TransactionTemplate extends DefaultTransactionDefinition implements TransactionOperations, InitializingBean{ . . . }TransactionTemplate继承了DefaultTransactionDefinition,实现了TransactionOperations,InitializingBean接口。先研究InitializingBean接口InitializingBean接口为bean提供...
阅读全文
摘要:til:properties in Spring reads configuration file from a location. And id is defined by util:properties and that id can be used to read property from configuration file. In the below example we have a configuration file in the classpath. And I will read it with help of @Value. app-conf.xml<beansx
阅读全文
摘要:1)Struts中的jar包jar包名称作用struts2-core-2.x.x.jarstruts2的核心jar包javassist-3.x.x.GA.jar一个开源的分析、编辑和创建Java字节码的类库(hibernate中也需要,引入其中一个即可)commons-io-2.x.x.jarcommons项目(commons项目就是java中一些常用的公共的组件)的io子项目,是处理异常的commons-lang-2.x.jarcommons项目中的lang包commons-fileupload-1.x.x.jarcommons项目中的关于文件上传的包, struts2.1.6版本后必须加入
阅读全文
摘要:1 <!-- 定义数据源Bean--> 2 <bean id="dataSource" 3 class="org.apache.commons.dbcp.BasicDataSource" 4 destroy-method="close"> 5 <property name="driverClassName" 6 value="${jdbc.driverClassName}" /> 7 <property name="url" valu
阅读全文
摘要:当把项目发布到webapps下后,又在server.xml的Host标签内配置缺省context时会出现如题问题,问题原因及一般解决方案参照,该解决方案修改了tomcat应用的部署结构,虽能解决问他,但不够优雅,缺省context和其他不在同一个目录中。推荐如下解决方案: 1、缺省context不使用Host标签配置context方式,直接把缺省context命名成为ROOT,这种方式的缺点是通过ROOT这个名字不能够从字面上知道context的意义 2、缺省context依然使用Host标签配置context方式,同时使用Host的deployIgnore属性忽略appB...
阅读全文
摘要:由于项目的需要spring的业务相关的bean不是写在xml文件中,因为项目是一个模块一个模块提交的,提交的时候不想修改xml文件,因此就用到了spring的注解Service。例如: Java代码1 @Service("TestService") 2 public class TestService {3 } 这等同于:Xml代码1 <bean id="TestService" class="TestService"/> spring会在classpath里面扫描标记有TestService等标签的类,扫描组件的配置如下
阅读全文
摘要:原文出处:http://blog.chenlb.com/2009/04/spring-use-groovy-dynamic-bean.html在 spring 中使用 groovy 等动态语言的好处就是:在服务器上改改或新加个 groovy 文件就可以有新的功能,不用重新打包并部署。对一些规则性的逻辑处理、动态性强的应用可以 groovy。示例下在 spring 中使用 groovy,我机子环境 spring 2.5.5, groovy-1.5.7。1、模拟业务接口: 1 package com.chenlb.groovy; 2 3 /** 4 * 业务模拟接口 5 * ...
阅读全文
摘要:1,定时凌晨1点执行(由于Quartz 2.0和spring目前版本不兼容,所以采取如下方法,不知道spring3.2会不会修复这个bug) public void doTask(CheckSpiderService doCheck) {// 获取当前时间Calendar currentDate = Calendar.getInstance();long currentDateLong = currentDate.getTime().getTime();// 计算满足条件的最近一次执行时间Calendar earliestDate = getEarliestDate(currentDate..
阅读全文