1.在com.ssm.aop.xml新建了Log.java和Message.java,新建了bean-aop-xml.xml文件,在libs里引入了包。2.为留言管理在TestXml里输出实体信息3.输出实体属性的基础上多输出前置通知。
parent
39b888593a
commit
edcc16e3cf
@ -0,0 +1,11 @@
|
||||
<component name="libraryTable">
|
||||
<library name="com.springsource.org.aopalliance-1.0.0">
|
||||
<CLASSES>
|
||||
<root url="jar://$PROJECT_DIR$/src/libs/com.springsource.org.aopalliance-1.0.0.jar!/" />
|
||||
<root url="jar://$PROJECT_DIR$/src/libs/com.springsource.org.aspectj.weaver-1.6.8.RELEASE.jar!/" />
|
||||
<root url="jar://$PROJECT_DIR$/src/libs/spring-aspects-5.1.6.RELEASE.jar!/" />
|
||||
</CLASSES>
|
||||
<JAVADOC />
|
||||
<SOURCES />
|
||||
</library>
|
||||
</component>
|
@ -0,0 +1,24 @@
|
||||
<?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"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
|
||||
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
|
||||
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd">
|
||||
|
||||
<bean id="message" class="com.ssm.aop.xml.Message">
|
||||
<property name="id" value="123456"></property>
|
||||
<property name="content" value="好看"></property>
|
||||
<property name="author" value="张三"></property>
|
||||
<property name="age" value="22"></property>
|
||||
</bean>
|
||||
|
||||
<bean id="log" class="com.ssm.aop.xml.Log"/>
|
||||
<aop:config>
|
||||
<aop:aspect id="log" ref="log">
|
||||
<aop:pointcut id="pointcut_log" expression="execution(public void com.ssm.aop.xml.Message.printInfo())"/>
|
||||
<aop:before method="before_log" pointcut-ref="pointcut_log"/>
|
||||
</aop:aspect>
|
||||
</aop:config>
|
||||
</beans>
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -0,0 +1,24 @@
|
||||
<?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"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
|
||||
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
|
||||
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd">
|
||||
|
||||
<bean id="message" class="com.ssm.aop.xml.Message">
|
||||
<property name="id" value="123456"></property>
|
||||
<property name="content" value="好看"></property>
|
||||
<property name="author" value="张三"></property>
|
||||
<property name="age" value="22"></property>
|
||||
</bean>
|
||||
|
||||
<bean id="log" class="com.ssm.aop.xml.Log"/>
|
||||
<aop:config>
|
||||
<aop:aspect id="log" ref="log">
|
||||
<aop:pointcut id="pointcut_log" expression="execution(public void com.ssm.aop.xml.Message.printInfo())"/>
|
||||
<aop:before method="before_log" pointcut-ref="pointcut_log"/>
|
||||
</aop:aspect>
|
||||
</aop:config>
|
||||
</beans>
|
@ -0,0 +1,10 @@
|
||||
package com.ssm.aop.xml;
|
||||
|
||||
import org.aspectj.lang.JoinPoint;
|
||||
import org.aspectj.lang.ProceedingJoinPoint;
|
||||
public class Log {
|
||||
public void before_log(JoinPoint joinPoint) {
|
||||
System.out.println("前置通知:模拟日志的记录..." + "目标类是:" + joinPoint.getTarget() + ",被切入通知的目标方法为:" +
|
||||
joinPoint.getSignature().getName());
|
||||
}
|
||||
}
|
@ -1,9 +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) {
|
||||
|
||||
ApplicationContext applicationContext = new ClassPathXmlApplicationContext("bean-aop-xml.xml");
|
||||
Message message = (Message)applicationContext.getBean("message");
|
||||
message.printInfo();
|
||||
}
|
||||
}
|
||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
Reference in new issue