67,513
社区成员
发帖
与我相关
我的任务
分享
<?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:aop="http://www.springframework.org/schema/aop"
xmlns:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd">
<aop:aspectj-autoproxy proxy-target-class="true" />
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="configLocation"
value="file:src/hibernate.cfg.xml">
</property>
</bean>
<bean id="transactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory">
<ref local="sessionFactory" />
</property>
</bean>
<bean id="PlayerDAO" class="user.hibernate.PlayerDAO">
<property name="sessionFactory">
<ref bean="sessionFactory" />
</property>
</bean>
<bean id="PlayerDAOProxy"
class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
<!-- 注意这个属性, 详细意义请参考文章开头的参考资料, 必须为 true 使用CGLIB才不用强制编写DAO接口 -->
<property name="proxyTargetClass">
<value>true</value>
</property>
<property name="transactionManager">
<ref bean="transactionManager" />
</property>
<property name="target">
<ref local="PlayerDAO" />
</property>
<property name="transactionAttributes">
<props>
<!-- 这里的方法签名可以精确到方法, 先懒惰一下全配置上 -->
<prop key="*">PROPAGATION_REQUIRED</prop>
</props>
</property>
</bean>
<bean id="Player" class="user.Player"
scope="prototype">
</bean>
<bean id="PlayerAOP" class="user.PlayerAOP"/>
</beans>
package user;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
@Aspect
public class PlayerAOP {
/**
* 定义一个切入点,切入点的名称:allAddMethod(该方法的返回值需要是void,该
* 方法只是一个标识),切入点的内容是一个表达式,以描述需要横切那些对象的那些方法
* 的调用
*/
@Pointcut("execution(* user.Player.trigger*(..)) || execution(* user.Player.save(..))")
public void playerSave(){}
/**
* 定一个advice,标识在那些切入点的何处插入本方法
*/
@Around("playerSave()")
public void checkSecurity(ProceedingJoinPoint pjp) throws Throwable{
System.out.println("playerSave impl...");
//打印所有方法的参数,您也可以在这里自定义您自己的权限检查行为
for(Object p : pjp.getArgs()){
System.out.println(p);
}
System.out.println(pjp);
pjp.proceed();
}
public void triggerLogin(){
}
}