From a3c22d6eb017e918ebdb51ab6da435a0bde022a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?DESKTOP-S70PEG5=5C=E8=8B=8F=E5=85=8B=E5=B1=B1?= Date: Tue, 6 Jul 2021 22:45:01 +0800 Subject: [PATCH 1/2] test --- README.txt | 1 + 1 file changed, 1 insertion(+) create mode 100644 README.txt diff --git a/README.txt b/README.txt new file mode 100644 index 0000000..743e320 --- /dev/null +++ b/README.txt @@ -0,0 +1 @@ +新的分支 \ No newline at end of file From e01357ff21a8bc1b847715b1f52890947f693014 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?DESKTOP-S70PEG5=5C=E8=8B=8F=E5=85=8B=E5=B1=B1?= Date: Wed, 7 Jul 2021 20:48:45 +0800 Subject: [PATCH 2/2] commit spring based on xml Configuration implement aop --- XMLAssembly/IUserDao.java | 6 ++++++ XMLAssembly/MyAspect.java | 38 ++++++++++++++++++++++++++++++++++++ XMLAssembly/Test.java | 22 +++++++++++++++++++++ XMLAssembly/UserDaoImpl.java | 26 ++++++++++++++++++++++++ XMLAssembly/aop.xml | 21 ++++++++++++++++++++ XMLAssembly/readme.txt | 17 ++++++++++++++++ 6 files changed, 130 insertions(+) create mode 100644 XMLAssembly/IUserDao.java create mode 100644 XMLAssembly/MyAspect.java create mode 100644 XMLAssembly/Test.java create mode 100644 XMLAssembly/UserDaoImpl.java create mode 100644 XMLAssembly/aop.xml create mode 100644 XMLAssembly/readme.txt diff --git a/XMLAssembly/IUserDao.java b/XMLAssembly/IUserDao.java new file mode 100644 index 0000000..51f6605 --- /dev/null +++ b/XMLAssembly/IUserDao.java @@ -0,0 +1,6 @@ +package com.spring.aop.XMLAssembly; + +public interface IUserDao { + public boolean addUser(String name); + public String deleteUser(int id); +} diff --git a/XMLAssembly/MyAspect.java b/XMLAssembly/MyAspect.java new file mode 100644 index 0000000..cb739a6 --- /dev/null +++ b/XMLAssembly/MyAspect.java @@ -0,0 +1,38 @@ +package com.spring.aop.XMLAssembly; + +import java.lang.reflect.Method; + +import org.aopalliance.intercept.MethodInterceptor; +import org.aopalliance.intercept.MethodInvocation; +import org.springframework.aop.AfterReturningAdvice; +import org.springframework.aop.MethodBeforeAdvice; + +public class MyAspect implements MethodInterceptor,MethodBeforeAdvice,AfterReturningAdvice{ + public void check(){ + System.out.println("ģȨ"); + } + public void log(){ + System.out.println("ģ־¼"); + } + @Override + //֪ͨ + public Object invoke(MethodInvocation mi) throws Throwable { + check(); + Object obj = mi.proceed(); + log(); + return obj; + } + @Override + //ǰ֪ͨ + public void before(Method arg0, Object[] arg1, Object arg2) + throws Throwable { + System.out.println("ִǰ"); + + } + @Override + //֪ͨ + public void afterReturning(Object arg0, Method arg1, Object[] arg2, + Object arg3) throws Throwable { + System.out.println("ִк"); + } +} diff --git a/XMLAssembly/Test.java b/XMLAssembly/Test.java new file mode 100644 index 0000000..b8ab483 --- /dev/null +++ b/XMLAssembly/Test.java @@ -0,0 +1,22 @@ +package com.spring.aop.XMLAssembly; + +import org.springframework.context.ApplicationContext; +import org.springframework.context.support.ClassPathXmlApplicationContext; + +public class Test { + + /** + * @param args + */ + public static void main(String[] args) { + System.getProperties().put("sun.misc.ProxyGenerator.saveGeneratedFiles", "true"); + String path = "com/spring/aop/XMLAssembly/aop.xml"; + ApplicationContext app = new ClassPathXmlApplicationContext(path); + IUserDao user = (IUserDao)app.getBean("proxyUserDao"); + Boolean add = user.addUser(""); + System.out.println(add); + String delete = user.deleteUser(5000); + System.out.println(delete); + } + +} diff --git a/XMLAssembly/UserDaoImpl.java b/XMLAssembly/UserDaoImpl.java new file mode 100644 index 0000000..1f0129f --- /dev/null +++ b/XMLAssembly/UserDaoImpl.java @@ -0,0 +1,26 @@ +package com.spring.aop.XMLAssembly; + +public class UserDaoImpl implements IUserDao { + + @Override + public boolean addUser(String name) { + System.out.println("û" + name); + return true; + } + + @Override + public String deleteUser(int id) { + String returnV = ""; + if((id != -1)&&(id != 0)){ + System.out.println("ɹɾid:"+id+"û"); + returnV="success"; + }else{ + returnV="failed"; + System.out.println("idֵϷ:"+ id); + } + return returnV; + } + protected void say(){System.out.println("say()");}; + + +} diff --git a/XMLAssembly/aop.xml b/XMLAssembly/aop.xml new file mode 100644 index 0000000..21b7206 --- /dev/null +++ b/XMLAssembly/aop.xml @@ -0,0 +1,21 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/XMLAssembly/readme.txt b/XMLAssembly/readme.txt new file mode 100644 index 0000000..22b8aa4 --- /dev/null +++ b/XMLAssembly/readme.txt @@ -0,0 +1,17 @@ + +***ڴProxyFactoryBeanʵAOP*** + + 1ProxyFactoryBeanFactoryBeanӿڵʵ + ͣ + 1)FactoryBeanʵBean + 2)ProxyFactoryBeanΪBeanʵ + ҪעIJ + 1)target:Ŀ,ֵһʵ + 2)proxyInterfaces:ҪʵֵĽӿ,ӿʹ .... ֵ + 3)proxyTargetClass:ֵΪboolean,ΪǷǽӿ,trueΪCGLIBfalse(Ĭ)ΪJDK̬ + 4)interceptorNames:Ҫ֪֯ͨbean + 5)singleton:شǷΪ,ĬΪtrue(صʵ) + 6)optimize:ֵΪboolean,trueǿʹCGLIBʽ + XMLò裺1)Ŀbean + 2)bean + 3)Ŀbeanʵ,class="org.springframework.aop.framework.ProxyFactoryBean",עӦԡ \ No newline at end of file