parent
167085c8e8
commit
bd6c442cbb
@ -0,0 +1,41 @@
|
||||
<?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
|
||||
https://www.springframework.org/schema/beans/spring-beans.xsd
|
||||
http://www.springframework.org/schema/aop
|
||||
https://www.springframework.org/schema/aop/spring-aop.xsd">
|
||||
|
||||
<!-- 商品 -->
|
||||
<bean id="product" class="com.ssm.aop.xml.Product">
|
||||
<property name="pid" value="1"/>
|
||||
<property name="pname" value="青皮香玉芒果"/>
|
||||
<property name="shopPrice" value="20.0"/>
|
||||
<property name="category" ref="category"/>
|
||||
</bean>
|
||||
|
||||
<!-- 分类 -->
|
||||
<bean id="category" class="com.ssm.aop.xml.Category">
|
||||
<property name="cid" value="1"/>
|
||||
<property name="cname" value="水果"/>
|
||||
</bean>
|
||||
|
||||
<!-- 切面 -->
|
||||
<bean id="logAspect" class="com.ssm.aop.xml.Log"/>
|
||||
|
||||
<!-- AOP配置 -->
|
||||
<aop:config>
|
||||
<aop:pointcut id="logPointcut"
|
||||
expression="execution(* com.ssm.aop.xml.Product.printInfo(..))"/>
|
||||
|
||||
<aop:aspect ref="logAspect">
|
||||
<aop:before method="beforeAdvice" pointcut-ref="logPointcut"/>
|
||||
<aop:after-returning method="afterReturningAdvice" pointcut-ref="logPointcut"/>
|
||||
<aop:after-throwing method="afterThrowingAdvice" pointcut-ref="logPointcut"/>
|
||||
<aop:after method="afterAdvice" pointcut-ref="logPointcut"/>
|
||||
<aop:around method="aroundAdvice" pointcut-ref="logPointcut"/>
|
||||
</aop:aspect>
|
||||
</aop:config>
|
||||
</beans>
|
||||
@ -0,0 +1,15 @@
|
||||
package com.ssm.aop.xml;
|
||||
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
|
||||
public class TestXML {
|
||||
public static void main(String[] args) {
|
||||
// 加载 Spring 配置文件
|
||||
ApplicationContext context = new ClassPathXmlApplicationContext("bean-aop-xml.xml");
|
||||
// 获取代理对象
|
||||
Product product = context.getBean("product", Product.class);
|
||||
// 执行目标方法
|
||||
product.printInfo();
|
||||
}
|
||||
}
|
||||
Loading…
Reference in new issue