java笔记:自己动手写javaEE框架(二) (二)
.println(invocation.getThis());
System.out.println("调用的方法:");
System.out.println(invocation.getMethod());
System.out.println("参数是:");
for (int i = 0;i < invocation.getArguments().length;i++)
{
Object[] objs = invocation.getArguments();
System.out.println(objs[i]);
}
obj = invocation.proceed();
System.out.println("返回结果是:");
System.out.println(obj);
System.out.println("拦截器执行结束!!");
return obj;
}
}
拦截器的注解我今天不写,太晚了,而且记得不清,下一篇里我会补上这些内容。
5.下面是修改后的applicationContext.xml配置文件,内容如下:
< xml version="1.0" encoding="UTF-8" > <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd"> <context:component-scan base-package="cn.com.sharpxiajun" /> <bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> <property name="locations"> <list> <value>classpath:conf/constants.propertiesvalue> list> property> bean> <bean id="myDataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"> <property name="driverClassName" value="${db.driverClass}"/> <property name="url" value="${db.jdbcUrl}"/> <property name="username" value="${db.user}"/> <property name="password" value="${db.password}"/> bean> <bean id="sqlMapClient" class="org.springframework.orm.ibatis.SqlMapClientFactoryBean"> <property name="configLocation"> <value>classpath:conf/SqlMapConfig.xmlvalue> property> <property name="dataSource" ref="myDataSource"/> bean> <bean id="sqlMapClientTemplate" class="org.springframework.orm.ibatis.SqlMapClientTemplate"> <property name="sqlMapClient"> <ref local="sqlMapClient"/> property> bean> <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> <property name="dataSource"> <ref local="myDataSource"/> property> bean> <bean id="methodServiceAdvisor" class="cn.com.sharpxiajun.common.aop.MethodServiceAdvisor"/> <aop:config> <aop:pointcut id="baseServiceMethods" expression="execution(* cn.com.sharpxiajun.service.*.*(..))"/> <aop:advisor advice-ref="methodServiceAdvisor" pointcut-ref="baseServiceMethods"/> aop:config> beans>
这里用到了aop:config这是spring为了迎合AspectJ,对于AspectJ这个以后有机会我也想研究下,写篇文章。
6.最后编写针对UsersService的测试类UsersServiceImplTest,所在包是:cn.com.sharpxiajun.junittest.service,代码如下:
package cn.com.sharpxiajun.junittest.service; import java.util.HashMap; import java.util.List; import java.util.Map; import org.junit.After; import org.junit.Before;