一、AOP的简单实用Demo
beans.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:aop="http://www.springframework.org/schema/aop"
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-3.0.xsd ">
<!-- bean definition & AOP specific configuration -->
<bean id="studentService" class="com.kjgym.service.impl.StudentServiceImpl"></bean>
<bean id="studentServiceAspect" class="com.kjgym.advice.StudentServiceAspect"></bean>
<!-- AOP简单配置 -->
<aop:config>
<aop:aspect id="studentServiceAspect2" ref="studentServiceAspect">
<!--
execution()方法表达式
* com.kjgym.service.*.*(..)
第一个 * 代表返回值
*代表任意, *.*代表service包下任意类
小括号里代表方法,两个点代表任意参数
-->
<aop:pointcut expression="execution(* com.kjgym.service.*.*(..))" id="businessService"/>
<!-- 切入方式:前置 后置 环绕 返回 异常 -->
<!-- method的值对应 id="studentServiceAspect2" 里面的方法 -->
<aop:before method="doBefore" pointcut-ref="businessService"/>
<aop:after method="doAfter" pointcut-ref="businessService"/>
<aop:around method="doAround" pointcut-ref="businessService"/>
<aop:after-returning method="doAfterReturning" pointcut-ref="businessService"/>
<aop:after-throwing method="doAfterThrowing" pointcut-ref="businessService" throwing="ex"/>
</aop:aspect>
</aop:config>
</beans>
二、Eclipse设置自动提示,即不需要每次点“alt+/”。
(一)Java代码自动提示
- 打开 Eclipse -> Window -> Perferences ->Java ->Editor ->Content Assist
- 下面的Auto activation triggers for Java: 只有一个”.”存在,意思是输入“.”的时候会自动提示。将“.”删掉,改成成”abcdefghijklmnopqrstuvwxyz.”即可。
- 如下图:
(二)设置xml代码自动提示
- Windows->preferance->XML->XML Files->Editor->Content Assist
- Auto Activation 将Prompt when these characters are inserted后面的文本框中的“<=:”替换成
“<=:abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ ”(注意后面还有一个空格) - 如下图: