{
+ /*
+ * 返回获取的bean
+ * */
+ public Person getObject() throws Exception {
+ Person person = new Person();
+ person.setId(3);
+ person.setName("王五");
+ return person;
+ }
+
+ //获取返回bean的类型
+ public Class> getObjectType() {
+ return Person.class;
+ }
+
+ //判断当前bean是否是单例的
+ public boolean isSingleton() {
+ return true;
+ }
+}
diff --git "a/javaframework/spring/03springIOC\345\256\271\345\231\250\347\232\204\351\205\215\347\275\256\344\275\277\347\224\2502/spring_study2/src/main/java/com/mashibing/factory/PersonInstanceFactory.java" "b/javaframework/spring/03springIOC\345\256\271\345\231\250\347\232\204\351\205\215\347\275\256\344\275\277\347\224\2502/spring_study2/src/main/java/com/mashibing/factory/PersonInstanceFactory.java"
new file mode 100644
index 00000000..054fa19c
--- /dev/null
+++ "b/javaframework/spring/03springIOC\345\256\271\345\231\250\347\232\204\351\205\215\347\275\256\344\275\277\347\224\2502/spring_study2/src/main/java/com/mashibing/factory/PersonInstanceFactory.java"
@@ -0,0 +1,17 @@
+package com.mashibing.factory;
+
+import com.mashibing.bean.Person;
+
+/**
+ * 实例工厂
+ */
+public class PersonInstanceFactory {
+
+ public Person getInstance(String name){
+ Person person = new Person();
+ person.setId(2);
+ person.setName(name);
+ person.setAge(22);
+ return person;
+ }
+}
diff --git "a/javaframework/spring/03springIOC\345\256\271\345\231\250\347\232\204\351\205\215\347\275\256\344\275\277\347\224\2502/spring_study2/src/main/java/com/mashibing/factory/PersonStaticFactory.java" "b/javaframework/spring/03springIOC\345\256\271\345\231\250\347\232\204\351\205\215\347\275\256\344\275\277\347\224\2502/spring_study2/src/main/java/com/mashibing/factory/PersonStaticFactory.java"
new file mode 100644
index 00000000..f890bb07
--- /dev/null
+++ "b/javaframework/spring/03springIOC\345\256\271\345\231\250\347\232\204\351\205\215\347\275\256\344\275\277\347\224\2502/spring_study2/src/main/java/com/mashibing/factory/PersonStaticFactory.java"
@@ -0,0 +1,17 @@
+package com.mashibing.factory;
+
+import com.mashibing.bean.Person;
+
+/**
+ * 静态工厂类
+ */
+public class PersonStaticFactory {
+
+ public static Person getInstance(String name){
+ Person person = new Person();
+ person.setId(1);
+ person.setName(name);
+ person.setAge(11);
+ return person;
+ }
+}
diff --git "a/javaframework/spring/03springIOC\345\256\271\345\231\250\347\232\204\351\205\215\347\275\256\344\275\277\347\224\2502/spring_study2/src/main/resources/db.properties" "b/javaframework/spring/03springIOC\345\256\271\345\231\250\347\232\204\351\205\215\347\275\256\344\275\277\347\224\2502/spring_study2/src/main/resources/db.properties"
new file mode 100644
index 00000000..26316991
--- /dev/null
+++ "b/javaframework/spring/03springIOC\345\256\271\345\231\250\347\232\204\351\205\215\347\275\256\344\275\277\347\224\2502/spring_study2/src/main/resources/db.properties"
@@ -0,0 +1,4 @@
+jdbc.username=root123
+jdbc.password=123456
+url=jdbc:mysql://localhost:3306/demo
+driverClassName=com.mysql.jdbc.Driver
\ No newline at end of file
diff --git "a/javaframework/spring/03springIOC\345\256\271\345\231\250\347\232\204\351\205\215\347\275\256\344\275\277\347\224\2502/spring_study2/src/main/resources/ioc.xml" "b/javaframework/spring/03springIOC\345\256\271\345\231\250\347\232\204\351\205\215\347\275\256\344\275\277\347\224\2502/spring_study2/src/main/resources/ioc.xml"
new file mode 100644
index 00000000..3dbcba65
--- /dev/null
+++ "b/javaframework/spring/03springIOC\345\256\271\345\231\250\347\232\204\351\205\215\347\275\256\344\275\277\347\224\2502/spring_study2/src/main/resources/ioc.xml"
@@ -0,0 +1,278 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git "a/javaframework/spring/03springIOC\345\256\271\345\231\250\347\232\204\351\205\215\347\275\256\344\275\277\347\224\2502/spring_study2/src/test/java/MyTest.java" "b/javaframework/spring/03springIOC\345\256\271\345\231\250\347\232\204\351\205\215\347\275\256\344\275\277\347\224\2502/spring_study2/src/test/java/MyTest.java"
new file mode 100644
index 00000000..1205c46b
--- /dev/null
+++ "b/javaframework/spring/03springIOC\345\256\271\345\231\250\347\232\204\351\205\215\347\275\256\344\275\277\347\224\2502/spring_study2/src/test/java/MyTest.java"
@@ -0,0 +1,71 @@
+import com.alibaba.druid.pool.DruidDataSource;
+import com.mashibing.bean.Address;
+import com.mashibing.bean.Person;
+import org.springframework.context.ApplicationContext;
+import org.springframework.context.support.ClassPathXmlApplicationContext;
+
+import java.sql.SQLException;
+
+public class MyTest {
+ public static void main(String[] args) throws SQLException {
+ ApplicationContext context = new ClassPathXmlApplicationContext("ioc.xml");
+ /*根据bean标签的id来获取对象*/
+// Person person = context.getBean("person", Person.class);
+// Person person2 = context.getBean("person",Person.class);
+// System.out.println(person == person2);
+
+ /*根据bean的类型来获取对象
+ * 注意:当通过类型进行获取的时候,如果存在两个相同类型对象,将无法完成获取工作
+ * */
+// Person bean = context.getBean(Person.class);
+// System.out.println(bean);
+
+ /**
+ * 当需要从容器中获取对象的时候,最好要保留无参构造方法,因为底层的实现是反射
+ *
+ * Class clazz = Person.class;
+ * Object obj = clazz.newInstance();默认调用无参的构造方法,此方法已经被弃用
+ * Object obj = class.getDeclaredConstructor().newInstance()
+ *
+ */
+
+// Person person2 = context.getBean("person", Person.class);
+// System.out.println(person2);
+//
+// Person person5 = context.getBean("person5", Person.class);
+// System.out.println(person5);
+
+// Person person6 = context.getBean("person6", Person.class);
+// System.out.println(person6);
+// Address address2 = context.getBean("address2", Address.class);
+// System.out.println(address2);
+
+// Person son = context.getBean("son", Person.class);
+// System.out.println(son);
+// Person parent = context.getBean("parent", Person.class);
+// System.out.println(parent);
+
+// Person person2 = context.getBean("person2", Person.class);
+// Person person3 = context.getBean("person2",Person.class);
+// System.out.println(person2 == person3);
+
+// Person person = context.getBean("person", Person.class);
+// System.out.println(person);
+// Person person2 = context.getBean("person2", Person.class);
+// System.out.println(person2);
+
+// Person myFactoryBean = context.getBean("myFactoryBean", Person.class);
+// System.out.println(myFactoryBean);
+
+// Person person = context.getBean("person", Person.class);
+// System.out.println(person);
+// ((ClassPathXmlApplicationContext)context).close();
+
+// DruidDataSource dataSource = context.getBean("dataSource2", DruidDataSource.class);
+// System.out.println(dataSource);
+// System.out.println(dataSource.getConnection());
+
+ Person person = context.getBean("person2", Person.class);
+ System.out.println(person);
+ }
+}
diff --git "a/javaframework/spring/03springIOC\345\256\271\345\231\250\347\232\204\351\205\215\347\275\256\344\275\277\347\224\2502/spring_study2/target/classes/com/mashibing/bean/Address.class" "b/javaframework/spring/03springIOC\345\256\271\345\231\250\347\232\204\351\205\215\347\275\256\344\275\277\347\224\2502/spring_study2/target/classes/com/mashibing/bean/Address.class"
new file mode 100644
index 00000000..4b37d3f6
Binary files /dev/null and "b/javaframework/spring/03springIOC\345\256\271\345\231\250\347\232\204\351\205\215\347\275\256\344\275\277\347\224\2502/spring_study2/target/classes/com/mashibing/bean/Address.class" differ
diff --git "a/javaframework/spring/03springIOC\345\256\271\345\231\250\347\232\204\351\205\215\347\275\256\344\275\277\347\224\2502/spring_study2/target/classes/com/mashibing/bean/MyBeanPostProcessor.class" "b/javaframework/spring/03springIOC\345\256\271\345\231\250\347\232\204\351\205\215\347\275\256\344\275\277\347\224\2502/spring_study2/target/classes/com/mashibing/bean/MyBeanPostProcessor.class"
new file mode 100644
index 00000000..28888b59
Binary files /dev/null and "b/javaframework/spring/03springIOC\345\256\271\345\231\250\347\232\204\351\205\215\347\275\256\344\275\277\347\224\2502/spring_study2/target/classes/com/mashibing/bean/MyBeanPostProcessor.class" differ
diff --git "a/javaframework/spring/03springIOC\345\256\271\345\231\250\347\232\204\351\205\215\347\275\256\344\275\277\347\224\2502/spring_study2/target/classes/com/mashibing/bean/Person.class" "b/javaframework/spring/03springIOC\345\256\271\345\231\250\347\232\204\351\205\215\347\275\256\344\275\277\347\224\2502/spring_study2/target/classes/com/mashibing/bean/Person.class"
new file mode 100644
index 00000000..a5e7b8f9
Binary files /dev/null and "b/javaframework/spring/03springIOC\345\256\271\345\231\250\347\232\204\351\205\215\347\275\256\344\275\277\347\224\2502/spring_study2/target/classes/com/mashibing/bean/Person.class" differ
diff --git "a/javaframework/spring/03springIOC\345\256\271\345\231\250\347\232\204\351\205\215\347\275\256\344\275\277\347\224\2502/spring_study2/target/classes/com/mashibing/factory/MyFactoryBean.class" "b/javaframework/spring/03springIOC\345\256\271\345\231\250\347\232\204\351\205\215\347\275\256\344\275\277\347\224\2502/spring_study2/target/classes/com/mashibing/factory/MyFactoryBean.class"
new file mode 100644
index 00000000..276a5adf
Binary files /dev/null and "b/javaframework/spring/03springIOC\345\256\271\345\231\250\347\232\204\351\205\215\347\275\256\344\275\277\347\224\2502/spring_study2/target/classes/com/mashibing/factory/MyFactoryBean.class" differ
diff --git "a/javaframework/spring/03springIOC\345\256\271\345\231\250\347\232\204\351\205\215\347\275\256\344\275\277\347\224\2502/spring_study2/target/classes/com/mashibing/factory/PersonInstanceFactory.class" "b/javaframework/spring/03springIOC\345\256\271\345\231\250\347\232\204\351\205\215\347\275\256\344\275\277\347\224\2502/spring_study2/target/classes/com/mashibing/factory/PersonInstanceFactory.class"
new file mode 100644
index 00000000..e170a6b2
Binary files /dev/null and "b/javaframework/spring/03springIOC\345\256\271\345\231\250\347\232\204\351\205\215\347\275\256\344\275\277\347\224\2502/spring_study2/target/classes/com/mashibing/factory/PersonInstanceFactory.class" differ
diff --git "a/javaframework/spring/03springIOC\345\256\271\345\231\250\347\232\204\351\205\215\347\275\256\344\275\277\347\224\2502/spring_study2/target/classes/com/mashibing/factory/PersonStaticFactory.class" "b/javaframework/spring/03springIOC\345\256\271\345\231\250\347\232\204\351\205\215\347\275\256\344\275\277\347\224\2502/spring_study2/target/classes/com/mashibing/factory/PersonStaticFactory.class"
new file mode 100644
index 00000000..f969801c
Binary files /dev/null and "b/javaframework/spring/03springIOC\345\256\271\345\231\250\347\232\204\351\205\215\347\275\256\344\275\277\347\224\2502/spring_study2/target/classes/com/mashibing/factory/PersonStaticFactory.class" differ
diff --git "a/javaframework/spring/03springIOC\345\256\271\345\231\250\347\232\204\351\205\215\347\275\256\344\275\277\347\224\2502/spring_study2/target/classes/db.properties" "b/javaframework/spring/03springIOC\345\256\271\345\231\250\347\232\204\351\205\215\347\275\256\344\275\277\347\224\2502/spring_study2/target/classes/db.properties"
new file mode 100644
index 00000000..26316991
--- /dev/null
+++ "b/javaframework/spring/03springIOC\345\256\271\345\231\250\347\232\204\351\205\215\347\275\256\344\275\277\347\224\2502/spring_study2/target/classes/db.properties"
@@ -0,0 +1,4 @@
+jdbc.username=root123
+jdbc.password=123456
+url=jdbc:mysql://localhost:3306/demo
+driverClassName=com.mysql.jdbc.Driver
\ No newline at end of file
diff --git "a/javaframework/spring/03springIOC\345\256\271\345\231\250\347\232\204\351\205\215\347\275\256\344\275\277\347\224\2502/spring_study2/target/classes/ioc.xml" "b/javaframework/spring/03springIOC\345\256\271\345\231\250\347\232\204\351\205\215\347\275\256\344\275\277\347\224\2502/spring_study2/target/classes/ioc.xml"
new file mode 100644
index 00000000..1d347d2e
--- /dev/null
+++ "b/javaframework/spring/03springIOC\345\256\271\345\231\250\347\232\204\351\205\215\347\275\256\344\275\277\347\224\2502/spring_study2/target/classes/ioc.xml"
@@ -0,0 +1,279 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git "a/javaframework/spring/03springIOC\345\256\271\345\231\250\347\232\204\351\205\215\347\275\256\344\275\277\347\224\2502/spring_study2/target/test-classes/MyTest.class" "b/javaframework/spring/03springIOC\345\256\271\345\231\250\347\232\204\351\205\215\347\275\256\344\275\277\347\224\2502/spring_study2/target/test-classes/MyTest.class"
new file mode 100644
index 00000000..402f6ee6
Binary files /dev/null and "b/javaframework/spring/03springIOC\345\256\271\345\231\250\347\232\204\351\205\215\347\275\256\344\275\277\347\224\2502/spring_study2/target/test-classes/MyTest.class" differ
diff --git "a/javaframework/spring/04SpringIOC\347\232\204\346\263\250\350\247\243\344\275\277\347\224\250/code/spring_annotation_study/.idea/compiler.xml" "b/javaframework/spring/04SpringIOC\347\232\204\346\263\250\350\247\243\344\275\277\347\224\250/code/spring_annotation_study/.idea/compiler.xml"
new file mode 100644
index 00000000..5dcc9026
--- /dev/null
+++ "b/javaframework/spring/04SpringIOC\347\232\204\346\263\250\350\247\243\344\275\277\347\224\250/code/spring_annotation_study/.idea/compiler.xml"
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git "a/javaframework/spring/04SpringIOC\347\232\204\346\263\250\350\247\243\344\275\277\347\224\250/code/spring_annotation_study/.idea/misc.xml" "b/javaframework/spring/04SpringIOC\347\232\204\346\263\250\350\247\243\344\275\277\347\224\250/code/spring_annotation_study/.idea/misc.xml"
new file mode 100644
index 00000000..4b661a5f
--- /dev/null
+++ "b/javaframework/spring/04SpringIOC\347\232\204\346\263\250\350\247\243\344\275\277\347\224\250/code/spring_annotation_study/.idea/misc.xml"
@@ -0,0 +1,14 @@
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git "a/javaframework/spring/04SpringIOC\347\232\204\346\263\250\350\247\243\344\275\277\347\224\250/code/spring_annotation_study/.idea/workspace.xml" "b/javaframework/spring/04SpringIOC\347\232\204\346\263\250\350\247\243\344\275\277\347\224\250/code/spring_annotation_study/.idea/workspace.xml"
new file mode 100644
index 00000000..269e66b6
--- /dev/null
+++ "b/javaframework/spring/04SpringIOC\347\232\204\346\263\250\350\247\243\344\275\277\347\224\250/code/spring_annotation_study/.idea/workspace.xml"
@@ -0,0 +1,787 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 1581750433085
+
+
+ 1581750433085
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ c3p0-0.9.5.4
+
+
+
+
+
+
+
+
+
+
+
+ 1.7
+
+
+
+
+
+
+
+
+
+
+
+ spring_annotation_study
+
+
+
+
+
+
+
+
+
+
+
+ 1.8
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git "a/javaframework/spring/04SpringIOC\347\232\204\346\263\250\350\247\243\344\275\277\347\224\250/code/spring_annotation_study/pom.xml" "b/javaframework/spring/04SpringIOC\347\232\204\346\263\250\350\247\243\344\275\277\347\224\250/code/spring_annotation_study/pom.xml"
new file mode 100644
index 00000000..9eda135b
--- /dev/null
+++ "b/javaframework/spring/04SpringIOC\347\232\204\346\263\250\350\247\243\344\275\277\347\224\250/code/spring_annotation_study/pom.xml"
@@ -0,0 +1,28 @@
+
+
+ 4.0.0
+
+ com.mashibing
+ spring_annotation_study
+ 1.0-SNAPSHOT
+
+
+
+
+
+ org.springframework
+ spring-context
+ 5.2.3.RELEASE
+
+
+
+ junit
+ junit
+ 4.12
+ test
+
+
+
+
\ No newline at end of file
diff --git "a/javaframework/spring/04SpringIOC\347\232\204\346\263\250\350\247\243\344\275\277\347\224\250/code/spring_annotation_study/spring_annotation_study.iml" "b/javaframework/spring/04SpringIOC\347\232\204\346\263\250\350\247\243\344\275\277\347\224\250/code/spring_annotation_study/spring_annotation_study.iml"
new file mode 100644
index 00000000..78b2cc53
--- /dev/null
+++ "b/javaframework/spring/04SpringIOC\347\232\204\346\263\250\350\247\243\344\275\277\347\224\250/code/spring_annotation_study/spring_annotation_study.iml"
@@ -0,0 +1,2 @@
+
+
\ No newline at end of file
diff --git "a/javaframework/spring/04SpringIOC\347\232\204\346\263\250\350\247\243\344\275\277\347\224\250/code/spring_annotation_study/src/main/java/com/mashibing/bean/Student.java" "b/javaframework/spring/04SpringIOC\347\232\204\346\263\250\350\247\243\344\275\277\347\224\250/code/spring_annotation_study/src/main/java/com/mashibing/bean/Student.java"
new file mode 100644
index 00000000..cb445cbb
--- /dev/null
+++ "b/javaframework/spring/04SpringIOC\347\232\204\346\263\250\350\247\243\344\275\277\347\224\250/code/spring_annotation_study/src/main/java/com/mashibing/bean/Student.java"
@@ -0,0 +1,4 @@
+package com.mashibing.bean;
+
+public class Student {
+}
diff --git "a/javaframework/spring/04SpringIOC\347\232\204\346\263\250\350\247\243\344\275\277\347\224\250/code/spring_annotation_study/src/main/java/com/mashibing/bean/Teacher.java" "b/javaframework/spring/04SpringIOC\347\232\204\346\263\250\350\247\243\344\275\277\347\224\250/code/spring_annotation_study/src/main/java/com/mashibing/bean/Teacher.java"
new file mode 100644
index 00000000..8fbc5dd1
--- /dev/null
+++ "b/javaframework/spring/04SpringIOC\347\232\204\346\263\250\350\247\243\344\275\277\347\224\250/code/spring_annotation_study/src/main/java/com/mashibing/bean/Teacher.java"
@@ -0,0 +1,4 @@
+package com.mashibing.bean;
+
+public class Teacher {
+}
diff --git "a/javaframework/spring/04SpringIOC\347\232\204\346\263\250\350\247\243\344\275\277\347\224\250/code/spring_annotation_study/src/main/java/com/mashibing/controller/PersonController.java" "b/javaframework/spring/04SpringIOC\347\232\204\346\263\250\350\247\243\344\275\277\347\224\250/code/spring_annotation_study/src/main/java/com/mashibing/controller/PersonController.java"
new file mode 100644
index 00000000..1829de26
--- /dev/null
+++ "b/javaframework/spring/04SpringIOC\347\232\204\346\263\250\350\247\243\344\275\277\347\224\250/code/spring_annotation_study/src/main/java/com/mashibing/controller/PersonController.java"
@@ -0,0 +1,48 @@
+package com.mashibing.controller;
+
+import com.mashibing.dao.PersonDao;
+import com.mashibing.service.PersonService;
+import com.mashibing.service.PersonService2;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Qualifier;
+import org.springframework.stereotype.Controller;
+
+import javax.annotation.Resource;
+
+@Controller
+//@Scope(value = "prototype")
+public class PersonController {
+
+ /**
+ * 通过@AutoWired注解能够完成自动注入的功能
+ * 是按照什么方式进行自动注入的呢?
+ * 默认情况下是按照ByType来进行装配的,如果找到直接赋值,找不到报错
+ * 如果有多个类型一样的bean对象,此时会按照id来进行查找,默认的id是类名首字符小写
+ * 如果找到了直接注入,如果找不到那么就报错
+ *
+ * 如果你想通过名字进行查找,可以自己规定名称,使用注解@Qualifier
+ *
+ * 当@AutoWired添加到方法上的时候,此方法在创建对象的时候会默认调用,同时方法中的参数会进行自动装配
+ *
+ * @Qualifier注解也可以定义在方法的参数列表中,可以指定当前属性的id名称 使用@Resource可以完成跟@AutoWired相同的功能,但是要注意他们之间的区别
+ * 1、@Resource是jdk提供的功能,@AutoWired是spring提供的功能
+ * 2、@Resource可以在其他框架中使用,而@AutoWired只能在spring中使用
+ * 换句话说:@Resource扩展性好,而@AutoWired支持的框架比较单一
+ * 3、@Resource是按照名称进行装配的,如果名字找不到,那么就使用类型
+ * 而@AutoWired是按照类型进行装配,如果类型找不到那么久使用名字进行查找
+ */
+ @Resource
+// @Autowired
+// @Qualifier("personService")
+ private PersonService personService;
+
+ public void save() {
+ personService.save();
+ }
+
+// @Autowired
+// public void test(@Qualifier("personDao") PersonDao personDao123) {
+// System.out.println("test");
+// personDao123.update();
+// }
+}
diff --git "a/javaframework/spring/04SpringIOC\347\232\204\346\263\250\350\247\243\344\275\277\347\224\250/code/spring_annotation_study/src/main/java/com/mashibing/dao/BaseDao.java" "b/javaframework/spring/04SpringIOC\347\232\204\346\263\250\350\247\243\344\275\277\347\224\250/code/spring_annotation_study/src/main/java/com/mashibing/dao/BaseDao.java"
new file mode 100644
index 00000000..3d114d93
--- /dev/null
+++ "b/javaframework/spring/04SpringIOC\347\232\204\346\263\250\350\247\243\344\275\277\347\224\250/code/spring_annotation_study/src/main/java/com/mashibing/dao/BaseDao.java"
@@ -0,0 +1,6 @@
+package com.mashibing.dao;
+
+public abstract class BaseDao {
+
+ public abstract void save();
+}
diff --git "a/javaframework/spring/04SpringIOC\347\232\204\346\263\250\350\247\243\344\275\277\347\224\250/code/spring_annotation_study/src/main/java/com/mashibing/dao/PersonDao.java" "b/javaframework/spring/04SpringIOC\347\232\204\346\263\250\350\247\243\344\275\277\347\224\250/code/spring_annotation_study/src/main/java/com/mashibing/dao/PersonDao.java"
new file mode 100644
index 00000000..492a1268
--- /dev/null
+++ "b/javaframework/spring/04SpringIOC\347\232\204\346\263\250\350\247\243\344\275\277\347\224\250/code/spring_annotation_study/src/main/java/com/mashibing/dao/PersonDao.java"
@@ -0,0 +1,15 @@
+package com.mashibing.dao;
+
+import org.springframework.stereotype.Repository;
+
+@Repository
+public class PersonDao {
+
+ public void save(){
+ System.out.println("保存成功");
+ }
+
+ public void update(){
+ System.out.println("更新成功");
+ }
+}
diff --git "a/javaframework/spring/04SpringIOC\347\232\204\346\263\250\350\247\243\344\275\277\347\224\250/code/spring_annotation_study/src/main/java/com/mashibing/dao/StudentDao.java" "b/javaframework/spring/04SpringIOC\347\232\204\346\263\250\350\247\243\344\275\277\347\224\250/code/spring_annotation_study/src/main/java/com/mashibing/dao/StudentDao.java"
new file mode 100644
index 00000000..7f95797a
--- /dev/null
+++ "b/javaframework/spring/04SpringIOC\347\232\204\346\263\250\350\247\243\344\275\277\347\224\250/code/spring_annotation_study/src/main/java/com/mashibing/dao/StudentDao.java"
@@ -0,0 +1,11 @@
+package com.mashibing.dao;
+
+import com.mashibing.bean.Student;
+import org.springframework.stereotype.Repository;
+
+@Repository
+public class StudentDao extends BaseDao {
+ public void save() {
+ System.out.println("保存学生");
+ }
+}
diff --git "a/javaframework/spring/04SpringIOC\347\232\204\346\263\250\350\247\243\344\275\277\347\224\250/code/spring_annotation_study/src/main/java/com/mashibing/dao/TeacherDao.java" "b/javaframework/spring/04SpringIOC\347\232\204\346\263\250\350\247\243\344\275\277\347\224\250/code/spring_annotation_study/src/main/java/com/mashibing/dao/TeacherDao.java"
new file mode 100644
index 00000000..9e4c65bc
--- /dev/null
+++ "b/javaframework/spring/04SpringIOC\347\232\204\346\263\250\350\247\243\344\275\277\347\224\250/code/spring_annotation_study/src/main/java/com/mashibing/dao/TeacherDao.java"
@@ -0,0 +1,11 @@
+package com.mashibing.dao;
+
+import com.mashibing.bean.Teacher;
+import org.springframework.stereotype.Repository;
+
+@Repository
+public class TeacherDao extends BaseDao{
+ public void save() {
+ System.out.println("保存老师");
+ }
+}
diff --git "a/javaframework/spring/04SpringIOC\347\232\204\346\263\250\350\247\243\344\275\277\347\224\250/code/spring_annotation_study/src/main/java/com/mashibing/service/BaseService.java" "b/javaframework/spring/04SpringIOC\347\232\204\346\263\250\350\247\243\344\275\277\347\224\250/code/spring_annotation_study/src/main/java/com/mashibing/service/BaseService.java"
new file mode 100644
index 00000000..bd989ede
--- /dev/null
+++ "b/javaframework/spring/04SpringIOC\347\232\204\346\263\250\350\247\243\344\275\277\347\224\250/code/spring_annotation_study/src/main/java/com/mashibing/service/BaseService.java"
@@ -0,0 +1,15 @@
+package com.mashibing.service;
+
+import com.mashibing.dao.BaseDao;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+public class BaseService {
+
+ @Autowired
+ private BaseDao baseDao;
+
+ public void save(){
+ baseDao.save();
+ }
+}
diff --git "a/javaframework/spring/04SpringIOC\347\232\204\346\263\250\350\247\243\344\275\277\347\224\250/code/spring_annotation_study/src/main/java/com/mashibing/service/PersonService.java" "b/javaframework/spring/04SpringIOC\347\232\204\346\263\250\350\247\243\344\275\277\347\224\250/code/spring_annotation_study/src/main/java/com/mashibing/service/PersonService.java"
new file mode 100644
index 00000000..80b58632
--- /dev/null
+++ "b/javaframework/spring/04SpringIOC\347\232\204\346\263\250\350\247\243\344\275\277\347\224\250/code/spring_annotation_study/src/main/java/com/mashibing/service/PersonService.java"
@@ -0,0 +1,17 @@
+package com.mashibing.service;
+
+import com.mashibing.dao.PersonDao;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+@Service
+public class PersonService {
+
+ @Autowired
+ private PersonDao personDao;
+
+ public void save(){
+ System.out.println("personservice");
+ personDao.save();
+ }
+}
diff --git "a/javaframework/spring/04SpringIOC\347\232\204\346\263\250\350\247\243\344\275\277\347\224\250/code/spring_annotation_study/src/main/java/com/mashibing/service/PersonService2.java" "b/javaframework/spring/04SpringIOC\347\232\204\346\263\250\350\247\243\344\275\277\347\224\250/code/spring_annotation_study/src/main/java/com/mashibing/service/PersonService2.java"
new file mode 100644
index 00000000..6290a00a
--- /dev/null
+++ "b/javaframework/spring/04SpringIOC\347\232\204\346\263\250\350\247\243\344\275\277\347\224\250/code/spring_annotation_study/src/main/java/com/mashibing/service/PersonService2.java"
@@ -0,0 +1,18 @@
+package com.mashibing.service;
+
+import com.mashibing.dao.PersonDao;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+@Service
+public class PersonService2 extends PersonService{
+
+ @Autowired
+ private PersonDao personDao;
+
+ public void save(){
+ System.out.println("personservice2...........");
+ personDao.save();
+ }
+
+}
diff --git "a/javaframework/spring/04SpringIOC\347\232\204\346\263\250\350\247\243\344\275\277\347\224\250/code/spring_annotation_study/src/main/java/com/mashibing/service/StudentService.java" "b/javaframework/spring/04SpringIOC\347\232\204\346\263\250\350\247\243\344\275\277\347\224\250/code/spring_annotation_study/src/main/java/com/mashibing/service/StudentService.java"
new file mode 100644
index 00000000..d5944d50
--- /dev/null
+++ "b/javaframework/spring/04SpringIOC\347\232\204\346\263\250\350\247\243\344\275\277\347\224\250/code/spring_annotation_study/src/main/java/com/mashibing/service/StudentService.java"
@@ -0,0 +1,12 @@
+package com.mashibing.service;
+
+import com.mashibing.bean.Student;
+import com.mashibing.dao.StudentDao;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+@Service
+public class StudentService extends BaseService{
+
+
+}
diff --git "a/javaframework/spring/04SpringIOC\347\232\204\346\263\250\350\247\243\344\275\277\347\224\250/code/spring_annotation_study/src/main/java/com/mashibing/service/TeacherService.java" "b/javaframework/spring/04SpringIOC\347\232\204\346\263\250\350\247\243\344\275\277\347\224\250/code/spring_annotation_study/src/main/java/com/mashibing/service/TeacherService.java"
new file mode 100644
index 00000000..dd9cffa8
--- /dev/null
+++ "b/javaframework/spring/04SpringIOC\347\232\204\346\263\250\350\247\243\344\275\277\347\224\250/code/spring_annotation_study/src/main/java/com/mashibing/service/TeacherService.java"
@@ -0,0 +1,12 @@
+package com.mashibing.service;
+
+import com.mashibing.bean.Student;
+import com.mashibing.bean.Teacher;
+import com.mashibing.dao.TeacherDao;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+@Service
+public class TeacherService extends BaseService {
+
+}
diff --git "a/javaframework/spring/04SpringIOC\347\232\204\346\263\250\350\247\243\344\275\277\347\224\250/code/spring_annotation_study/src/main/resources/applicationContext.xml" "b/javaframework/spring/04SpringIOC\347\232\204\346\263\250\350\247\243\344\275\277\347\224\250/code/spring_annotation_study/src/main/resources/applicationContext.xml"
new file mode 100644
index 00000000..be65dec2
--- /dev/null
+++ "b/javaframework/spring/04SpringIOC\347\232\204\346\263\250\350\247\243\344\275\277\347\224\250/code/spring_annotation_study/src/main/resources/applicationContext.xml"
@@ -0,0 +1,51 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git "a/javaframework/spring/04SpringIOC\347\232\204\346\263\250\350\247\243\344\275\277\347\224\250/code/spring_annotation_study/src/test/java/MyTest.java" "b/javaframework/spring/04SpringIOC\347\232\204\346\263\250\350\247\243\344\275\277\347\224\250/code/spring_annotation_study/src/test/java/MyTest.java"
new file mode 100644
index 00000000..a00dbb75
--- /dev/null
+++ "b/javaframework/spring/04SpringIOC\347\232\204\346\263\250\350\247\243\344\275\277\347\224\250/code/spring_annotation_study/src/test/java/MyTest.java"
@@ -0,0 +1,32 @@
+import com.mashibing.controller.PersonController;
+import com.mashibing.service.PersonService;
+import com.mashibing.service.StudentService;
+import com.mashibing.service.TeacherService;
+import org.junit.Test;
+import org.springframework.context.support.ClassPathXmlApplicationContext;
+
+/**
+ * 注意,给测试类起名字的时候千万不要定义成Test
+ * 测试的方法不可以有参数,不可以有返回值
+ */
+public class MyTest {
+
+ ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
+
+ @Test
+ public void test01() {
+ PersonController personController = context.getBean("personController", PersonController.class);
+ personController.save();
+
+ }
+
+ @Test
+ public void test02() {
+
+ StudentService studentService = context.getBean("studentService", StudentService.class);
+ studentService.save();
+
+ TeacherService teacherService = context.getBean("teacherService",TeacherService.class);
+ teacherService.save();
+ }
+}
diff --git "a/javaframework/spring/04SpringIOC\347\232\204\346\263\250\350\247\243\344\275\277\347\224\250/code/spring_annotation_study/target/classes/META-INF/spring_annotation_study.kotlin_module" "b/javaframework/spring/04SpringIOC\347\232\204\346\263\250\350\247\243\344\275\277\347\224\250/code/spring_annotation_study/target/classes/META-INF/spring_annotation_study.kotlin_module"
new file mode 100644
index 00000000..8fb60192
Binary files /dev/null and "b/javaframework/spring/04SpringIOC\347\232\204\346\263\250\350\247\243\344\275\277\347\224\250/code/spring_annotation_study/target/classes/META-INF/spring_annotation_study.kotlin_module" differ
diff --git "a/javaframework/spring/04SpringIOC\347\232\204\346\263\250\350\247\243\344\275\277\347\224\250/code/spring_annotation_study/target/classes/applicationContext.xml" "b/javaframework/spring/04SpringIOC\347\232\204\346\263\250\350\247\243\344\275\277\347\224\250/code/spring_annotation_study/target/classes/applicationContext.xml"
new file mode 100644
index 00000000..be65dec2
--- /dev/null
+++ "b/javaframework/spring/04SpringIOC\347\232\204\346\263\250\350\247\243\344\275\277\347\224\250/code/spring_annotation_study/target/classes/applicationContext.xml"
@@ -0,0 +1,51 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git "a/javaframework/spring/04SpringIOC\347\232\204\346\263\250\350\247\243\344\275\277\347\224\250/code/spring_annotation_study/target/classes/com/mashibing/bean/Student.class" "b/javaframework/spring/04SpringIOC\347\232\204\346\263\250\350\247\243\344\275\277\347\224\250/code/spring_annotation_study/target/classes/com/mashibing/bean/Student.class"
new file mode 100644
index 00000000..cfa4911d
Binary files /dev/null and "b/javaframework/spring/04SpringIOC\347\232\204\346\263\250\350\247\243\344\275\277\347\224\250/code/spring_annotation_study/target/classes/com/mashibing/bean/Student.class" differ
diff --git "a/javaframework/spring/04SpringIOC\347\232\204\346\263\250\350\247\243\344\275\277\347\224\250/code/spring_annotation_study/target/classes/com/mashibing/bean/Teacher.class" "b/javaframework/spring/04SpringIOC\347\232\204\346\263\250\350\247\243\344\275\277\347\224\250/code/spring_annotation_study/target/classes/com/mashibing/bean/Teacher.class"
new file mode 100644
index 00000000..991d0760
Binary files /dev/null and "b/javaframework/spring/04SpringIOC\347\232\204\346\263\250\350\247\243\344\275\277\347\224\250/code/spring_annotation_study/target/classes/com/mashibing/bean/Teacher.class" differ
diff --git "a/javaframework/spring/04SpringIOC\347\232\204\346\263\250\350\247\243\344\275\277\347\224\250/code/spring_annotation_study/target/classes/com/mashibing/controller/PersonController.class" "b/javaframework/spring/04SpringIOC\347\232\204\346\263\250\350\247\243\344\275\277\347\224\250/code/spring_annotation_study/target/classes/com/mashibing/controller/PersonController.class"
new file mode 100644
index 00000000..82818aed
Binary files /dev/null and "b/javaframework/spring/04SpringIOC\347\232\204\346\263\250\350\247\243\344\275\277\347\224\250/code/spring_annotation_study/target/classes/com/mashibing/controller/PersonController.class" differ
diff --git "a/javaframework/spring/04SpringIOC\347\232\204\346\263\250\350\247\243\344\275\277\347\224\250/code/spring_annotation_study/target/classes/com/mashibing/dao/BaseDao.class" "b/javaframework/spring/04SpringIOC\347\232\204\346\263\250\350\247\243\344\275\277\347\224\250/code/spring_annotation_study/target/classes/com/mashibing/dao/BaseDao.class"
new file mode 100644
index 00000000..0734c708
Binary files /dev/null and "b/javaframework/spring/04SpringIOC\347\232\204\346\263\250\350\247\243\344\275\277\347\224\250/code/spring_annotation_study/target/classes/com/mashibing/dao/BaseDao.class" differ
diff --git "a/javaframework/spring/04SpringIOC\347\232\204\346\263\250\350\247\243\344\275\277\347\224\250/code/spring_annotation_study/target/classes/com/mashibing/dao/PersonDao.class" "b/javaframework/spring/04SpringIOC\347\232\204\346\263\250\350\247\243\344\275\277\347\224\250/code/spring_annotation_study/target/classes/com/mashibing/dao/PersonDao.class"
new file mode 100644
index 00000000..75b15bf6
Binary files /dev/null and "b/javaframework/spring/04SpringIOC\347\232\204\346\263\250\350\247\243\344\275\277\347\224\250/code/spring_annotation_study/target/classes/com/mashibing/dao/PersonDao.class" differ
diff --git "a/javaframework/spring/04SpringIOC\347\232\204\346\263\250\350\247\243\344\275\277\347\224\250/code/spring_annotation_study/target/classes/com/mashibing/dao/StudentDao.class" "b/javaframework/spring/04SpringIOC\347\232\204\346\263\250\350\247\243\344\275\277\347\224\250/code/spring_annotation_study/target/classes/com/mashibing/dao/StudentDao.class"
new file mode 100644
index 00000000..99c28fe2
Binary files /dev/null and "b/javaframework/spring/04SpringIOC\347\232\204\346\263\250\350\247\243\344\275\277\347\224\250/code/spring_annotation_study/target/classes/com/mashibing/dao/StudentDao.class" differ
diff --git "a/javaframework/spring/04SpringIOC\347\232\204\346\263\250\350\247\243\344\275\277\347\224\250/code/spring_annotation_study/target/classes/com/mashibing/dao/TeacherDao.class" "b/javaframework/spring/04SpringIOC\347\232\204\346\263\250\350\247\243\344\275\277\347\224\250/code/spring_annotation_study/target/classes/com/mashibing/dao/TeacherDao.class"
new file mode 100644
index 00000000..131a9616
Binary files /dev/null and "b/javaframework/spring/04SpringIOC\347\232\204\346\263\250\350\247\243\344\275\277\347\224\250/code/spring_annotation_study/target/classes/com/mashibing/dao/TeacherDao.class" differ
diff --git "a/javaframework/spring/04SpringIOC\347\232\204\346\263\250\350\247\243\344\275\277\347\224\250/code/spring_annotation_study/target/classes/com/mashibing/service/BaseService.class" "b/javaframework/spring/04SpringIOC\347\232\204\346\263\250\350\247\243\344\275\277\347\224\250/code/spring_annotation_study/target/classes/com/mashibing/service/BaseService.class"
new file mode 100644
index 00000000..1dca5511
Binary files /dev/null and "b/javaframework/spring/04SpringIOC\347\232\204\346\263\250\350\247\243\344\275\277\347\224\250/code/spring_annotation_study/target/classes/com/mashibing/service/BaseService.class" differ
diff --git "a/javaframework/spring/04SpringIOC\347\232\204\346\263\250\350\247\243\344\275\277\347\224\250/code/spring_annotation_study/target/classes/com/mashibing/service/PersonService.class" "b/javaframework/spring/04SpringIOC\347\232\204\346\263\250\350\247\243\344\275\277\347\224\250/code/spring_annotation_study/target/classes/com/mashibing/service/PersonService.class"
new file mode 100644
index 00000000..3d81b565
Binary files /dev/null and "b/javaframework/spring/04SpringIOC\347\232\204\346\263\250\350\247\243\344\275\277\347\224\250/code/spring_annotation_study/target/classes/com/mashibing/service/PersonService.class" differ
diff --git "a/javaframework/spring/04SpringIOC\347\232\204\346\263\250\350\247\243\344\275\277\347\224\250/code/spring_annotation_study/target/classes/com/mashibing/service/PersonService2.class" "b/javaframework/spring/04SpringIOC\347\232\204\346\263\250\350\247\243\344\275\277\347\224\250/code/spring_annotation_study/target/classes/com/mashibing/service/PersonService2.class"
new file mode 100644
index 00000000..3232880e
Binary files /dev/null and "b/javaframework/spring/04SpringIOC\347\232\204\346\263\250\350\247\243\344\275\277\347\224\250/code/spring_annotation_study/target/classes/com/mashibing/service/PersonService2.class" differ
diff --git "a/javaframework/spring/04SpringIOC\347\232\204\346\263\250\350\247\243\344\275\277\347\224\250/code/spring_annotation_study/target/classes/com/mashibing/service/StudentService.class" "b/javaframework/spring/04SpringIOC\347\232\204\346\263\250\350\247\243\344\275\277\347\224\250/code/spring_annotation_study/target/classes/com/mashibing/service/StudentService.class"
new file mode 100644
index 00000000..643466b0
Binary files /dev/null and "b/javaframework/spring/04SpringIOC\347\232\204\346\263\250\350\247\243\344\275\277\347\224\250/code/spring_annotation_study/target/classes/com/mashibing/service/StudentService.class" differ
diff --git "a/javaframework/spring/04SpringIOC\347\232\204\346\263\250\350\247\243\344\275\277\347\224\250/code/spring_annotation_study/target/classes/com/mashibing/service/TeacherService.class" "b/javaframework/spring/04SpringIOC\347\232\204\346\263\250\350\247\243\344\275\277\347\224\250/code/spring_annotation_study/target/classes/com/mashibing/service/TeacherService.class"
new file mode 100644
index 00000000..3a4c55ff
Binary files /dev/null and "b/javaframework/spring/04SpringIOC\347\232\204\346\263\250\350\247\243\344\275\277\347\224\250/code/spring_annotation_study/target/classes/com/mashibing/service/TeacherService.class" differ
diff --git "a/javaframework/spring/04SpringIOC\347\232\204\346\263\250\350\247\243\344\275\277\347\224\250/code/spring_annotation_study/target/test-classes/MyTest.class" "b/javaframework/spring/04SpringIOC\347\232\204\346\263\250\350\247\243\344\275\277\347\224\250/code/spring_annotation_study/target/test-classes/MyTest.class"
new file mode 100644
index 00000000..6bbd042d
Binary files /dev/null and "b/javaframework/spring/04SpringIOC\347\232\204\346\263\250\350\247\243\344\275\277\347\224\250/code/spring_annotation_study/target/test-classes/MyTest.class" differ
diff --git "a/javaframework/spring/04SpringIOC\347\232\204\346\263\250\350\247\243\344\275\277\347\224\250/note/03SpringIOC\347\232\204\346\263\250\350\247\243\345\272\224\347\224\250.md" "b/javaframework/spring/04SpringIOC\347\232\204\346\263\250\350\247\243\344\275\277\347\224\250/note/03SpringIOC\347\232\204\346\263\250\350\247\243\345\272\224\347\224\250.md"
new file mode 100644
index 00000000..65994ef5
--- /dev/null
+++ "b/javaframework/spring/04SpringIOC\347\232\204\346\263\250\350\247\243\344\275\277\347\224\250/note/03SpringIOC\347\232\204\346\263\250\350\247\243\345\272\224\347\224\250.md"
@@ -0,0 +1,583 @@
+# 03SpringIOC的注解应用
+
+ 在之前的项目中,我们都是通过xml文件进行bean或者某些属性的赋值,其实还有另外一种注解的方式,在企业开发中使用的很多,在bean上添加注解,可以快速的将bean注册到ioc容器。
+
+### 1、使用注解的方式注册bean到IOC容器中
+
+applicationContext.xml
+
+```xml
+
+
+
+
+
+
+
+```
+
+PersonController.java
+
+```java
+package com.mashibing.controller;
+
+import org.springframework.stereotype.Controller;
+
+@Controller
+public class PersonController {
+ public PersonController() {
+ System.out.println("创建对象");
+ }
+}
+```
+
+PersonService.java
+
+```java
+package com.mashibing.service;
+
+import org.springframework.stereotype.Service;
+
+@Service
+public class PersonService {
+}
+```
+
+PersonDao.java
+
+```java
+package com.mashibing.dao;
+
+import org.springframework.stereotype.Repository;
+
+@Repository("personDao")
+@Scope(value="prototype")
+public class PersonDao {
+}
+```
+
+### 2、定义扫描包时要包含的类和不要包含的类
+
+ 当定义好基础的扫描包后,在某些情况下可能要有选择性的配置是否要注册bean到IOC容器中,此时可以通过如下的方式进行配置。
+
+applicationContext.xml
+
+```xml
+
+
+
+
+
+
+
+
+
+
+```
+
+### 3、使用@AutoWired进行自动注入
+
+ 使用注解的方式实现自动注入需要使用@AutoWired注解。
+
+PersonController.java
+
+```java
+package com.mashibing.controller;
+
+import com.mashibing.service.PersonService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Controller;
+
+@Controller
+public class PersonController {
+
+ @Autowired
+ private PersonService personService;
+
+ public PersonController() {
+ System.out.println("创建对象");
+ }
+
+ public void getPerson(){
+ personService.getPerson();
+ }
+}
+```
+
+PersonService.java
+
+```java
+package com.mashibing.service;
+
+import com.mashibing.dao.PersonDao;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+@Service
+public class PersonService {
+
+ @Autowired
+ private PersonDao personDao;
+
+ public void getPerson(){
+ personDao.getPerson();
+ }
+}
+```
+
+PersonDao.java
+
+```java
+package com.mashibing.dao;
+
+ import org.springframework.stereotype.Repository;
+
+@Repository
+public class PersonDao {
+
+ public void getPerson(){
+ System.out.println("PersonDao:getPerson");
+ }
+}
+```
+
+注意:当使用AutoWired注解的时候,自动装配的时候是根据类型实现的。
+
+ 1、如果只找到一个,则直接进行赋值,
+
+ 2、如果没有找到,则直接抛出异常,
+
+ 3、如果找到多个,那么会按照变量名作为id继续匹配,
+
+ 1、匹配上直接进行装配
+
+ 2、如果匹配不上则直接报异常
+
+PersonServiceExt.java
+
+```java
+package com.mashibing.service;
+
+import com.mashibing.dao.PersonDao;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+@Service
+public class PersonServiceExt extends PersonService{
+
+ @Autowired
+ private PersonDao personDao;
+
+ public void getPerson(){
+ System.out.println("PersonServiceExt......");
+ personDao.getPerson();
+ }
+}
+```
+
+PersonController.java
+
+```java
+package com.mashibing.controller;
+
+import com.mashibing.service.PersonService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Controller;
+
+@Controller
+public class PersonController {
+
+ @Autowired
+ private PersonService personServiceExt;
+
+ public PersonController() {
+ System.out.println("创建对象");
+ }
+
+ public void getPerson(){
+ personServiceExt.getPerson();
+ }
+}
+```
+
+ 还可以使用@Qualifier注解来指定id的名称,让spring不要使用变量名,当使用@Qualifier注解的时候也会有两种情况:
+
+ 1、找到,则直接装配
+
+ 2、找不到,就会报错
+
+PersonController.java
+
+```java
+package com.mashibing.controller;
+
+import com.mashibing.service.PersonService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Qualifier;
+import org.springframework.stereotype.Controller;
+
+@Controller
+public class PersonController {
+
+ @Autowired
+ @Qualifier("personService")
+ private PersonService personServiceExt2;
+
+ public PersonController() {
+ System.out.println("创建对象");
+ }
+
+ public void getPerson(){
+ personServiceExt2.getPerson();
+ }
+}
+```
+
+ 通过上述的代码我们能够发现,使用@AutoWired肯定是能够装配上的,如果装配不上就会报错。
+
+### 4、@AutoWired可以进行定义在方法上
+
+ 当我们查看@AutoWired注解的源码的时候发现,此注解不仅可以使用在成员变量上,也可以使用在方法上。
+
+PersonController.java
+
+```java
+package com.mashibing.controller;
+
+import com.mashibing.dao.PersonDao;
+import com.mashibing.service.PersonService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Qualifier;
+import org.springframework.stereotype.Controller;
+
+@Controller
+public class PersonController {
+
+ @Qualifier("personService")
+ @Autowired
+ private PersonService personServiceExt2;
+
+ public PersonController() {
+ System.out.println("创建对象");
+ }
+
+ public void getPerson(){
+ System.out.println("personController..."+personServiceExt2);
+// personServiceExt2.getPerson();
+ }
+
+ /**
+ * 当方法上有@AutoWired注解时:
+ * 1、此方法在bean创建的时候会自动调用
+ * 2、这个方法的每一个参数都会自动注入值
+ * @param personDao
+ */
+ @Autowired
+ public void test(PersonDao personDao){
+ System.out.println("此方法被调用:"+personDao);
+ }
+
+ /**
+ * @Qualifier注解也可以作用在属性上,用来被当作id去匹配容器中的对象,如果没有
+ * 此注解,那么直接按照类型进行匹配
+ * @param personService
+ */
+ @Autowired
+ public void test2(@Qualifier("personServiceExt") PersonService personService){
+ System.out.println("此方法被调用:"+personService);
+ }
+}
+```
+
+### 5、自动装配的注解@AutoWired,@Resource
+
+ 在使用自动装配的时候,出了可以使用@AutoWired注解之外,还可以使用@Resource注解,大家需要知道这两个注解的区别。
+
+ 1、@AutoWired:是spring中提供的注解,@Resource:是jdk中定义的注解,依靠的是java的标准
+
+ 2、@AutoWired默认是按照类型进行装配,默认情况下要求依赖的对象必须存在,@Resource默认是按照名字进行匹配的,同时可以指定name属性。
+
+ 3、@AutoWired只适合spring框架,而@Resource扩展性更好
+
+PersonController.java
+
+```java
+package com.mashibing.controller;
+
+import com.mashibing.dao.PersonDao;
+import com.mashibing.service.PersonService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Qualifier;
+import org.springframework.stereotype.Controller;
+
+import javax.annotation.Resource;
+
+@Controller
+public class PersonController {
+
+ @Qualifier("personService")
+ @Resource
+ private PersonService personServiceExt2;
+
+ public PersonController() {
+ System.out.println("创建对象");
+ }
+
+ public void getPerson(){
+ System.out.println("personController..."+personServiceExt2);
+ personServiceExt2.getPerson();
+ }
+
+ /**
+ * 当方法上有@AutoWired注解时:
+ * 1、此方法在bean创建的时候会自动调用
+ * 2、这个方法的每一个参数都会自动注入值
+ * @param personDao
+ */
+ @Autowired
+ public void test(PersonDao personDao){
+ System.out.println("此方法被调用:"+personDao);
+ }
+
+ /**
+ * @Qualifier注解也可以作用在属性上,用来被当作id去匹配容器中的对象,如果没有
+ * 此注解,那么直接按照类型进行匹配
+ * @param personService
+ */
+ @Autowired
+ public void test2(@Qualifier("personServiceExt") PersonService personService){
+ System.out.println("此方法被调用:"+personService);
+ }
+}
+```
+
+### 6、泛型依赖注入
+
+ 为了讲解泛型依赖注入,首先我们需要先写一个基本的案例,按照我们之前学习的知识:
+
+Student.java
+
+```java
+package com.mashibing.bean;
+
+public class Student {
+}
+```
+
+Teacher.java
+
+```java
+package com.mashibing.bean;
+
+public class Teacher {
+}
+```
+
+BaseDao.java
+
+```java
+package com.mashibing.dao;
+
+import org.springframework.stereotype.Repository;
+
+@Repository
+public abstract class BaseDao {
+
+ public abstract void save();
+}
+```
+
+StudentDao.java
+
+```java
+package com.mashibing.dao;
+
+import com.mashibing.bean.Student;
+import org.springframework.stereotype.Repository;
+
+@Repository
+public class StudentDao extends BaseDao{
+ public void save() {
+ System.out.println("保存学生");
+ }
+}
+```
+
+TeacherDao.java
+
+```java
+package com.mashibing.dao;
+
+import com.mashibing.bean.Teacher;
+import org.springframework.stereotype.Repository;
+
+@Repository
+public class TeacherDao extends BaseDao {
+ public void save() {
+ System.out.println("保存老师");
+ }
+}
+```
+
+StudentService.java
+
+```java
+package com.mashibing.service;
+
+import com.mashibing.dao.StudentDao;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+@Service
+public class StudentService {
+
+ @Autowired
+ private StudentDao studentDao;
+
+ public void save(){
+ studentDao.save();
+ }
+}
+```
+
+TeacherService.java
+
+```java
+package com.mashibing.service;
+
+import com.mashibing.dao.TeacherDao;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+@Service
+public class TeacherService {
+ @Autowired
+ private TeacherDao teacherDao;
+
+ public void save(){
+ teacherDao.save();
+ }
+}
+```
+
+MyTest.java
+
+```java
+import com.mashibing.service.StudentService;
+import com.mashibing.service.TeacherService;
+import org.springframework.context.ApplicationContext;
+import org.springframework.context.support.ClassPathXmlApplicationContext;
+
+import javax.sql.DataSource;
+import java.sql.SQLException;
+
+public class MyTest {
+ public static void main(String[] args) throws SQLException {
+ ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
+ StudentService studentService = context.getBean("studentService",StudentService.class);
+ studentService.save();
+
+ TeacherService teacherService = context.getBean("teacherService",TeacherService.class);
+ teacherService.save();
+ }
+}
+```
+
+ 上述代码是我们之前的可以完成的功能,但是可以思考,Service层的代码是否能够改写:
+
+BaseService.java
+
+```java
+package com.mashibing.service;
+
+import com.mashibing.dao.BaseDao;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+public class BaseService {
+
+ @Autowired
+ BaseDao baseDao;
+
+ public void save(){
+ System.out.println("自动注入的对象:"+baseDao);
+ baseDao.save();
+ }
+}
+```
+
+StudentService.java
+
+```java
+package com.mashibing.service;
+
+import com.mashibing.bean.Student;
+import com.mashibing.dao.StudentDao;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+@Service
+public class StudentService extends BaseService {
+
+}
+```
+
+TeacherService.java
+
+```java
+package com.mashibing.service;
+
+import com.mashibing.bean.Teacher;
+import com.mashibing.dao.TeacherDao;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+@Service
+public class TeacherService extends BaseService{
+
+}
+```
+
diff --git "a/javaframework/spring/05SpringAOP\347\232\204\345\274\225\345\205\245\345\217\212\351\205\215\347\275\256\344\275\277\347\224\250/code/spring_aop_study/.idea/compiler.xml" "b/javaframework/spring/05SpringAOP\347\232\204\345\274\225\345\205\245\345\217\212\351\205\215\347\275\256\344\275\277\347\224\250/code/spring_aop_study/.idea/compiler.xml"
new file mode 100644
index 00000000..958a9165
--- /dev/null
+++ "b/javaframework/spring/05SpringAOP\347\232\204\345\274\225\345\205\245\345\217\212\351\205\215\347\275\256\344\275\277\347\224\250/code/spring_aop_study/.idea/compiler.xml"
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git "a/javaframework/spring/05SpringAOP\347\232\204\345\274\225\345\205\245\345\217\212\351\205\215\347\275\256\344\275\277\347\224\250/code/spring_aop_study/.idea/misc.xml" "b/javaframework/spring/05SpringAOP\347\232\204\345\274\225\345\205\245\345\217\212\351\205\215\347\275\256\344\275\277\347\224\250/code/spring_aop_study/.idea/misc.xml"
new file mode 100644
index 00000000..4b661a5f
--- /dev/null
+++ "b/javaframework/spring/05SpringAOP\347\232\204\345\274\225\345\205\245\345\217\212\351\205\215\347\275\256\344\275\277\347\224\250/code/spring_aop_study/.idea/misc.xml"
@@ -0,0 +1,14 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git "a/javaframework/spring/05SpringAOP\347\232\204\345\274\225\345\205\245\345\217\212\351\205\215\347\275\256\344\275\277\347\224\250/code/spring_aop_study/.idea/uiDesigner.xml" "b/javaframework/spring/05SpringAOP\347\232\204\345\274\225\345\205\245\345\217\212\351\205\215\347\275\256\344\275\277\347\224\250/code/spring_aop_study/.idea/uiDesigner.xml"
new file mode 100644
index 00000000..e96534fb
--- /dev/null
+++ "b/javaframework/spring/05SpringAOP\347\232\204\345\274\225\345\205\245\345\217\212\351\205\215\347\275\256\344\275\277\347\224\250/code/spring_aop_study/.idea/uiDesigner.xml"
@@ -0,0 +1,124 @@
+
+
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+
+
+
+ -
+
+
+
+
+
+ -
+
+
+
+
+
+ -
+
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+
+
+ -
+
+
+ -
+
+
+
+
+
\ No newline at end of file
diff --git "a/javaframework/spring/05SpringAOP\347\232\204\345\274\225\345\205\245\345\217\212\351\205\215\347\275\256\344\275\277\347\224\250/code/spring_aop_study/.idea/workspace.xml" "b/javaframework/spring/05SpringAOP\347\232\204\345\274\225\345\205\245\345\217\212\351\205\215\347\275\256\344\275\277\347\224\250/code/spring_aop_study/.idea/workspace.xml"
new file mode 100644
index 00000000..91ab649e
--- /dev/null
+++ "b/javaframework/spring/05SpringAOP\347\232\204\345\274\225\345\205\245\345\217\212\351\205\215\347\275\256\344\275\277\347\224\250/code/spring_aop_study/.idea/workspace.xml"
@@ -0,0 +1,712 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ int
+
+
+ Integer
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 1581768338458
+
+
+ 1581768338458
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ c3p0-0.9.5.4
+
+
+
+
+
+
+
+
+
+
+
+ 1.7
+
+
+
+
+
+
+
+
+
+
+
+ spring_aop_study
+
+
+
+
+
+
+
+
+
+
+
+
+ 1.8
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git "a/javaframework/spring/05SpringAOP\347\232\204\345\274\225\345\205\245\345\217\212\351\205\215\347\275\256\344\275\277\347\224\250/code/spring_aop_study/pom.xml" "b/javaframework/spring/05SpringAOP\347\232\204\345\274\225\345\205\245\345\217\212\351\205\215\347\275\256\344\275\277\347\224\250/code/spring_aop_study/pom.xml"
new file mode 100644
index 00000000..d9b23714
--- /dev/null
+++ "b/javaframework/spring/05SpringAOP\347\232\204\345\274\225\345\205\245\345\217\212\351\205\215\347\275\256\344\275\277\347\224\250/code/spring_aop_study/pom.xml"
@@ -0,0 +1,50 @@
+
+
+ 4.0.0
+
+ com.mashibing
+ spring_aop_study
+ 1.0-SNAPSHOT
+
+
+
+
+ junit
+ junit
+ 4.12
+ test
+
+
+
+ org.springframework
+ spring-context
+ 5.2.3.RELEASE
+
+
+
+ cglib
+ cglib
+ 3.3.0
+
+
+
+ org.aspectj
+ aspectjweaver
+ 1.9.5
+
+
+
+ aopalliance
+ aopalliance
+ 1.0
+
+
+
+ org.springframework
+ spring-aspects
+ 5.2.3.RELEASE
+
+
+
\ No newline at end of file
diff --git "a/javaframework/spring/05SpringAOP\347\232\204\345\274\225\345\205\245\345\217\212\351\205\215\347\275\256\344\275\277\347\224\250/code/spring_aop_study/spring_aop_study.iml" "b/javaframework/spring/05SpringAOP\347\232\204\345\274\225\345\205\245\345\217\212\351\205\215\347\275\256\344\275\277\347\224\250/code/spring_aop_study/spring_aop_study.iml"
new file mode 100644
index 00000000..78b2cc53
--- /dev/null
+++ "b/javaframework/spring/05SpringAOP\347\232\204\345\274\225\345\205\245\345\217\212\351\205\215\347\275\256\344\275\277\347\224\250/code/spring_aop_study/spring_aop_study.iml"
@@ -0,0 +1,2 @@
+
+
\ No newline at end of file
diff --git "a/javaframework/spring/05SpringAOP\347\232\204\345\274\225\345\205\245\345\217\212\351\205\215\347\275\256\344\275\277\347\224\250/code/spring_aop_study/src/main/java/com/mashibing/myinter/MyInterface.java" "b/javaframework/spring/05SpringAOP\347\232\204\345\274\225\345\205\245\345\217\212\351\205\215\347\275\256\344\275\277\347\224\250/code/spring_aop_study/src/main/java/com/mashibing/myinter/MyInterface.java"
new file mode 100644
index 00000000..f39d68d2
--- /dev/null
+++ "b/javaframework/spring/05SpringAOP\347\232\204\345\274\225\345\205\245\345\217\212\351\205\215\347\275\256\344\275\277\347\224\250/code/spring_aop_study/src/main/java/com/mashibing/myinter/MyInterface.java"
@@ -0,0 +1,6 @@
+package com.mashibing.myinter;
+
+public interface MyInterface {
+
+ public void show(Integer i);
+}
diff --git "a/javaframework/spring/05SpringAOP\347\232\204\345\274\225\345\205\245\345\217\212\351\205\215\347\275\256\344\275\277\347\224\250/code/spring_aop_study/src/main/java/com/mashibing/myinter/MySubClass.java" "b/javaframework/spring/05SpringAOP\347\232\204\345\274\225\345\205\245\345\217\212\351\205\215\347\275\256\344\275\277\347\224\250/code/spring_aop_study/src/main/java/com/mashibing/myinter/MySubClass.java"
new file mode 100644
index 00000000..9a327f40
--- /dev/null
+++ "b/javaframework/spring/05SpringAOP\347\232\204\345\274\225\345\205\245\345\217\212\351\205\215\347\275\256\344\275\277\347\224\250/code/spring_aop_study/src/main/java/com/mashibing/myinter/MySubClass.java"
@@ -0,0 +1,7 @@
+package com.mashibing.myinter;
+
+public class MySubClass implements MyInterface {
+ public void show(Integer i) {
+ System.out.println("show.......");
+ }
+}
diff --git "a/javaframework/spring/05SpringAOP\347\232\204\345\274\225\345\205\245\345\217\212\351\205\215\347\275\256\344\275\277\347\224\250/code/spring_aop_study/src/main/java/com/mashibing/proxy/CalculatorProxy.java" "b/javaframework/spring/05SpringAOP\347\232\204\345\274\225\345\205\245\345\217\212\351\205\215\347\275\256\344\275\277\347\224\250/code/spring_aop_study/src/main/java/com/mashibing/proxy/CalculatorProxy.java"
new file mode 100644
index 00000000..7bb85f95
--- /dev/null
+++ "b/javaframework/spring/05SpringAOP\347\232\204\345\274\225\345\205\245\345\217\212\351\205\215\347\275\256\344\275\277\347\224\250/code/spring_aop_study/src/main/java/com/mashibing/proxy/CalculatorProxy.java"
@@ -0,0 +1,52 @@
+package com.mashibing.proxy;
+
+import com.mashibing.service.Calculator;
+import com.mashibing.util.LogUtil;
+import sun.rmi.runtime.Log;
+
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.Method;
+import java.lang.reflect.Proxy;
+import java.util.Arrays;
+
+/**
+ * 必须要有接口,如果没有接口,不能使用,这种方式是用jdk提供的reflect包下的类
+ * 但是在生产环境中我不能保证每个类都有实现的接口,所有有第二种方式cglib
+ *
+ * cglib在实现的时候有没有接口都无所谓
+ *
+ * 在spring中使用了两种动态代理的方式,一种是jdk提供的(刚刚完成的)另外一种就是cglib
+ */
+public class CalculatorProxy {
+
+ public static Calculator getProxy( final Calculator calculator){
+
+ //获取被代理对象的类加载器
+ ClassLoader loader = calculator.getClass().getClassLoader();
+ //被代理对象的所有接口
+ Class>[] interfaces = calculator.getClass().getInterfaces();
+ //用来执行被代理类需要执行的方法
+ InvocationHandler handler = new InvocationHandler() {
+ public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
+ Object result = null;
+ try{
+// System.out.println(method.getName()+"方法开始执行,参数列表是:"+ Arrays.asList(args));
+// LogUtil.start(method,args);
+ //开始调用被代理类的方法
+ result = method.invoke(calculator,args);
+// System.out.println(method.getName()+"方法执行完成,结果是:"+result);
+// LogUtil.stop(method,result);
+ }catch (Exception e){
+// System.out.println(method.getName()+"方法抛出异常:"+e.getMessage());
+// LogUtil.logException(method,e);
+ }finally {
+// System.out.println(method.getName()+"方法执行结束。。。。。over");
+// LogUtil.logFinally(method);
+ }
+ return result;
+ }
+ };
+ Object o = Proxy.newProxyInstance(loader, interfaces, handler);
+ return (Calculator) o;
+ }
+}
diff --git "a/javaframework/spring/05SpringAOP\347\232\204\345\274\225\345\205\245\345\217\212\351\205\215\347\275\256\344\275\277\347\224\250/code/spring_aop_study/src/main/java/com/mashibing/proxy/DynamicProxy.java" "b/javaframework/spring/05SpringAOP\347\232\204\345\274\225\345\205\245\345\217\212\351\205\215\347\275\256\344\275\277\347\224\250/code/spring_aop_study/src/main/java/com/mashibing/proxy/DynamicProxy.java"
new file mode 100644
index 00000000..9c4ad1a5
--- /dev/null
+++ "b/javaframework/spring/05SpringAOP\347\232\204\345\274\225\345\205\245\345\217\212\351\205\215\347\275\256\344\275\277\347\224\250/code/spring_aop_study/src/main/java/com/mashibing/proxy/DynamicProxy.java"
@@ -0,0 +1,10 @@
+package com.mashibing.proxy;
+
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.Method;
+
+public class DynamicProxy implements InvocationHandler {
+ public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
+ return null;
+ }
+}
diff --git "a/javaframework/spring/05SpringAOP\347\232\204\345\274\225\345\205\245\345\217\212\351\205\215\347\275\256\344\275\277\347\224\250/code/spring_aop_study/src/main/java/com/mashibing/service/Calculator.java" "b/javaframework/spring/05SpringAOP\347\232\204\345\274\225\345\205\245\345\217\212\351\205\215\347\275\256\344\275\277\347\224\250/code/spring_aop_study/src/main/java/com/mashibing/service/Calculator.java"
new file mode 100644
index 00000000..2242eed4
--- /dev/null
+++ "b/javaframework/spring/05SpringAOP\347\232\204\345\274\225\345\205\245\345\217\212\351\205\215\347\275\256\344\275\277\347\224\250/code/spring_aop_study/src/main/java/com/mashibing/service/Calculator.java"
@@ -0,0 +1,12 @@
+package com.mashibing.service;
+
+import org.springframework.stereotype.Service;
+
+
+public interface Calculator {
+
+ public Integer add(Integer i,Integer j) throws NoSuchMethodException;
+ public Integer sub(Integer i,Integer j) throws NoSuchMethodException;
+ public Integer mul(Integer i,Integer j) throws NoSuchMethodException;
+ public Integer div(Integer i,Integer j) throws NoSuchMethodException;
+}
diff --git "a/javaframework/spring/05SpringAOP\347\232\204\345\274\225\345\205\245\345\217\212\351\205\215\347\275\256\344\275\277\347\224\250/code/spring_aop_study/src/main/java/com/mashibing/service/MyCalculator.java" "b/javaframework/spring/05SpringAOP\347\232\204\345\274\225\345\205\245\345\217\212\351\205\215\347\275\256\344\275\277\347\224\250/code/spring_aop_study/src/main/java/com/mashibing/service/MyCalculator.java"
new file mode 100644
index 00000000..de953f01
--- /dev/null
+++ "b/javaframework/spring/05SpringAOP\347\232\204\345\274\225\345\205\245\345\217\212\351\205\215\347\275\256\344\275\277\347\224\250/code/spring_aop_study/src/main/java/com/mashibing/service/MyCalculator.java"
@@ -0,0 +1,38 @@
+package com.mashibing.service;
+
+import org.springframework.stereotype.Service;
+
+@Service
+public class MyCalculator implements Calculator {
+ public Integer add(Integer i, Integer j) throws NoSuchMethodException {
+// Method add = MyCalculator.class.getMethod("add", Integer.class, Integer.class);
+// LogUtil.start(add,i,j);
+ Integer result = i+j;
+// LogUtil.stop(add,result);
+ return result;
+ }
+
+ public Integer sub(Integer i, Integer j) throws NoSuchMethodException {
+// Method sub = MyCalculator.class.getMethod("sub", Integer.class, Integer.class);
+// LogUtil.start(sub,i,j);
+ Integer result = i-j;
+// LogUtil.stop(sub,result);
+ return result;
+ }
+
+ public Integer mul(Integer i, Integer j) throws NoSuchMethodException {
+// Method mul = MyCalculator.class.getMethod("mul", Integer.class, Integer.class);
+// LogUtil.start(mul,i,j);
+ Integer result = i*j;
+// LogUtil.stop(mul,result);
+ return result;
+ }
+
+ public Integer div(Integer i, Integer j) throws NoSuchMethodException {
+// Method div = MyCalculator.class.getMethod("div", Integer.class, Integer.class);
+// LogUtil.start(div,i,j);
+ Integer result = i/j;
+// LogUtil.stop(div,result);
+ return result;
+ }
+}
diff --git "a/javaframework/spring/05SpringAOP\347\232\204\345\274\225\345\205\245\345\217\212\351\205\215\347\275\256\344\275\277\347\224\250/code/spring_aop_study/src/main/java/com/mashibing/service/SecondCalculator.java" "b/javaframework/spring/05SpringAOP\347\232\204\345\274\225\345\205\245\345\217\212\351\205\215\347\275\256\344\275\277\347\224\250/code/spring_aop_study/src/main/java/com/mashibing/service/SecondCalculator.java"
new file mode 100644
index 00000000..b0d3e7c8
--- /dev/null
+++ "b/javaframework/spring/05SpringAOP\347\232\204\345\274\225\345\205\245\345\217\212\351\205\215\347\275\256\344\275\277\347\224\250/code/spring_aop_study/src/main/java/com/mashibing/service/SecondCalculator.java"
@@ -0,0 +1,19 @@
+package com.mashibing.service;
+
+public class SecondCalculator implements Calculator {
+ public Integer add(Integer i, Integer j) throws NoSuchMethodException {
+ return null;
+ }
+
+ public Integer sub(Integer i, Integer j) throws NoSuchMethodException {
+ return null;
+ }
+
+ public Integer mul(Integer i, Integer j) throws NoSuchMethodException {
+ return null;
+ }
+
+ public Integer div(Integer i, Integer j) throws NoSuchMethodException {
+ return null;
+ }
+}
diff --git "a/javaframework/spring/05SpringAOP\347\232\204\345\274\225\345\205\245\345\217\212\351\205\215\347\275\256\344\275\277\347\224\250/code/spring_aop_study/src/main/java/com/mashibing/util/LogUtil.java" "b/javaframework/spring/05SpringAOP\347\232\204\345\274\225\345\205\245\345\217\212\351\205\215\347\275\256\344\275\277\347\224\250/code/spring_aop_study/src/main/java/com/mashibing/util/LogUtil.java"
new file mode 100644
index 00000000..d1bd6366
--- /dev/null
+++ "b/javaframework/spring/05SpringAOP\347\232\204\345\274\225\345\205\245\345\217\212\351\205\215\347\275\256\344\275\277\347\224\250/code/spring_aop_study/src/main/java/com/mashibing/util/LogUtil.java"
@@ -0,0 +1,44 @@
+package com.mashibing.util;
+
+import org.aspectj.lang.annotation.*;
+import org.springframework.stereotype.Component;
+
+import java.lang.reflect.Method;
+import java.util.Arrays;
+
+@Aspect
+@Component
+public class LogUtil {
+ /**
+ * 通知注解有以下几种类型:
+ *
+ * @Before:前置通知,在方法执行之前完成
+ * @After:后置通知,在方法执行完成之后执行
+ * @AfterReturing:返回通知:在返回结果之后运行
+ * @AfterThrowing:异常通知:出现异常的时候使用
+ * @Around:环绕通知
+ *
+ * 在方法的参数列表中不要随便添加参数值,会有异常信息
+ */
+
+ @Before("execution( public Integer com.mashibing.service.MyCalculator.add(Integer,Integer))")
+ public static void start(){
+ System.out.println("方法开始执行:参数是");
+ }
+
+ @AfterReturning("execution( public Integer com.mashibing.service.MyCalculator.add(Integer,Integer))")
+ public static void stop(){
+ System.out.println("方法执行结束,结果是:");
+ }
+
+ @AfterThrowing("execution( public Integer com.mashibing.service.MyCalculator.add(Integer,Integer))")
+ public static void logException(){
+ System.out.println("方法抛出异常:");
+ }
+
+ @After("execution( public Integer com.mashibing.service.MyCalculator.add(Integer,Integer))")
+ public static void logFinally(){
+ System.out.println("方法执行结束。。。。。over");
+
+ }
+}
diff --git "a/javaframework/spring/05SpringAOP\347\232\204\345\274\225\345\205\245\345\217\212\351\205\215\347\275\256\344\275\277\347\224\250/code/spring_aop_study/src/main/resources/applicationContext.xml" "b/javaframework/spring/05SpringAOP\347\232\204\345\274\225\345\205\245\345\217\212\351\205\215\347\275\256\344\275\277\347\224\250/code/spring_aop_study/src/main/resources/applicationContext.xml"
new file mode 100644
index 00000000..029eea1a
--- /dev/null
+++ "b/javaframework/spring/05SpringAOP\347\232\204\345\274\225\345\205\245\345\217\212\351\205\215\347\275\256\344\275\277\347\224\250/code/spring_aop_study/src/main/resources/applicationContext.xml"
@@ -0,0 +1,17 @@
+
+
+
+
+
+
+
\ No newline at end of file
diff --git "a/javaframework/spring/05SpringAOP\347\232\204\345\274\225\345\205\245\345\217\212\351\205\215\347\275\256\344\275\277\347\224\250/code/spring_aop_study/src/test/java/MyTest.java" "b/javaframework/spring/05SpringAOP\347\232\204\345\274\225\345\205\245\345\217\212\351\205\215\347\275\256\344\275\277\347\224\250/code/spring_aop_study/src/test/java/MyTest.java"
new file mode 100644
index 00000000..bc7497fa
--- /dev/null
+++ "b/javaframework/spring/05SpringAOP\347\232\204\345\274\225\345\205\245\345\217\212\351\205\215\347\275\256\344\275\277\347\224\250/code/spring_aop_study/src/test/java/MyTest.java"
@@ -0,0 +1,35 @@
+import com.mashibing.myinter.MyInterface;
+import com.mashibing.myinter.MySubClass;
+import com.mashibing.proxy.CalculatorProxy;
+import com.mashibing.service.Calculator;
+import com.mashibing.service.MyCalculator;
+import com.mashibing.service.SecondCalculator;
+import org.junit.Test;
+import org.springframework.context.support.ClassPathXmlApplicationContext;
+
+public class MyTest {
+
+ @Test
+ public void test01() throws NoSuchMethodException {
+
+// MyCalculator myCalculator = new MyCalculator();
+// System.out.println(myCalculator.add(1, 2));
+// System.out.println(myCalculator.div(1, 1));
+
+ Calculator calculator = (Calculator) CalculatorProxy.getProxy(new MyCalculator());
+ System.out.println(calculator.add(1, 1));
+ calculator.sub(1,1);
+ calculator.mul(1,1);
+ calculator.div(1,0);
+ System.out.println(calculator.getClass());
+// System.out.println("------------------");
+// MyInterface proxy = (MyInterface) CalculatorProxy.getProxy(new MySubClass());
+// proxy.show(100);
+ }
+ @Test
+ public void test02() throws NoSuchMethodException {
+ ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
+ Calculator calculator = context.getBean( Calculator.class);
+ calculator.add(1,1);
+ }
+}
diff --git "a/javaframework/spring/05SpringAOP\347\232\204\345\274\225\345\205\245\345\217\212\351\205\215\347\275\256\344\275\277\347\224\250/code/spring_aop_study/target/classes/applicationContext.xml" "b/javaframework/spring/05SpringAOP\347\232\204\345\274\225\345\205\245\345\217\212\351\205\215\347\275\256\344\275\277\347\224\250/code/spring_aop_study/target/classes/applicationContext.xml"
new file mode 100644
index 00000000..029eea1a
--- /dev/null
+++ "b/javaframework/spring/05SpringAOP\347\232\204\345\274\225\345\205\245\345\217\212\351\205\215\347\275\256\344\275\277\347\224\250/code/spring_aop_study/target/classes/applicationContext.xml"
@@ -0,0 +1,17 @@
+
+
+
+
+
+
+
\ No newline at end of file
diff --git "a/javaframework/spring/05SpringAOP\347\232\204\345\274\225\345\205\245\345\217\212\351\205\215\347\275\256\344\275\277\347\224\250/code/spring_aop_study/target/classes/com/mashibing/myinter/MyInterface.class" "b/javaframework/spring/05SpringAOP\347\232\204\345\274\225\345\205\245\345\217\212\351\205\215\347\275\256\344\275\277\347\224\250/code/spring_aop_study/target/classes/com/mashibing/myinter/MyInterface.class"
new file mode 100644
index 00000000..0dd65883
Binary files /dev/null and "b/javaframework/spring/05SpringAOP\347\232\204\345\274\225\345\205\245\345\217\212\351\205\215\347\275\256\344\275\277\347\224\250/code/spring_aop_study/target/classes/com/mashibing/myinter/MyInterface.class" differ
diff --git "a/javaframework/spring/05SpringAOP\347\232\204\345\274\225\345\205\245\345\217\212\351\205\215\347\275\256\344\275\277\347\224\250/code/spring_aop_study/target/classes/com/mashibing/myinter/MySubClass.class" "b/javaframework/spring/05SpringAOP\347\232\204\345\274\225\345\205\245\345\217\212\351\205\215\347\275\256\344\275\277\347\224\250/code/spring_aop_study/target/classes/com/mashibing/myinter/MySubClass.class"
new file mode 100644
index 00000000..856113b8
Binary files /dev/null and "b/javaframework/spring/05SpringAOP\347\232\204\345\274\225\345\205\245\345\217\212\351\205\215\347\275\256\344\275\277\347\224\250/code/spring_aop_study/target/classes/com/mashibing/myinter/MySubClass.class" differ
diff --git "a/javaframework/spring/05SpringAOP\347\232\204\345\274\225\345\205\245\345\217\212\351\205\215\347\275\256\344\275\277\347\224\250/code/spring_aop_study/target/classes/com/mashibing/proxy/CalculatorProxy$1.class" "b/javaframework/spring/05SpringAOP\347\232\204\345\274\225\345\205\245\345\217\212\351\205\215\347\275\256\344\275\277\347\224\250/code/spring_aop_study/target/classes/com/mashibing/proxy/CalculatorProxy$1.class"
new file mode 100644
index 00000000..4bad49bc
Binary files /dev/null and "b/javaframework/spring/05SpringAOP\347\232\204\345\274\225\345\205\245\345\217\212\351\205\215\347\275\256\344\275\277\347\224\250/code/spring_aop_study/target/classes/com/mashibing/proxy/CalculatorProxy$1.class" differ
diff --git "a/javaframework/spring/05SpringAOP\347\232\204\345\274\225\345\205\245\345\217\212\351\205\215\347\275\256\344\275\277\347\224\250/code/spring_aop_study/target/classes/com/mashibing/proxy/CalculatorProxy.class" "b/javaframework/spring/05SpringAOP\347\232\204\345\274\225\345\205\245\345\217\212\351\205\215\347\275\256\344\275\277\347\224\250/code/spring_aop_study/target/classes/com/mashibing/proxy/CalculatorProxy.class"
new file mode 100644
index 00000000..6c1761d4
Binary files /dev/null and "b/javaframework/spring/05SpringAOP\347\232\204\345\274\225\345\205\245\345\217\212\351\205\215\347\275\256\344\275\277\347\224\250/code/spring_aop_study/target/classes/com/mashibing/proxy/CalculatorProxy.class" differ
diff --git "a/javaframework/spring/05SpringAOP\347\232\204\345\274\225\345\205\245\345\217\212\351\205\215\347\275\256\344\275\277\347\224\250/code/spring_aop_study/target/classes/com/mashibing/proxy/DynamicProxy.class" "b/javaframework/spring/05SpringAOP\347\232\204\345\274\225\345\205\245\345\217\212\351\205\215\347\275\256\344\275\277\347\224\250/code/spring_aop_study/target/classes/com/mashibing/proxy/DynamicProxy.class"
new file mode 100644
index 00000000..876d036d
Binary files /dev/null and "b/javaframework/spring/05SpringAOP\347\232\204\345\274\225\345\205\245\345\217\212\351\205\215\347\275\256\344\275\277\347\224\250/code/spring_aop_study/target/classes/com/mashibing/proxy/DynamicProxy.class" differ
diff --git "a/javaframework/spring/05SpringAOP\347\232\204\345\274\225\345\205\245\345\217\212\351\205\215\347\275\256\344\275\277\347\224\250/code/spring_aop_study/target/classes/com/mashibing/service/Calculator.class" "b/javaframework/spring/05SpringAOP\347\232\204\345\274\225\345\205\245\345\217\212\351\205\215\347\275\256\344\275\277\347\224\250/code/spring_aop_study/target/classes/com/mashibing/service/Calculator.class"
new file mode 100644
index 00000000..59fe5455
Binary files /dev/null and "b/javaframework/spring/05SpringAOP\347\232\204\345\274\225\345\205\245\345\217\212\351\205\215\347\275\256\344\275\277\347\224\250/code/spring_aop_study/target/classes/com/mashibing/service/Calculator.class" differ
diff --git "a/javaframework/spring/05SpringAOP\347\232\204\345\274\225\345\205\245\345\217\212\351\205\215\347\275\256\344\275\277\347\224\250/code/spring_aop_study/target/classes/com/mashibing/service/MyCalculator.class" "b/javaframework/spring/05SpringAOP\347\232\204\345\274\225\345\205\245\345\217\212\351\205\215\347\275\256\344\275\277\347\224\250/code/spring_aop_study/target/classes/com/mashibing/service/MyCalculator.class"
new file mode 100644
index 00000000..598a34b2
Binary files /dev/null and "b/javaframework/spring/05SpringAOP\347\232\204\345\274\225\345\205\245\345\217\212\351\205\215\347\275\256\344\275\277\347\224\250/code/spring_aop_study/target/classes/com/mashibing/service/MyCalculator.class" differ
diff --git "a/javaframework/spring/05SpringAOP\347\232\204\345\274\225\345\205\245\345\217\212\351\205\215\347\275\256\344\275\277\347\224\250/code/spring_aop_study/target/classes/com/mashibing/service/SecondCalculator.class" "b/javaframework/spring/05SpringAOP\347\232\204\345\274\225\345\205\245\345\217\212\351\205\215\347\275\256\344\275\277\347\224\250/code/spring_aop_study/target/classes/com/mashibing/service/SecondCalculator.class"
new file mode 100644
index 00000000..1459abc9
Binary files /dev/null and "b/javaframework/spring/05SpringAOP\347\232\204\345\274\225\345\205\245\345\217\212\351\205\215\347\275\256\344\275\277\347\224\250/code/spring_aop_study/target/classes/com/mashibing/service/SecondCalculator.class" differ
diff --git "a/javaframework/spring/05SpringAOP\347\232\204\345\274\225\345\205\245\345\217\212\351\205\215\347\275\256\344\275\277\347\224\250/code/spring_aop_study/target/classes/com/mashibing/util/LogUtil.class" "b/javaframework/spring/05SpringAOP\347\232\204\345\274\225\345\205\245\345\217\212\351\205\215\347\275\256\344\275\277\347\224\250/code/spring_aop_study/target/classes/com/mashibing/util/LogUtil.class"
new file mode 100644
index 00000000..d552fdc2
Binary files /dev/null and "b/javaframework/spring/05SpringAOP\347\232\204\345\274\225\345\205\245\345\217\212\351\205\215\347\275\256\344\275\277\347\224\250/code/spring_aop_study/target/classes/com/mashibing/util/LogUtil.class" differ
diff --git "a/javaframework/spring/05SpringAOP\347\232\204\345\274\225\345\205\245\345\217\212\351\205\215\347\275\256\344\275\277\347\224\250/code/spring_aop_study/target/test-classes/MyTest.class" "b/javaframework/spring/05SpringAOP\347\232\204\345\274\225\345\205\245\345\217\212\351\205\215\347\275\256\344\275\277\347\224\250/code/spring_aop_study/target/test-classes/MyTest.class"
new file mode 100644
index 00000000..ba0a6cad
Binary files /dev/null and "b/javaframework/spring/05SpringAOP\347\232\204\345\274\225\345\205\245\345\217\212\351\205\215\347\275\256\344\275\277\347\224\250/code/spring_aop_study/target/test-classes/MyTest.class" differ
diff --git "a/javaframework/spring/05SpringAOP\347\232\204\345\274\225\345\205\245\345\217\212\351\205\215\347\275\256\344\275\277\347\224\250/note/04Spring AOP\344\273\213\347\273\215\344\270\216\344\275\277\347\224\250.md" "b/javaframework/spring/05SpringAOP\347\232\204\345\274\225\345\205\245\345\217\212\351\205\215\347\275\256\344\275\277\347\224\250/note/04Spring AOP\344\273\213\347\273\215\344\270\216\344\275\277\347\224\250.md"
new file mode 100644
index 00000000..e5298686
--- /dev/null
+++ "b/javaframework/spring/05SpringAOP\347\232\204\345\274\225\345\205\245\345\217\212\351\205\215\347\275\256\344\275\277\347\224\250/note/04Spring AOP\344\273\213\347\273\215\344\270\216\344\275\277\347\224\250.md"
@@ -0,0 +1,1160 @@
+# 04Spring AOP介绍与使用
+
+AOP:Aspect Oriented Programming 面向切面编程
+
+OOP:Object Oriented Programming 面向对象编程
+
+ 面向切面编程:基于OOP基础之上新的编程思想,OOP面向的主要对象是类,而AOP面向的主要对象是切面,在处理日志、安全管理、事务管理等方面有非常重要的作用。AOP是Spring中重要的核心点,虽然IOC容器没有依赖AOP,但是AOP提供了非常强大的功能,用来对IOC做补充。通俗点说的话就是在程序运行期间,将**某段代码动态切入**到**指定方法**的**指定位置**进行运行的这种编程方式。
+
+### 1、AOP的概念
+
+##### 为什么要引入AOP?
+
+Calculator.java
+
+```java
+package com.mashibing.inter;
+
+public interface Calculator {
+
+ public int add(int i,int j);
+
+ public int sub(int i,int j);
+
+ public int mult(int i,int j);
+
+ public int div(int i,int j);
+}
+```
+
+MyCalculator.java
+
+```java
+package com.mashibing.inter;
+
+public class MyCalculator implements Calculator {
+ public int add(int i, int j) {
+ int result = i + j;
+ return result;
+ }
+
+ public int sub(int i, int j) {
+ int result = i - j;
+ return result;
+ }
+
+ public int mult(int i, int j) {
+ int result = i * j;
+ return result;
+ }
+
+ public int div(int i, int j) {
+ int result = i / j;
+ return result;
+ }
+}
+```
+
+MyTest.java
+
+```java
+public class MyTest {
+ public static void main(String[] args) throws SQLException {
+ MyCalculator myCalculator = new MyCalculator();
+ System.out.println(myCalculator.add(1, 2));
+ }
+}
+```
+
+ 此代码非常简单,就是基础的javase的代码实现,此时如果需要添加日志功能应该怎么做呢,只能在每个方法中添加日志输出,同时如果需要修改的话会变得非常麻烦。
+
+MyCalculator.java
+
+```java
+package com.mashibing.inter;
+
+public class MyCalculator implements Calculator {
+ public int add(int i, int j) {
+ System.out.println("add 方法开始执行,参数为:"+i+","+j);
+ int result = i + j;
+ System.out.println("add 方法开始完成结果为:"+result);
+ return result;
+ }
+
+ public int sub(int i, int j) {
+ System.out.println("sub 方法开始执行,参数为:"+i+","+j);
+ int result = i - j;
+ System.out.println("add 方法开始完成结果为:"+result);
+ return result;
+ }
+
+ public int mult(int i, int j) {
+ System.out.println("mult 方法开始执行,参数为:"+i+","+j);
+ int result = i * j;
+ System.out.println("add 方法开始完成结果为:"+result);
+ return result;
+ }
+
+ public int div(int i, int j) {
+ System.out.println("div 方法开始执行,参数为:"+i+","+j);
+ int result = i / j;
+ System.out.println("add 方法开始完成结果为:"+result);
+ return result;
+ }
+}
+```
+
+ 可以考虑将日志的处理抽象出来,变成工具类来进行实现:
+
+LogUtil.java
+
+```java
+package com.mashibing.util;
+
+import java.util.Arrays;
+
+public class LogUtil {
+
+ public static void start(Object ... objects){
+ System.out.println("XXX方法开始执行,使用的参数是:"+ Arrays.asList(objects));
+ }
+
+ public static void stop(Object ... objects){
+ System.out.println("XXX方法执行结束,结果是:"+ Arrays.asList(objects));
+ }
+}
+```
+
+MyCalculator.java
+
+```java
+package com.mashibing.inter;
+
+import com.mashibing.util.LogUtil;
+
+public class MyCalculator implements Calculator {
+ public int add(int i, int j) {
+ LogUtil.start(i,j);
+ int result = i + j;
+ LogUtil.stop(result);
+ return result;
+ }
+
+ public int sub(int i, int j) {
+ LogUtil.start(i,j);
+ int result = i - j;
+ LogUtil.stop(result);
+ return result;
+ }
+
+ public int mult(int i, int j) {
+ LogUtil.start(i,j);
+ int result = i * j;
+ LogUtil.stop(result);
+ return result;
+ }
+
+ public int div(int i, int j) {
+ LogUtil.start(i,j);
+ int result = i / j;
+ LogUtil.stop(result);
+ return result;
+ }
+}
+```
+
+ 按照上述方式抽象之后,代码确实简单很多,但是大家应该已经发现在输出的信息中并不包含具体的方法名称,我们更多的是想要在程序运行过程中动态的获取方法的名称及参数、结果等相关信息,此时可以通过使用**动态代理**的方式来进行实现。
+
+CalculatorProxy.java
+
+```java
+package com.mashibing.proxy;
+
+import com.mashibing.inter.Calculator;
+
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.lang.reflect.Proxy;
+import java.util.Arrays;
+
+/**
+ * 帮助Calculator生成代理对象的类
+ */
+public class CalculatorProxy {
+
+ /**
+ *
+ * 为传入的参数对象创建一个动态代理对象
+ * @param calculator 被代理对象
+ * @return
+ */
+ public static Calculator getProxy(final Calculator calculator){
+
+
+ //被代理对象的类加载器
+ ClassLoader loader = calculator.getClass().getClassLoader();
+ //被代理对象的接口
+ Class>[] interfaces = calculator.getClass().getInterfaces();
+ //方法执行器,执行被代理对象的目标方法
+ InvocationHandler h = new InvocationHandler() {
+ /**
+ * 执行目标方法
+ * @param proxy 代理对象,给jdk使用,任何时候都不要操作此对象
+ * @param method 当前将要执行的目标对象的方法
+ * @param args 这个方法调用时外界传入的参数值
+ * @return
+ * @throws Throwable
+ */
+ public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
+ //利用反射执行目标方法,目标方法执行后的返回值
+// System.out.println("这是动态代理执行的方法");
+ Object result = null;
+ try {
+ System.out.println(method.getName()+"方法开始执行,参数是:"+ Arrays.asList(args));
+ result = method.invoke(calculator, args);
+ System.out.println(method.getName()+"方法执行完成,结果是:"+ result);
+ } catch (Exception e) {
+ System.out.println(method.getName()+"方法出现异常:"+ e.getMessage());
+ } finally {
+ System.out.println(method.getName()+"方法执行结束了......");
+ }
+ //将结果返回回去
+ return result;
+ }
+ };
+ Object proxy = Proxy.newProxyInstance(loader, interfaces, h);
+ return (Calculator) proxy;
+ }
+}
+```
+
+ 我们可以看到这种方式更加灵活,而且不需要在业务方法中添加额外的代码,这才是常用的方式。如果想追求完美的同学,还可以使用上述的日志工具类来完善。
+
+LogUtil.java
+
+```java
+package com.mashibing.util;
+
+import java.lang.reflect.Method;
+import java.util.Arrays;
+
+public class LogUtil {
+
+ public static void start(Method method, Object ... objects){
+// System.out.println("XXX方法开始执行,使用的参数是:"+ Arrays.asList(objects));
+ System.out.println(method.getName()+"方法开始执行,参数是:"+ Arrays.asList(objects));
+ }
+
+ public static void stop(Method method,Object ... objects){
+// System.out.println("XXX方法执行结束,结果是:"+ Arrays.asList(objects));
+ System.out.println(method.getName()+"方法开始执行,参数是:"+ Arrays.asList(objects));
+
+ }
+
+ public static void logException(Method method,Exception e){
+ System.out.println(method.getName()+"方法出现异常:"+ e.getMessage());
+ }
+
+ public static void end(Method method){
+ System.out.println(method.getName()+"方法执行结束了......");
+ }
+}
+```
+
+CalculatorProxy.java
+
+```java
+package com.mashibing.proxy;
+
+import com.mashibing.inter.Calculator;
+import com.mashibing.util.LogUtil;
+
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.lang.reflect.Proxy;
+import java.util.Arrays;
+
+/**
+ * 帮助Calculator生成代理对象的类
+ */
+public class CalculatorProxy {
+
+ /**
+ *
+ * 为传入的参数对象创建一个动态代理对象
+ * @param calculator 被代理对象
+ * @return
+ */
+ public static Calculator getProxy(final Calculator calculator){
+
+
+ //被代理对象的类加载器
+ ClassLoader loader = calculator.getClass().getClassLoader();
+ //被代理对象的接口
+ Class>[] interfaces = calculator.getClass().getInterfaces();
+ //方法执行器,执行被代理对象的目标方法
+ InvocationHandler h = new InvocationHandler() {
+ /**
+ * 执行目标方法
+ * @param proxy 代理对象,给jdk使用,任何时候都不要操作此对象
+ * @param method 当前将要执行的目标对象的方法
+ * @param args 这个方法调用时外界传入的参数值
+ * @return
+ * @throws Throwable
+ */
+ public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
+ //利用反射执行目标方法,目标方法执行后的返回值
+// System.out.println("这是动态代理执行的方法");
+ Object result = null;
+ try {
+ LogUtil.start(method,args);
+ result = method.invoke(calculator, args);
+ LogUtil.stop(method,args);
+ } catch (Exception e) {
+ LogUtil.logException(method,e);
+ } finally {
+ LogUtil.end(method);
+ }
+ //将结果返回回去
+ return result;
+ }
+ };
+ Object proxy = Proxy.newProxyInstance(loader, interfaces, h);
+ return (Calculator) proxy;
+ }
+}
+```
+
+ 很多同学看到上述代码之后可能感觉已经非常完美了,但是要说明的是,这种动态代理的实现方式调用的是jdk的基本实现,如果需要代理的目标对象没有实现任何接口,那么是无法为他创建代理对象的,这也是致命的缺陷。而在Spring中我们可以不编写上述如此复杂的代码,只需要利用AOP,就能够轻轻松松实现上述功能,当然,Spring AOP的底层实现也依赖的是动态代理。
+
+##### AOP的核心概念及术语
+
+- 切面(Aspect): 指关注点模块化,这个关注点可能会横切多个对象。事务管理是企业级Java应用中有关横切关注点的例子。 在Spring AOP中,切面可以使用通用类基于模式的方式(schema-based approach)或者在普通类中以`@Aspect`注解(@AspectJ 注解方式)来实现。
+- 连接点(Join point): 在程序执行过程中某个特定的点,例如某个方法调用的时间点或者处理异常的时间点。在Spring AOP中,一个连接点总是代表一个方法的执行。
+- 通知(Advice): 在切面的某个特定的连接点上执行的动作。通知有多种类型,包括“around”, “before” and “after”等等。通知的类型将在后面的章节进行讨论。 许多AOP框架,包括Spring在内,都是以拦截器做通知模型的,并维护着一个以连接点为中心的拦截器链。
+- 切点(Pointcut): 匹配连接点的断言。通知和切点表达式相关联,并在满足这个切点的连接点上运行(例如,当执行某个特定名称的方法时)。切点表达式如何和连接点匹配是AOP的核心:Spring默认使用AspectJ切点语义。
+- 引入(Introduction): 声明额外的方法或者某个类型的字段。Spring允许引入新的接口(以及一个对应的实现)到任何被通知的对象上。例如,可以使用引入来使bean实现 `IsModified`接口, 以便简化缓存机制(在AspectJ社区,引入也被称为内部类型声明(inter))。
+- 目标对象(Target object): 被一个或者多个切面所通知的对象。也被称作被通知(advised)对象。既然Spring AOP是通过运行时代理实现的,那么这个对象永远是一个被代理(proxied)的对象。
+- AOP代理(AOP proxy):AOP框架创建的对象,用来实现切面契约(aspect contract)(包括通知方法执行等功能)。在Spring中,AOP代理可以是JDK动态代理或CGLIB代理。
+- 织入(Weaving): 把切面连接到其它的应用程序类型或者对象上,并创建一个被被通知的对象的过程。这个过程可以在编译时(例如使用AspectJ编译器)、类加载时或运行时中完成。 Spring和其他纯Java AOP框架一样,是在运行时完成织入的。
+
+##### AOP的通知类型
+
+- 前置通知(Before advice): 在连接点之前运行但无法阻止执行流程进入连接点的通知(除非它引发异常)。
+- 后置返回通知(After returning advice):在连接点正常完成后执行的通知(例如,当方法没有抛出任何异常并正常返回时)。
+- 后置异常通知(After throwing advice): 在方法抛出异常退出时执行的通知。
+- 后置通知(总会执行)(After (finally) advice): 当连接点退出的时候执行的通知(无论是正常返回还是异常退出)。
+- 环绕通知(Around Advice):环绕连接点的通知,例如方法调用。这是最强大的一种通知类型,。环绕通知可以在方法调用前后完成自定义的行为。它可以选择是否继续执行连接点或直接返回自定义的返回值又或抛出异常将执行结束。
+
+##### AOP的应用场景
+
+- 日志管理
+- 权限认证
+- 安全检查
+- 事务控制
+
+### 2、Spring AOP的简单配置
+
+ 在上述代码中我们是通过动态代理的方式实现日志功能的,但是比较麻烦,现在我们将要使用spring aop的功能实现此需求,其实通俗点说的话,就是把LogUtil的工具类换成另外一种实现方式。
+
+##### 1、添加pom依赖
+
+```xml
+
+
+ cglib
+ cglib
+ 3.3.0
+
+
+
+ org.aspectj
+ aspectjweaver
+ 1.9.5
+
+
+
+ aopalliance
+ aopalliance
+ 1.0
+
+
+
+ org.springframework
+ spring-aspects
+ 5.2.3.RELEASE
+
+```
+
+##### 2、编写配置
+
+- 将目标类和切面类加入到IOC容器中,在对应的类上添加组件注解
+
+ - 给LogUtil添加@Component注解
+
+ - 给MyCalculator添加@Service注解
+
+ - 添加自动扫描的配置
+
+ ```xml
+
+
+ ```
+
+- 设置程序中的切面类
+
+ - 在LogUtil.java中添加@Aspect注解
+
+- 设置切面类中的方法是什么时候在哪里执行
+
+ ```java
+ package com.mashibing.util;
+
+ import org.aspectj.lang.annotation.*;
+ import org.springframework.stereotype.Component;
+
+ import java.lang.reflect.Method;
+ import java.util.Arrays;
+
+ @Component
+ @Aspect
+ public class LogUtil {
+
+ /*
+ 设置下面方法在什么时候运行
+ @Before:在目标方法之前运行:前置通知
+ @After:在目标方法之后运行:后置通知
+ @AfterReturning:在目标方法正常返回之后:返回通知
+ @AfterThrowing:在目标方法抛出异常后开始运行:异常通知
+ @Around:环绕:环绕通知
+
+ 当编写完注解之后还需要设置在哪些方法上执行,使用表达式
+ execution(访问修饰符 返回值类型 方法全称)
+ */
+ @Before("execution( public int com.mashibing.inter.MyCalculator.*(int,int))")
+ public static void start(){
+ // System.out.println("XXX方法开始执行,使用的参数是:"+ Arrays.asList(objects));
+ // System.out.println(method.getName()+"方法开始执行,参数是:"+ Arrays.asList(objects));
+ System.out.println("方法开始执行,参数是:");
+ }
+
+ @AfterReturning("execution( public int com.mashibing.inter.MyCalculator.*(int,int))")
+ public static void stop(){
+ // System.out.println("XXX方法执行结束,结果是:"+ Arrays.asList(objects));
+ // System.out.println(method.getName()+"方法执行结束,结果是:"+ Arrays.asList(objects));
+ System.out.println("方法执行完成,结果是:");
+
+ }
+
+ @AfterThrowing("execution( public int com.mashibing.inter.MyCalculator.*(int,int))")
+ public static void logException(){
+ // System.out.println(method.getName()+"方法出现异常:"+ e.getMessage());
+ System.out.println("方法出现异常:");
+ }
+
+ @After("execution( public int com.mashibing.inter.MyCalculator.*(int,int))")
+ public static void end(){
+ // System.out.println(method.getName()+"方法执行结束了......");
+ System.out.println("方法执行结束了......");
+ }
+ }
+ ```
+
+- 开启基于注解的aop的功能
+
+ ```xml
+
+
+
+
+
+ ```
+
+
+##### 3、测试
+
+ MyTest.java
+
+ ```java
+ import com.mashibing.inter.Calculator;
+ import org.springframework.context.ApplicationContext;
+ import org.springframework.context.support.ClassPathXmlApplicationContext;
+ public class MyTest {
+ public static void main(String[] args){
+ ApplicationContext context = new ClassPathXmlApplicationContext("aop.xml");
+ Calculator bean = context.getBean(Calculator.class);
+ bean.add(1,1);
+ }
+}
+ ```
+
+ spring AOP的动态代理方式是jdk自带的方式,容器中保存的组件是代理对象com.sun.proxy.$Proxy对象
+
+ ##### 4、通过cglib来创建代理对象
+
+MyCalculator.java
+
+```java
+package com.mashibing.inter;
+
+import org.springframework.stereotype.Service;
+
+@Service
+public class MyCalculator {
+ public int add(int i, int j) {
+ int result = i + j;
+ return result;
+ }
+
+ public int sub(int i, int j) {
+ int result = i - j;
+ return result;
+ }
+
+ public int mult(int i, int j) {
+ int result = i * j;
+ return result;
+ }
+
+ public int div(int i, int j) {
+ int result = i / j;
+ return result;
+ }
+}
+```
+
+MyTest.java
+
+```java
+public class MyTest {
+ public static void main(String[] args){
+ ApplicationContext context = new ClassPathXmlApplicationContext("aop.xml");
+ MyCalculator bean = context.getBean(MyCalculator.class);
+ bean.add(1,1);
+ System.out.println(bean);
+ System.out.println(bean.getClass());
+ }
+}
+```
+
+ 可以通过cglib的方式来创建代理对象,此时不需要实现任何接口,代理对象是
+
+class com.mashibing.inter.MyCalculator$$EnhancerBySpringCGLIB$$1f93b605类型
+
+ **综上所述:在spring容器中,如果有接口,那么会使用jdk自带的动态代理,如果没有接口,那么会使用cglib的动态代理。动态代理的实现原理,后续会详细讲。**
+
+##### 注意:
+
+###### 1、切入点表达式
+
+ 在使用表达式的时候,除了之前的写法之外,还可以使用通配符的方式:
+
+ *:
+
+ 1、匹配一个或者多个字符
+
+ execution( public int com.mashibing.inter.My\*alculator.*(int,int))
+
+ 2、匹配任意一个参数,
+
+ execution( public int com.mashibing.inter.MyCalculator.\*(int,\*))
+
+ 3、只能匹配一层路径,如果项目路径下有多层目录,那么*只能匹配一层路径
+
+ 4、权限位置不能使用*,如果想表示全部权限,那么不写即可
+
+ execution( * com.mashibing.inter.MyCalculator.\*(int,\*))
+
+ ..:
+
+ 1、匹配多个参数,任意类型参数
+
+ execution( * com.mashibing.inter.MyCalculator.\*(..))
+
+ 2、匹配任意多层路径
+
+ execution( * com.mashibing..MyCalculator.\*(..))
+
+ 在写表达式的时候,可以有N多种写法,但是有一种最偷懒和最精确的方式:
+
+ 最偷懒的方式:execution(* \*(..)) 或者 execution(* \*.\*(..))
+
+ 最精确的方式:execution( public int com.mashibing.inter.MyCalculator.add(int,int))
+
+ 除此之外,在表达式中还支持 &&、||、!的方式
+
+ &&:两个表达式同时
+
+ execution( public int com.mashibing.inter.MyCalculator.*(..)) && execution(\* \*.\*(int,int) )
+
+ ||:任意满足一个表达式即可
+
+ execution( public int com.mashibing.inter.MyCalculator.*(..)) && execution(\* \*.\*(int,int) )
+
+ !:只要不是这个位置都可以进行切入
+
+ &&:两个表达式同时
+
+ execution( public int com.mashibing.inter.MyCalculator.*(..))
+
+###### 2、通知方法的执行顺序
+
+ 在之前的代码中大家一直对通知的执行顺序有疑问,其实执行的结果并没有错,大家需要注意:
+
+ 1、正常执行:@Before--->@After--->@AfterReturning
+
+ 2、异常执行:@Before--->@After--->@AfterThrowing
+
+###### 3、获取方法的详细信息
+
+ 在上面的案例中,我们并没有获取Method的详细信息,例如方法名、参数列表等信息,想要获取的话其实非常简单,只需要添加JoinPoint参数即可。
+
+LogUtil.java
+
+```java
+package com.mashibing.util;
+
+import org.aspectj.lang.JoinPoint;
+import org.aspectj.lang.annotation.*;
+import org.springframework.stereotype.Component;
+
+import java.util.Arrays;
+
+@Component
+@Aspect
+public class LogUtil {
+
+ @Before("execution( public int com.mashibing.inter.MyCalculator.*(int,int))")
+ public static void start(JoinPoint joinPoint){
+ Object[] args = joinPoint.getArgs();
+ String name = joinPoint.getSignature().getName();
+ System.out.println(name+"方法开始执行,参数是:"+ Arrays.asList(args));
+ }
+
+ @AfterReturning("execution( public int com.mashibing.inter.MyCalculator.*(int,int))")
+ public static void stop(JoinPoint joinPoint){
+ String name = joinPoint.getSignature().getName();
+ System.out.println(name+"方法执行完成,结果是:");
+
+ }
+
+ @AfterThrowing("execution( public int com.mashibing.inter.MyCalculator.*(int,int))")
+ public static void logException(JoinPoint joinPoint){
+ String name = joinPoint.getSignature().getName();
+ System.out.println(name+"方法出现异常:");
+ }
+
+ @After("execution( public int com.mashibing.inter.MyCalculator.*(int,int))")
+ public static void end(JoinPoint joinPoint){
+ String name = joinPoint.getSignature().getName();
+ System.out.println(name+"方法执行结束了......");
+ }
+}
+```
+
+ 刚刚只是获取了方法的信息,但是如果需要获取结果,还需要添加另外一个方法参数,并且告诉spring使用哪个参数来进行结果接收
+
+LogUtil.java
+
+```java
+ @AfterReturning(value = "execution( public int com.mashibing.inter.MyCalculator.*(int,int))",returning = "result")
+ public static void stop(JoinPoint joinPoint,Object result){
+ String name = joinPoint.getSignature().getName();
+ System.out.println(name+"方法执行完成,结果是:"+result);
+
+ }
+```
+
+ 也可以通过相同的方式来获取异常的信息
+
+LogUtil.java
+
+```java
+ @AfterThrowing(value = "execution( public int com.mashibing.inter.MyCalculator.*(int,int))",throwing = "exception")
+ public static void logException(JoinPoint joinPoint,Exception exception){
+ String name = joinPoint.getSignature().getName();
+ System.out.println(name+"方法出现异常:"+exception);
+ }
+```
+
+###### 4、spring对通过方法的要求
+
+ spring对于通知方法的要求并不是很高,你可以任意改变方法的返回值和方法的访问修饰符,但是唯一不能修改的就是方法的参数,会出现参数绑定的错误,原因在于通知方法是spring利用反射调用的,每次方法调用得确定这个方法的参数的值。
+
+LogUtil.java
+
+```java
+ @After("execution( public int com.mashibing.inter.MyCalculator.*(int,int))")
+ private int end(JoinPoint joinPoint,String aa){
+// System.out.println(method.getName()+"方法执行结束了......");
+ String name = joinPoint.getSignature().getName();
+ System.out.println(name+"方法执行结束了......");
+ return 0;
+ }
+```
+
+###### 5、表达式的抽取
+
+如果在实际使用过程中,多个方法的表达式是一致的话,那么可以考虑将切入点表达式抽取出来:
+
+ a、随便生命一个没有实现的返回void的空方法
+
+ b、给方法上标注@Potintcut注解
+
+```java
+package com.mashibing.util;
+
+import org.aspectj.lang.JoinPoint;
+import org.aspectj.lang.annotation.*;
+import org.springframework.stereotype.Component;
+
+import java.util.Arrays;
+
+@Component
+@Aspect
+public class LogUtil {
+
+ @Pointcut("execution( public int com.mashibing.inter.MyCalculator.*(int,int))")
+ public void myPoint(){}
+
+ @Before("myPoint()")
+ public static void start(JoinPoint joinPoint){
+ Object[] args = joinPoint.getArgs();
+ String name = joinPoint.getSignature().getName();
+ System.out.println(name+"方法开始执行,参数是:"+ Arrays.asList(args));
+ }
+
+ @AfterReturning(value = "myPoint()",returning = "result")
+ public static void stop(JoinPoint joinPoint,Object result){
+ String name = joinPoint.getSignature().getName();
+ System.out.println(name+"方法执行完成,结果是:"+result);
+
+ }
+
+ @AfterThrowing(value = "myPoint()",throwing = "exception")
+ public static void logException(JoinPoint joinPoint,Exception exception){
+ String name = joinPoint.getSignature().getName();
+ System.out.println(name+"方法出现异常:"+exception.getMessage());
+ }
+
+ @After("myPoint()")
+ private int end(JoinPoint joinPoint){
+ String name = joinPoint.getSignature().getName();
+ System.out.println(name+"方法执行结束了......");
+ return 0;
+ }
+}
+```
+
+###### 6、环绕通知的使用
+
+LogUtil.java
+
+```java
+package com.mashibing.util;
+
+import org.aspectj.lang.JoinPoint;
+import org.aspectj.lang.ProceedingJoinPoint;
+import org.aspectj.lang.annotation.*;
+import org.springframework.stereotype.Component;
+
+import java.util.Arrays;
+
+@Component
+@Aspect
+public class LogUtil {
+ @Pointcut("execution( public int com.mashibing.inter.MyCalculator.*(int,int))")
+ public void myPoint(){}
+
+ /**
+ * 环绕通知是spring中功能最强大的通知
+ * @param proceedingJoinPoint
+ * @return
+ */
+ @Around("myPoint()")
+ public Object myAround(ProceedingJoinPoint proceedingJoinPoint){
+ Object[] args = proceedingJoinPoint.getArgs();
+ String name = proceedingJoinPoint.getSignature().getName();
+ Object proceed = null;
+ try {
+ System.out.println("环绕前置通知:"+name+"方法开始,参数是"+Arrays.asList(args));
+ //利用反射调用目标方法,就是method.invoke()
+ proceed = proceedingJoinPoint.proceed(args);
+ System.out.println("环绕返回通知:"+name+"方法返回,返回值是"+proceed);
+ } catch (Throwable e) {
+ System.out.println("环绕异常通知"+name+"方法出现异常,异常信息是:"+e);
+ }finally {
+ System.out.println("环绕后置通知"+name+"方法结束");
+ }
+ return proceed;
+ }
+}
+```
+
+ 总结:环绕通知的执行顺序是优于普通通知的,具体的执行顺序如下:
+
+环绕前置-->普通前置-->目标方法执行-->环绕正常结束/出现异常-->环绕后置-->普通后置-->普通返回或者异常。
+
+但是需要注意的是,如果出现了异常,那么环绕通知会处理或者捕获异常,普通异常通知是接收不到的,因此最好的方式是在环绕异常通知中向外抛出异常。
+
+###### 7、多切面运行的顺序
+
+ 如果有多个切面要进行执行,那么顺序是什么样的呢?
+
+LogUtil.java
+
+```java
+package com.mashibing.util;
+
+import org.aspectj.lang.JoinPoint;
+import org.aspectj.lang.ProceedingJoinPoint;
+import org.aspectj.lang.annotation.*;
+import org.springframework.stereotype.Component;
+
+import java.util.Arrays;
+
+@Component
+@Aspect
+public class LogUtil {
+ @Pointcut("execution( public int com.mashibing.inter.MyCalculator.*(int,int))")
+ public void myPoint(){}
+ @Before("myPoint()")
+ public static void start(JoinPoint joinPoint){
+// System.out.println("XXX方法开始执行,使用的参数是:"+ Arrays.asList(objects));
+// System.out.println(method.getName()+"方法开始执行,参数是:"+ Arrays.asList(objects));
+ Object[] args = joinPoint.getArgs();
+ String name = joinPoint.getSignature().getName();
+ System.out.println("Log:"+name+"方法开始执行,参数是:"+ Arrays.asList(args));
+ }
+
+ @AfterReturning(value = "myPoint()",returning = "result")
+ public static void stop(JoinPoint joinPoint,Object result){
+// System.out.println("XXX方法执行结束,结果是:"+ Arrays.asList(objects));
+// System.out.println(method.getName()+"方法执行结束,结果是:"+ Arrays.asList(objects));
+ String name = joinPoint.getSignature().getName();
+ System.out.println("Log:"+name+"方法执行完成,结果是:"+result);
+
+ }
+
+ @AfterThrowing(value = "myPoint()",throwing = "exception")
+ public static void logException(JoinPoint joinPoint,Exception exception){
+// System.out.println(method.getName()+"方法出现异常:"+ e.getMessage());
+ String name = joinPoint.getSignature().getName();
+ System.out.println("Log:"+name+"方法出现异常:"+exception.getMessage());
+ }
+
+ @After("myPoint()")
+ private int end(JoinPoint joinPoint){
+// System.out.println(method.getName()+"方法执行结束了......");
+ String name = joinPoint.getSignature().getName();
+ System.out.println("Log:"+name+"方法执行结束了......");
+ return 0;
+ }
+
+ /**
+ * 环绕通知是spring中功能最强大的通知
+ * @param proceedingJoinPoint
+ * @return
+ */
+ //@Around("myPoint()")
+ public Object myAround(ProceedingJoinPoint proceedingJoinPoint){
+ Object[] args = proceedingJoinPoint.getArgs();
+ String name = proceedingJoinPoint.getSignature().getName();
+ Object proceed = null;
+ try {
+ System.out.println("环绕前置通知:"+name+"方法开始,参数是"+Arrays.asList(args));
+ //利用反射调用目标方法,就是method.invoke()
+ proceed = proceedingJoinPoint.proceed(args);
+ System.out.println("环绕返回通知:"+name+"方法返回,返回值是"+proceed);
+ } catch (Throwable e) {
+ System.out.println("环绕异常通知"+name+"方法出现异常,异常信息是:"+e);
+ }finally {
+ System.out.println("环绕后置通知"+name+"方法结束");
+ }
+ return proceed;
+ }
+}
+```
+
+SecurityAspect.java
+
+```java
+package com.mashibing.util;
+
+import org.aspectj.lang.JoinPoint;
+import org.aspectj.lang.ProceedingJoinPoint;
+import org.aspectj.lang.annotation.*;
+import org.springframework.stereotype.Component;
+
+import java.util.Arrays;
+
+@Component
+@Aspect
+public class SecurityAspect {
+
+ @Before("com.mashibing.util.LogUtil.myPoint()")
+ public static void start(JoinPoint joinPoint){
+ Object[] args = joinPoint.getArgs();
+ String name = joinPoint.getSignature().getName();
+ System.out.println("Security:"+name+"方法开始执行,参数是:"+ Arrays.asList(args));
+ }
+
+ @AfterReturning(value = "com.mashibing.util.LogUtil.myPoint()",returning = "result")
+ public static void stop(JoinPoint joinPoint,Object result){
+ String name = joinPoint.getSignature().getName();
+ System.out.println("Security:"+name+"方法执行完成,结果是:"+result);
+
+ }
+
+ @AfterThrowing(value = "com.mashibing.util.LogUtil.myPoint()",throwing = "exception")
+ public static void logException(JoinPoint joinPoint,Exception exception){
+ String name = joinPoint.getSignature().getName();
+ System.out.println("Security:"+name+"方法出现异常:"+exception.getMessage());
+ }
+
+ @After("com.mashibing.util.LogUtil.myPoint()")
+ private int end(JoinPoint joinPoint){
+ String name = joinPoint.getSignature().getName();
+ System.out.println("Security:"+name+"方法执行结束了......");
+ return 0;
+ }
+
+ /**
+ * 环绕通知是spring中功能最强大的通知
+ * @param proceedingJoinPoint
+ * @return
+ */
+ //@Around("myPoint()")
+ public Object myAround(ProceedingJoinPoint proceedingJoinPoint){
+ Object[] args = proceedingJoinPoint.getArgs();
+ String name = proceedingJoinPoint.getSignature().getName();
+ Object proceed = null;
+ try {
+ System.out.println("环绕前置通知:"+name+"方法开始,参数是"+Arrays.asList(args));
+ //利用反射调用目标方法,就是method.invoke()
+ proceed = proceedingJoinPoint.proceed(args);
+ System.out.println("环绕返回通知:"+name+"方法返回,返回值是"+proceed);
+ } catch (Throwable e) {
+ System.out.println("环绕异常通知"+name+"方法出现异常,异常信息是:"+e);
+ }finally {
+ System.out.println("环绕后置通知"+name+"方法结束");
+ }
+ return proceed;
+ }
+}
+```
+
+ 在spring中,默认是按照切面名称的字典顺序进行执行的,但是如果想自己改变具体的执行顺序的话,可以使用@Order注解来解决,数值越小,优先级越高。
+
+LogUtil.java
+
+```java
+package com.mashibing.util;
+
+import org.aspectj.lang.JoinPoint;
+import org.aspectj.lang.ProceedingJoinPoint;
+import org.aspectj.lang.annotation.*;
+import org.springframework.stereotype.Component;
+
+import java.util.Arrays;
+
+@Component
+@Aspect
+@Order(2)
+public class LogUtil {
+ @Pointcut("execution( public int com.mashibing.inter.MyCalculator.*(int,int))")
+ public void myPoint(){}
+ @Before("myPoint()")
+ public static void start(JoinPoint joinPoint){
+// System.out.println("XXX方法开始执行,使用的参数是:"+ Arrays.asList(objects));
+// System.out.println(method.getName()+"方法开始执行,参数是:"+ Arrays.asList(objects));
+ Object[] args = joinPoint.getArgs();
+ String name = joinPoint.getSignature().getName();
+ System.out.println("Log:"+name+"方法开始执行,参数是:"+ Arrays.asList(args));
+ }
+
+ @AfterReturning(value = "myPoint()",returning = "result")
+ public static void stop(JoinPoint joinPoint,Object result){
+// System.out.println("XXX方法执行结束,结果是:"+ Arrays.asList(objects));
+// System.out.println(method.getName()+"方法执行结束,结果是:"+ Arrays.asList(objects));
+ String name = joinPoint.getSignature().getName();
+ System.out.println("Log:"+name+"方法执行完成,结果是:"+result);
+
+ }
+
+ @AfterThrowing(value = "myPoint()",throwing = "exception")
+ public static void logException(JoinPoint joinPoint,Exception exception){
+// System.out.println(method.getName()+"方法出现异常:"+ e.getMessage());
+ String name = joinPoint.getSignature().getName();
+ System.out.println("Log:"+name+"方法出现异常:"+exception.getMessage());
+ }
+
+ @After("myPoint()")
+ private int end(JoinPoint joinPoint){
+// System.out.println(method.getName()+"方法执行结束了......");
+ String name = joinPoint.getSignature().getName();
+ System.out.println("Log:"+name+"方法执行结束了......");
+ return 0;
+ }
+
+ /**
+ * 环绕通知是spring中功能最强大的通知
+ * @param proceedingJoinPoint
+ * @return
+ */
+ //@Around("myPoint()")
+ public Object myAround(ProceedingJoinPoint proceedingJoinPoint){
+ Object[] args = proceedingJoinPoint.getArgs();
+ String name = proceedingJoinPoint.getSignature().getName();
+ Object proceed = null;
+ try {
+ System.out.println("环绕前置通知:"+name+"方法开始,参数是"+Arrays.asList(args));
+ //利用反射调用目标方法,就是method.invoke()
+ proceed = proceedingJoinPoint.proceed(args);
+ System.out.println("环绕返回通知:"+name+"方法返回,返回值是"+proceed);
+ } catch (Throwable e) {
+ System.out.println("环绕异常通知"+name+"方法出现异常,异常信息是:"+e);
+ }finally {
+ System.out.println("环绕后置通知"+name+"方法结束");
+ }
+ return proceed;
+ }
+}
+```
+
+SecurityAspect.java
+
+```java
+package com.mashibing.util;
+
+import org.aspectj.lang.JoinPoint;
+import org.aspectj.lang.ProceedingJoinPoint;
+import org.aspectj.lang.annotation.*;
+import org.springframework.stereotype.Component;
+
+import java.util.Arrays;
+
+@Component
+@Aspect
+@Order(1)
+public class SecurityAspect {
+
+ @Before("com.mashibing.util.LogUtil.myPoint()")
+ public static void start(JoinPoint joinPoint){
+ Object[] args = joinPoint.getArgs();
+ String name = joinPoint.getSignature().getName();
+ System.out.println("Security:"+name+"方法开始执行,参数是:"+ Arrays.asList(args));
+ }
+
+ @AfterReturning(value = "com.mashibing.util.LogUtil.myPoint()",returning = "result")
+ public static void stop(JoinPoint joinPoint,Object result){
+ String name = joinPoint.getSignature().getName();
+ System.out.println("Security:"+name+"方法执行完成,结果是:"+result);
+
+ }
+
+ @AfterThrowing(value = "com.mashibing.util.LogUtil.myPoint()",throwing = "exception")
+ public static void logException(JoinPoint joinPoint,Exception exception){
+ String name = joinPoint.getSignature().getName();
+ System.out.println("Security:"+name+"方法出现异常:"+exception.getMessage());
+ }
+
+ @After("com.mashibing.util.LogUtil.myPoint()")
+ private int end(JoinPoint joinPoint){
+ String name = joinPoint.getSignature().getName();
+ System.out.println("Security:"+name+"方法执行结束了......");
+ return 0;
+ }
+
+ /**
+ * 环绕通知是spring中功能最强大的通知
+ * @param proceedingJoinPoint
+ * @return
+ */
+ //@Around("myPoint()")
+ public Object myAround(ProceedingJoinPoint proceedingJoinPoint){
+ Object[] args = proceedingJoinPoint.getArgs();
+ String name = proceedingJoinPoint.getSignature().getName();
+ Object proceed = null;
+ try {
+ System.out.println("环绕前置通知:"+name+"方法开始,参数是"+Arrays.asList(args));
+ //利用反射调用目标方法,就是method.invoke()
+ proceed = proceedingJoinPoint.proceed(args);
+ System.out.println("环绕返回通知:"+name+"方法返回,返回值是"+proceed);
+ } catch (Throwable e) {
+ System.out.println("环绕异常通知"+name+"方法出现异常,异常信息是:"+e);
+ }finally {
+ System.out.println("环绕后置通知"+name+"方法结束");
+ }
+ return proceed;
+ }
+}
+```
+
+ 如果需要添加环绕通知呢,具体的执行顺序又会是什么顺序呢?
+
+ 因为环绕通知在进行添加的时候,是在切面层引入的,所以在哪个切面添加环绕通知,那么就会在哪个切面执行。
+
+### 3、基于配置的AOP配置
+
+ 之前我们讲解了基于注解的AOP配置方式,下面我们开始讲一下基于xml的配置方式,虽然在现在的企业级开发中使用注解的方式比较多,但是你不能不会,因此需要简单的进行配置,注解配置快速简单,配置的方式共呢个完善。
+
+1、将所有的注解都进行删除
+
+2、添加配置文件
+
+aop.xml
+
+```xml
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+```
+
diff --git "a/javaframework/spring/06SpringAOP\347\232\204\350\257\246\347\273\206\350\256\262\350\247\243/code/spring_aop_study/.idea/compiler.xml" "b/javaframework/spring/06SpringAOP\347\232\204\350\257\246\347\273\206\350\256\262\350\247\243/code/spring_aop_study/.idea/compiler.xml"
new file mode 100644
index 00000000..958a9165
--- /dev/null
+++ "b/javaframework/spring/06SpringAOP\347\232\204\350\257\246\347\273\206\350\256\262\350\247\243/code/spring_aop_study/.idea/compiler.xml"
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git "a/javaframework/spring/06SpringAOP\347\232\204\350\257\246\347\273\206\350\256\262\350\247\243/code/spring_aop_study/.idea/misc.xml" "b/javaframework/spring/06SpringAOP\347\232\204\350\257\246\347\273\206\350\256\262\350\247\243/code/spring_aop_study/.idea/misc.xml"
new file mode 100644
index 00000000..4b661a5f
--- /dev/null
+++ "b/javaframework/spring/06SpringAOP\347\232\204\350\257\246\347\273\206\350\256\262\350\247\243/code/spring_aop_study/.idea/misc.xml"
@@ -0,0 +1,14 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git "a/javaframework/spring/06SpringAOP\347\232\204\350\257\246\347\273\206\350\256\262\350\247\243/code/spring_aop_study/.idea/uiDesigner.xml" "b/javaframework/spring/06SpringAOP\347\232\204\350\257\246\347\273\206\350\256\262\350\247\243/code/spring_aop_study/.idea/uiDesigner.xml"
new file mode 100644
index 00000000..e96534fb
--- /dev/null
+++ "b/javaframework/spring/06SpringAOP\347\232\204\350\257\246\347\273\206\350\256\262\350\247\243/code/spring_aop_study/.idea/uiDesigner.xml"
@@ -0,0 +1,124 @@
+
+
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+
+
+
+ -
+
+
+
+
+
+ -
+
+
+
+
+
+ -
+
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+
+
+ -
+
+
+ -
+
+
+
+
+
\ No newline at end of file
diff --git "a/javaframework/spring/06SpringAOP\347\232\204\350\257\246\347\273\206\350\256\262\350\247\243/code/spring_aop_study/.idea/workspace.xml" "b/javaframework/spring/06SpringAOP\347\232\204\350\257\246\347\273\206\350\256\262\350\247\243/code/spring_aop_study/.idea/workspace.xml"
new file mode 100644
index 00000000..8c789d55
--- /dev/null
+++ "b/javaframework/spring/06SpringAOP\347\232\204\350\257\246\347\273\206\350\256\262\350\247\243/code/spring_aop_study/.idea/workspace.xml"
@@ -0,0 +1,784 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ int
+
+
+ Integer
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 1581768338458
+
+
+ 1581768338458
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ c3p0-0.9.5.4
+
+
+
+
+
+
+
+
+
+
+
+ 1.7
+
+
+
+
+
+
+
+
+
+
+
+ spring_aop_study
+
+
+
+
+
+
+
+
+
+
+
+
+ 1.8
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git "a/javaframework/spring/06SpringAOP\347\232\204\350\257\246\347\273\206\350\256\262\350\247\243/code/spring_aop_study/pom.xml" "b/javaframework/spring/06SpringAOP\347\232\204\350\257\246\347\273\206\350\256\262\350\247\243/code/spring_aop_study/pom.xml"
new file mode 100644
index 00000000..d9b23714
--- /dev/null
+++ "b/javaframework/spring/06SpringAOP\347\232\204\350\257\246\347\273\206\350\256\262\350\247\243/code/spring_aop_study/pom.xml"
@@ -0,0 +1,50 @@
+
+
+ 4.0.0
+
+ com.mashibing
+ spring_aop_study
+ 1.0-SNAPSHOT
+
+
+
+
+ junit
+ junit
+ 4.12
+ test
+
+
+
+ org.springframework
+ spring-context
+ 5.2.3.RELEASE
+
+
+
+ cglib
+ cglib
+ 3.3.0
+
+
+
+ org.aspectj
+ aspectjweaver
+ 1.9.5
+
+
+
+ aopalliance
+ aopalliance
+ 1.0
+
+
+
+ org.springframework
+ spring-aspects
+ 5.2.3.RELEASE
+
+
+
\ No newline at end of file
diff --git "a/javaframework/spring/06SpringAOP\347\232\204\350\257\246\347\273\206\350\256\262\350\247\243/code/spring_aop_study/spring_aop_study.iml" "b/javaframework/spring/06SpringAOP\347\232\204\350\257\246\347\273\206\350\256\262\350\247\243/code/spring_aop_study/spring_aop_study.iml"
new file mode 100644
index 00000000..78b2cc53
--- /dev/null
+++ "b/javaframework/spring/06SpringAOP\347\232\204\350\257\246\347\273\206\350\256\262\350\247\243/code/spring_aop_study/spring_aop_study.iml"
@@ -0,0 +1,2 @@
+
+
\ No newline at end of file
diff --git "a/javaframework/spring/06SpringAOP\347\232\204\350\257\246\347\273\206\350\256\262\350\247\243/code/spring_aop_study/src/main/java/com/mashibing/myinter/MyInterface.java" "b/javaframework/spring/06SpringAOP\347\232\204\350\257\246\347\273\206\350\256\262\350\247\243/code/spring_aop_study/src/main/java/com/mashibing/myinter/MyInterface.java"
new file mode 100644
index 00000000..f39d68d2
--- /dev/null
+++ "b/javaframework/spring/06SpringAOP\347\232\204\350\257\246\347\273\206\350\256\262\350\247\243/code/spring_aop_study/src/main/java/com/mashibing/myinter/MyInterface.java"
@@ -0,0 +1,6 @@
+package com.mashibing.myinter;
+
+public interface MyInterface {
+
+ public void show(Integer i);
+}
diff --git "a/javaframework/spring/06SpringAOP\347\232\204\350\257\246\347\273\206\350\256\262\350\247\243/code/spring_aop_study/src/main/java/com/mashibing/myinter/MySubClass.java" "b/javaframework/spring/06SpringAOP\347\232\204\350\257\246\347\273\206\350\256\262\350\247\243/code/spring_aop_study/src/main/java/com/mashibing/myinter/MySubClass.java"
new file mode 100644
index 00000000..9a327f40
--- /dev/null
+++ "b/javaframework/spring/06SpringAOP\347\232\204\350\257\246\347\273\206\350\256\262\350\247\243/code/spring_aop_study/src/main/java/com/mashibing/myinter/MySubClass.java"
@@ -0,0 +1,7 @@
+package com.mashibing.myinter;
+
+public class MySubClass implements MyInterface {
+ public void show(Integer i) {
+ System.out.println("show.......");
+ }
+}
diff --git "a/javaframework/spring/06SpringAOP\347\232\204\350\257\246\347\273\206\350\256\262\350\247\243/code/spring_aop_study/src/main/java/com/mashibing/proxy/CalculatorProxy.java" "b/javaframework/spring/06SpringAOP\347\232\204\350\257\246\347\273\206\350\256\262\350\247\243/code/spring_aop_study/src/main/java/com/mashibing/proxy/CalculatorProxy.java"
new file mode 100644
index 00000000..909733f9
--- /dev/null
+++ "b/javaframework/spring/06SpringAOP\347\232\204\350\257\246\347\273\206\350\256\262\350\247\243/code/spring_aop_study/src/main/java/com/mashibing/proxy/CalculatorProxy.java"
@@ -0,0 +1,55 @@
+package com.mashibing.proxy;
+
+import com.mashibing.service.Calculator;
+import com.mashibing.util.LogUtil;
+import org.springframework.transaction.annotation.Transactional;
+import sun.rmi.runtime.Log;
+
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.Method;
+import java.lang.reflect.Proxy;
+import java.util.Arrays;
+
+/**
+ * 必须要有接口,如果没有接口,不能使用,这种方式是用jdk提供的reflect包下的类
+ * 但是在生产环境中我不能保证每个类都有实现的接口,所有有第二种方式cglib
+ *
+ * cglib在实现的时候有没有接口都无所谓
+ *
+ * 在spring中使用了两种动态代理的方式,一种是jdk提供的(刚刚完成的)另外一种就是cglib
+ */
+public class CalculatorProxy {
+
+ public static Calculator getProxy( final Calculator calculator){
+
+ //获取被代理对象的类加载器
+ ClassLoader loader = calculator.getClass().getClassLoader();
+ //被代理对象的所有接口
+ Class>[] interfaces = calculator.getClass().getInterfaces();
+ //用来执行被代理类需要执行的方法
+ InvocationHandler handler = new InvocationHandler() {
+ public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
+ Object result = null;
+ try{
+// System.out.println(method.getName()+"方法开始执行,参数列表是:"+ Arrays.asList(args));
+// LogUtil.start(method,args);
+ //开始调用被代理类的方法
+ //start
+ result = method.invoke(calculator,args);
+ //end
+// System.out.println(method.getName()+"方法执行完成,结果是:"+result);
+// LogUtil.stop(method,result);
+ }catch (Exception e){
+// System.out.println(method.getName()+"方法抛出异常:"+e.getMessage());
+// LogUtil.logException(method,e);
+ }finally {
+// System.out.println(method.getName()+"方法执行结束。。。。。over");
+// LogUtil.logFinally(method);
+ }
+ return result;
+ }
+ };
+ Object o = Proxy.newProxyInstance(loader, interfaces, handler);
+ return (Calculator) o;
+ }
+}
diff --git "a/javaframework/spring/06SpringAOP\347\232\204\350\257\246\347\273\206\350\256\262\350\247\243/code/spring_aop_study/src/main/java/com/mashibing/proxy/DynamicProxy.java" "b/javaframework/spring/06SpringAOP\347\232\204\350\257\246\347\273\206\350\256\262\350\247\243/code/spring_aop_study/src/main/java/com/mashibing/proxy/DynamicProxy.java"
new file mode 100644
index 00000000..9c4ad1a5
--- /dev/null
+++ "b/javaframework/spring/06SpringAOP\347\232\204\350\257\246\347\273\206\350\256\262\350\247\243/code/spring_aop_study/src/main/java/com/mashibing/proxy/DynamicProxy.java"
@@ -0,0 +1,10 @@
+package com.mashibing.proxy;
+
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.Method;
+
+public class DynamicProxy implements InvocationHandler {
+ public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
+ return null;
+ }
+}
diff --git "a/javaframework/spring/06SpringAOP\347\232\204\350\257\246\347\273\206\350\256\262\350\247\243/code/spring_aop_study/src/main/java/com/mashibing/service/Calculator.java" "b/javaframework/spring/06SpringAOP\347\232\204\350\257\246\347\273\206\350\256\262\350\247\243/code/spring_aop_study/src/main/java/com/mashibing/service/Calculator.java"
new file mode 100644
index 00000000..2242eed4
--- /dev/null
+++ "b/javaframework/spring/06SpringAOP\347\232\204\350\257\246\347\273\206\350\256\262\350\247\243/code/spring_aop_study/src/main/java/com/mashibing/service/Calculator.java"
@@ -0,0 +1,12 @@
+package com.mashibing.service;
+
+import org.springframework.stereotype.Service;
+
+
+public interface Calculator {
+
+ public Integer add(Integer i,Integer j) throws NoSuchMethodException;
+ public Integer sub(Integer i,Integer j) throws NoSuchMethodException;
+ public Integer mul(Integer i,Integer j) throws NoSuchMethodException;
+ public Integer div(Integer i,Integer j) throws NoSuchMethodException;
+}
diff --git "a/javaframework/spring/06SpringAOP\347\232\204\350\257\246\347\273\206\350\256\262\350\247\243/code/spring_aop_study/src/main/java/com/mashibing/service/MyCalculator.java" "b/javaframework/spring/06SpringAOP\347\232\204\350\257\246\347\273\206\350\256\262\350\247\243/code/spring_aop_study/src/main/java/com/mashibing/service/MyCalculator.java"
new file mode 100644
index 00000000..0f10939b
--- /dev/null
+++ "b/javaframework/spring/06SpringAOP\347\232\204\350\257\246\347\273\206\350\256\262\350\247\243/code/spring_aop_study/src/main/java/com/mashibing/service/MyCalculator.java"
@@ -0,0 +1,43 @@
+package com.mashibing.service;
+
+import org.springframework.stereotype.Service;
+
+@Service
+public class MyCalculator /*implements Calculator */{
+ public Integer add(Integer i, Integer j) throws NoSuchMethodException {
+// Method add = MyCalculator.class.getMethod("add", Integer.class, Integer.class);
+// LogUtil.start(add,i,j);
+ Integer result = i+j;
+// LogUtil.stop(add,result);
+ return result;
+ }
+
+ public Integer sub(Integer i, Integer j) throws NoSuchMethodException {
+// Method sub = MyCalculator.class.getMethod("sub", Integer.class, Integer.class);
+// LogUtil.start(sub,i,j);
+ Integer result = i-j;
+// LogUtil.stop(sub,result);
+ return result;
+ }
+
+ public Integer mul(Integer i, Integer j) throws NoSuchMethodException {
+// Method mul = MyCalculator.class.getMethod("mul", Integer.class, Integer.class);
+// LogUtil.start(mul,i,j);
+ Integer result = i*j;
+// LogUtil.stop(mul,result);
+ return result;
+ }
+
+ public Integer div(Integer i, Integer j) throws NoSuchMethodException {
+// Method div = MyCalculator.class.getMethod("div", Integer.class, Integer.class);
+// LogUtil.start(div,i,j);
+ Integer result = i/j;
+// LogUtil.stop(div,result);
+ return result;
+ }
+
+ public Integer show(Integer i){
+ System.out.println("show .....");
+ return i;
+ }
+}
diff --git "a/javaframework/spring/06SpringAOP\347\232\204\350\257\246\347\273\206\350\256\262\350\247\243/code/spring_aop_study/src/main/java/com/mashibing/service/SecondCalculator.java" "b/javaframework/spring/06SpringAOP\347\232\204\350\257\246\347\273\206\350\256\262\350\247\243/code/spring_aop_study/src/main/java/com/mashibing/service/SecondCalculator.java"
new file mode 100644
index 00000000..b0d3e7c8
--- /dev/null
+++ "b/javaframework/spring/06SpringAOP\347\232\204\350\257\246\347\273\206\350\256\262\350\247\243/code/spring_aop_study/src/main/java/com/mashibing/service/SecondCalculator.java"
@@ -0,0 +1,19 @@
+package com.mashibing.service;
+
+public class SecondCalculator implements Calculator {
+ public Integer add(Integer i, Integer j) throws NoSuchMethodException {
+ return null;
+ }
+
+ public Integer sub(Integer i, Integer j) throws NoSuchMethodException {
+ return null;
+ }
+
+ public Integer mul(Integer i, Integer j) throws NoSuchMethodException {
+ return null;
+ }
+
+ public Integer div(Integer i, Integer j) throws NoSuchMethodException {
+ return null;
+ }
+}
diff --git "a/javaframework/spring/06SpringAOP\347\232\204\350\257\246\347\273\206\350\256\262\350\247\243/code/spring_aop_study/src/main/java/com/mashibing/service/impl/MyCalculator2.java" "b/javaframework/spring/06SpringAOP\347\232\204\350\257\246\347\273\206\350\256\262\350\247\243/code/spring_aop_study/src/main/java/com/mashibing/service/impl/MyCalculator2.java"
new file mode 100644
index 00000000..11bce39c
--- /dev/null
+++ "b/javaframework/spring/06SpringAOP\347\232\204\350\257\246\347\273\206\350\256\262\350\247\243/code/spring_aop_study/src/main/java/com/mashibing/service/impl/MyCalculator2.java"
@@ -0,0 +1,43 @@
+package com.mashibing.service.impl;
+
+import org.springframework.stereotype.Service;
+
+@Service
+public class MyCalculator2 /*implements Calculator */{
+ public Integer add(Integer i, Integer j) throws NoSuchMethodException {
+// Method add = MyCalculator.class.getMethod("add", Integer.class, Integer.class);
+// LogUtil.start(add,i,j);
+ Integer result = i+j;
+// LogUtil.stop(add,result);
+ return result;
+ }
+
+ public Integer sub(Integer i, Integer j) throws NoSuchMethodException {
+// Method sub = MyCalculator.class.getMethod("sub", Integer.class, Integer.class);
+// LogUtil.start(sub,i,j);
+ Integer result = i-j;
+// LogUtil.stop(sub,result);
+ return result;
+ }
+
+ public Integer mul(Integer i, Integer j) throws NoSuchMethodException {
+// Method mul = MyCalculator.class.getMethod("mul", Integer.class, Integer.class);
+// LogUtil.start(mul,i,j);
+ Integer result = i*j;
+// LogUtil.stop(mul,result);
+ return result;
+ }
+
+ public Integer div(Integer i, Integer j) throws NoSuchMethodException {
+// Method div = MyCalculator.class.getMethod("div", Integer.class, Integer.class);
+// LogUtil.start(div,i,j);
+ Integer result = i/j;
+// LogUtil.stop(div,result);
+ return result;
+ }
+
+ public Integer show(Integer i,Double j){
+ System.out.println("show .....");
+ return i;
+ }
+}
diff --git "a/javaframework/spring/06SpringAOP\347\232\204\350\257\246\347\273\206\350\256\262\350\247\243/code/spring_aop_study/src/main/java/com/mashibing/util/LogUtil.java" "b/javaframework/spring/06SpringAOP\347\232\204\350\257\246\347\273\206\350\256\262\350\247\243/code/spring_aop_study/src/main/java/com/mashibing/util/LogUtil.java"
new file mode 100644
index 00000000..e1273d78
--- /dev/null
+++ "b/javaframework/spring/06SpringAOP\347\232\204\350\257\246\347\273\206\350\256\262\350\247\243/code/spring_aop_study/src/main/java/com/mashibing/util/LogUtil.java"
@@ -0,0 +1,155 @@
+package com.mashibing.util;
+
+import org.aspectj.lang.JoinPoint;
+import org.aspectj.lang.ProceedingJoinPoint;
+import org.aspectj.lang.Signature;
+import org.aspectj.lang.annotation.*;
+import org.springframework.core.annotation.Order;
+import org.springframework.stereotype.Component;
+
+import java.lang.reflect.Method;
+import java.util.Arrays;
+
+@Aspect
+@Component
+@Order(200)
+public class LogUtil {
+ /**
+ * 通知注解有以下几种类型:
+ *
+ * @Before:前置通知,在方法执行之前完成
+ * @After:后置通知,在方法执行完成之后执行
+ * @AfterReturing:返回通知:在返回结果之后运行
+ * @AfterThrowing:异常通知:出现异常的时候使用
+ * @Around:环绕通知
+ *
+ * 在方法的参数列表中不要随便添加参数值,会有异常信息
+ *
+ * 切入点表达式:
+ * 最精确的匹配方式:
+ * public Integer com.mashibing.service.MyCalculator.add(Integer,Integer)
+ * 在实际的生产环境中,更多的时候使用通配符的方式
+ * *:
+ * 1、可以用来匹配一个或者多个字符
+ * execution( public Integer com.mashibing.service.MyCalculator.*(Integer,Integer)
+ * 2、匹配任意类型的参数,只能匹配一个
+ * execution( public Integer com.mashibing.service.M*Calculator.*(Integer,*))
+ * 3、*在进行匹配的时候只能匹配一层路径,不能匹配多层
+ * 4、*不能够匹配访问修饰符,如果不确定访问修饰符是什么,可以直接省略不写
+ * execution( Integer com.mashibing.service.MyCalculator.*(Integer,*))
+ * 5、返回值可以使用*来代替
+ * ..:
+ * 1、可以匹配多个参数,任意类型
+ * execution(* com.mashibing.service.MyCalculator.*(..))
+ * 2、可以匹配多层路径
+ * execution(* com.mashibing..MyCalculator*.*(..))
+ * 最偷懒的方式:
+ * execution(* *(..))
+ * execution(* com..*(..))
+ * 如果表达式是以*开头,那么可以代替所有
+ *
+ * 在使用表达式的时候还支持逻辑运算
+ * &&:多个条件必须同时满足
+ * execution(public Integer com.mashibing.service.MyCalculator.*(..)) && execution(* *(..))
+ * ||:多个条件只要满足其中一个即可
+ * execution(public Integer com.mashibing.service.MyCalculator.*(..)) || execution(* *(..))
+ * !:取反,除了这种情况的其他都满足
+ * !execution(public Integer com.mashibing.service.MyCalculator.add(Integer,Integer))
+ *
+ * 使用通配符的时候不是越简洁越好,更多的是要选择符合要求或者符合规则的匹配方式,
+ * 此时就要求在定义标识符的时候必须要遵循项目规范
+ *
+ * 通知的正常执行顺序:
+ * 如果正常执行:@Before--》@After----》@AfterReturning
+ * 如果异常结束:@Before--》@After----》@AfterThrowing
+ *
+ *
+ * 如果想要在方法中获取对应的参数或者方法名称等信息的时候,必须要使用JoinPoint对象,并且此参数必须是第一个
+ * getSignature()
+ * getArgs()
+ * 如果方法中有返回值,那么必须要在注解中添加 Returing="result" ,这个result必须要和参数列表中的参数名称保持一致
+ * 如果需要添加异常信息,那么在注解中要添加Throwing="e" 这个e的名称必须跟参数列表中的名称保持一致
+ * 如果想要添加其他参数,必须要添加args(参数列表),ArgNames(参数列表)
+ * @Before(value = "execution(public Integer com.mashibing.service.MyCalculator.*(Integer,Integer)) && args(joinPoint,k)",argNames = "joinPoint,k")
+ *
+ *
+ * 通知方法在定义的时候有没有什么特殊的要求?
+ * 通知方法在定义的时候对于访问修饰符、返回值类型都没有明确的要求,
+ * 但是要注意,参数不能随便添加
+ *
+ * 如果有多个匹配的表达式相同,能否做抽象?
+ * 定义一个没有返回值的空方法,给该方法添加@PointCut注解,后续在使用的时候可以直接调用方法名称
+ * 此处的方法只是起一个声明的作用,能够供内部的其他通知方法进行调用
+ *
+ *
+ * 环绕通知:
+ * 环绕通知在执行的时候是优先于普通通知的
+ * 如果是正常结束,那么执行顺序是:
+ * 环绕前置通知--》@Before--》环绕后置通知--》环绕返回通知--》@After--》@AfterReturning
+ * 如果是异常结束,那么执行顺序是:
+ * 环绕前置通知--》@Before--》环绕异常通知--》环绕返回通知--》@After--》@AfterReturing
+ * 如果出现异常的时候,在环绕通知中解决了,那么普通通知是接受不到的,如果想让普通通知接收到需要进行抛出 throw throwable
+ * 执行顺序改为:
+ * 环绕前置通知--》@Before--》环绕异常通知--》环绕返回通知--》@After--》@AfterThrowing
+ *
+ * 当应用程序中包含多个切面类的时候,具体的执行顺序是什么样?
+ * 按照切面类的名称的首字母进行排序操作,按照字典序
+ * 如果需要认为的规定顺序,可以在切面类上添加@Order注解同时可以添加具体的值
+ * 值越小,越优先
+ */
+
+ @Pointcut("execution(public Integer com.mashibing.service.MyCalculator.*(Integer,Integer))")
+ public void myPointCut(){}
+
+ @Pointcut("execution(* *(..))")
+ public void myPointCut1(){}
+
+ @Before(value = "myPointCut()")
+ private int start(JoinPoint joinPoint){
+ //获取方法签名
+ Signature signature = joinPoint.getSignature();
+ //获取参数信息
+ Object[] args = joinPoint.getArgs();
+ System.out.println("log---"+signature.getName()+"方法开始执行:参数是"+Arrays.asList(args));
+ return 100;
+ }
+
+ @AfterReturning(value = "myPointCut()",returning = "result")
+ public static void stop(JoinPoint joinPoint,Object result){
+ Signature signature = joinPoint.getSignature();
+ System.out.println("log---"+signature.getName()+"方法执行结束,结果是:"+result);
+ }
+
+ @AfterThrowing(value = "myPointCut()",throwing = "e")
+ public static void logException(JoinPoint joinPoint,Exception e){
+ Signature signature = joinPoint.getSignature();
+ System.out.println("log---"+signature.getName()+"方法抛出异常:"+e.getMessage());
+ }
+
+ @After("myPointCut()")
+ public static void logFinally(JoinPoint joinPoint){
+ Signature signature = joinPoint.getSignature();
+ System.out.println("log---"+signature.getName()+"方法执行结束。。。。。over");
+
+ }
+
+ @Around("myPointCut()")
+ public Object around(ProceedingJoinPoint pjp) throws Throwable {
+ Signature signature = pjp.getSignature();
+ Object[] args = pjp.getArgs();
+ Object result = null;
+ try {
+ System.out.println("log---环绕通知start:"+signature.getName()+"方法开始执行,参数为:"+Arrays.asList(args));
+ //通过反射的方式调用目标的方法,相当于执行method.invoke(),可以自己修改结果值
+ result = pjp.proceed(args);
+// result=100;
+ System.out.println("log---环绕通知stop"+signature.getName()+"方法执行结束");
+ } catch (Throwable throwable) {
+ System.out.println("log---环绕异常通知:"+signature.getName()+"出现异常");
+ throw throwable;
+ }finally {
+ System.out.println("log---环绕返回通知:"+signature.getName()+"方法返回结果是:"+result);
+ }
+ return result;
+ }
+}
diff --git "a/javaframework/spring/06SpringAOP\347\232\204\350\257\246\347\273\206\350\256\262\350\247\243/code/spring_aop_study/src/main/java/com/mashibing/util/SecurityUtil.java" "b/javaframework/spring/06SpringAOP\347\232\204\350\257\246\347\273\206\350\256\262\350\247\243/code/spring_aop_study/src/main/java/com/mashibing/util/SecurityUtil.java"
new file mode 100644
index 00000000..7cf93004
--- /dev/null
+++ "b/javaframework/spring/06SpringAOP\347\232\204\350\257\246\347\273\206\350\256\262\350\247\243/code/spring_aop_study/src/main/java/com/mashibing/util/SecurityUtil.java"
@@ -0,0 +1,68 @@
+package com.mashibing.util;
+
+import org.aspectj.lang.JoinPoint;
+import org.aspectj.lang.ProceedingJoinPoint;
+import org.aspectj.lang.Signature;
+import org.aspectj.lang.annotation.*;
+import org.springframework.core.annotation.Order;
+import org.springframework.stereotype.Component;
+
+import java.util.Arrays;
+
+@Aspect
+@Component
+@Order(100)
+public class SecurityUtil {
+
+ @Pointcut("execution(public Integer com.mashibing.service.MyCalculator.*(Integer,Integer))")
+ public void myPointCut(){}
+
+
+
+ @Before(value = "myPointCut()")
+ private int start(JoinPoint joinPoint){
+ Signature signature = joinPoint.getSignature();
+ Object[] args = joinPoint.getArgs();
+ System.out.println("Security---"+signature.getName()+"方法开始执行:参数是"+Arrays.asList(args));
+ return 100;
+ }
+
+ @AfterReturning(value = "myPointCut()",returning = "result")
+ public static void stop(JoinPoint joinPoint,Object result){
+ Signature signature = joinPoint.getSignature();
+ System.out.println("Security---"+signature.getName()+"方法执行结束,结果是:"+result);
+ }
+
+ @AfterThrowing(value = "myPointCut()",throwing = "e")
+ public static void logException(JoinPoint joinPoint,Exception e){
+ Signature signature = joinPoint.getSignature();
+ System.out.println("Security---"+signature.getName()+"方法抛出异常:"+e.getMessage());
+ }
+
+ @After("myPointCut()")
+ public static void logFinally(JoinPoint joinPoint){
+ Signature signature = joinPoint.getSignature();
+ System.out.println("Security---"+signature.getName()+"方法执行结束。。。。。over");
+
+ }
+
+ @Around("myPointCut()")
+ public Object around(ProceedingJoinPoint pjp) throws Throwable {
+ Signature signature = pjp.getSignature();
+ Object[] args = pjp.getArgs();
+ Object result = null;
+ try {
+ System.out.println("Security---环绕通知start:"+signature.getName()+"方法开始执行,参数为:"+ Arrays.asList(args));
+ //通过反射的方式调用目标的方法,相当于执行method.invoke(),可以自己修改结果值
+ result = pjp.proceed(args);
+// result=100;
+ System.out.println("Security---环绕通知stop"+signature.getName()+"方法执行结束");
+ } catch (Throwable throwable) {
+ System.out.println("Security---环绕异常通知:"+signature.getName()+"出现异常");
+ throw throwable;
+ }finally {
+ System.out.println("Security---环绕返回通知:"+signature.getName()+"方法返回结果是:"+result);
+ }
+ return result;
+ }
+}
diff --git "a/javaframework/spring/06SpringAOP\347\232\204\350\257\246\347\273\206\350\256\262\350\247\243/code/spring_aop_study/src/main/resources/applicationContext.xml" "b/javaframework/spring/06SpringAOP\347\232\204\350\257\246\347\273\206\350\256\262\350\247\243/code/spring_aop_study/src/main/resources/applicationContext.xml"
new file mode 100644
index 00000000..029eea1a
--- /dev/null
+++ "b/javaframework/spring/06SpringAOP\347\232\204\350\257\246\347\273\206\350\256\262\350\247\243/code/spring_aop_study/src/main/resources/applicationContext.xml"
@@ -0,0 +1,17 @@
+
+
+
+
+
+
+
\ No newline at end of file
diff --git "a/javaframework/spring/06SpringAOP\347\232\204\350\257\246\347\273\206\350\256\262\350\247\243/code/spring_aop_study/src/test/java/MyTest.java" "b/javaframework/spring/06SpringAOP\347\232\204\350\257\246\347\273\206\350\256\262\350\247\243/code/spring_aop_study/src/test/java/MyTest.java"
new file mode 100644
index 00000000..85b22601
--- /dev/null
+++ "b/javaframework/spring/06SpringAOP\347\232\204\350\257\246\347\273\206\350\256\262\350\247\243/code/spring_aop_study/src/test/java/MyTest.java"
@@ -0,0 +1,45 @@
+import com.mashibing.myinter.MyInterface;
+import com.mashibing.myinter.MySubClass;
+import com.mashibing.proxy.CalculatorProxy;
+import com.mashibing.service.Calculator;
+import com.mashibing.service.MyCalculator;
+import com.mashibing.service.SecondCalculator;
+import com.mashibing.service.impl.MyCalculator2;
+import org.junit.Test;
+import org.springframework.context.support.ClassPathXmlApplicationContext;
+
+public class MyTest {
+ ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
+
+ @Test
+ public void test01() throws NoSuchMethodException {
+
+// MyCalculator myCalculator = new MyCalculator();
+// System.out.println(myCalculator.add(1, 2));
+// System.out.println(myCalculator.div(1, 1));
+
+// Calculator calculator = (Calculator) CalculatorProxy.getProxy(new MyCalculator());
+// System.out.println(calculator.add(1, 1));
+// calculator.sub(1,1);
+// calculator.mul(1,1);
+// calculator.div(1,0);
+// System.out.println(calculator.getClass());
+// System.out.println("------------------");
+// MyInterface proxy = (MyInterface) CalculatorProxy.getProxy(new MySubClass());
+// proxy.show(100);
+ }
+
+ @Test
+ public void test02() throws NoSuchMethodException {
+ MyCalculator calculator = context.getBean(MyCalculator.class);
+ calculator.div(1, 1);
+ System.out.println(calculator.getClass());
+
+ }
+
+ @Test
+ public void test03() throws NoSuchMethodException {
+ MyCalculator2 myCalculator2 = context.getBean("myCalculator2", MyCalculator2.class);
+ myCalculator2.add(1,1);
+ }
+}
diff --git "a/javaframework/spring/06SpringAOP\347\232\204\350\257\246\347\273\206\350\256\262\350\247\243/code/spring_aop_study/target/classes/META-INF/spring_aop_study.kotlin_module" "b/javaframework/spring/06SpringAOP\347\232\204\350\257\246\347\273\206\350\256\262\350\247\243/code/spring_aop_study/target/classes/META-INF/spring_aop_study.kotlin_module"
new file mode 100644
index 00000000..8fb60192
Binary files /dev/null and "b/javaframework/spring/06SpringAOP\347\232\204\350\257\246\347\273\206\350\256\262\350\247\243/code/spring_aop_study/target/classes/META-INF/spring_aop_study.kotlin_module" differ
diff --git "a/javaframework/spring/06SpringAOP\347\232\204\350\257\246\347\273\206\350\256\262\350\247\243/code/spring_aop_study/target/classes/applicationContext.xml" "b/javaframework/spring/06SpringAOP\347\232\204\350\257\246\347\273\206\350\256\262\350\247\243/code/spring_aop_study/target/classes/applicationContext.xml"
new file mode 100644
index 00000000..029eea1a
--- /dev/null
+++ "b/javaframework/spring/06SpringAOP\347\232\204\350\257\246\347\273\206\350\256\262\350\247\243/code/spring_aop_study/target/classes/applicationContext.xml"
@@ -0,0 +1,17 @@
+
+
+
+
+
+
+
\ No newline at end of file
diff --git "a/javaframework/spring/06SpringAOP\347\232\204\350\257\246\347\273\206\350\256\262\350\247\243/code/spring_aop_study/target/classes/com/mashibing/myinter/MyInterface.class" "b/javaframework/spring/06SpringAOP\347\232\204\350\257\246\347\273\206\350\256\262\350\247\243/code/spring_aop_study/target/classes/com/mashibing/myinter/MyInterface.class"
new file mode 100644
index 00000000..0dd65883
Binary files /dev/null and "b/javaframework/spring/06SpringAOP\347\232\204\350\257\246\347\273\206\350\256\262\350\247\243/code/spring_aop_study/target/classes/com/mashibing/myinter/MyInterface.class" differ
diff --git "a/javaframework/spring/06SpringAOP\347\232\204\350\257\246\347\273\206\350\256\262\350\247\243/code/spring_aop_study/target/classes/com/mashibing/myinter/MySubClass.class" "b/javaframework/spring/06SpringAOP\347\232\204\350\257\246\347\273\206\350\256\262\350\247\243/code/spring_aop_study/target/classes/com/mashibing/myinter/MySubClass.class"
new file mode 100644
index 00000000..856113b8
Binary files /dev/null and "b/javaframework/spring/06SpringAOP\347\232\204\350\257\246\347\273\206\350\256\262\350\247\243/code/spring_aop_study/target/classes/com/mashibing/myinter/MySubClass.class" differ
diff --git "a/javaframework/spring/06SpringAOP\347\232\204\350\257\246\347\273\206\350\256\262\350\247\243/code/spring_aop_study/target/classes/com/mashibing/proxy/CalculatorProxy$1.class" "b/javaframework/spring/06SpringAOP\347\232\204\350\257\246\347\273\206\350\256\262\350\247\243/code/spring_aop_study/target/classes/com/mashibing/proxy/CalculatorProxy$1.class"
new file mode 100644
index 00000000..ad296ddc
Binary files /dev/null and "b/javaframework/spring/06SpringAOP\347\232\204\350\257\246\347\273\206\350\256\262\350\247\243/code/spring_aop_study/target/classes/com/mashibing/proxy/CalculatorProxy$1.class" differ
diff --git "a/javaframework/spring/06SpringAOP\347\232\204\350\257\246\347\273\206\350\256\262\350\247\243/code/spring_aop_study/target/classes/com/mashibing/proxy/CalculatorProxy.class" "b/javaframework/spring/06SpringAOP\347\232\204\350\257\246\347\273\206\350\256\262\350\247\243/code/spring_aop_study/target/classes/com/mashibing/proxy/CalculatorProxy.class"
new file mode 100644
index 00000000..88feeebb
Binary files /dev/null and "b/javaframework/spring/06SpringAOP\347\232\204\350\257\246\347\273\206\350\256\262\350\247\243/code/spring_aop_study/target/classes/com/mashibing/proxy/CalculatorProxy.class" differ
diff --git "a/javaframework/spring/06SpringAOP\347\232\204\350\257\246\347\273\206\350\256\262\350\247\243/code/spring_aop_study/target/classes/com/mashibing/proxy/DynamicProxy.class" "b/javaframework/spring/06SpringAOP\347\232\204\350\257\246\347\273\206\350\256\262\350\247\243/code/spring_aop_study/target/classes/com/mashibing/proxy/DynamicProxy.class"
new file mode 100644
index 00000000..876d036d
Binary files /dev/null and "b/javaframework/spring/06SpringAOP\347\232\204\350\257\246\347\273\206\350\256\262\350\247\243/code/spring_aop_study/target/classes/com/mashibing/proxy/DynamicProxy.class" differ
diff --git "a/javaframework/spring/06SpringAOP\347\232\204\350\257\246\347\273\206\350\256\262\350\247\243/code/spring_aop_study/target/classes/com/mashibing/service/Calculator.class" "b/javaframework/spring/06SpringAOP\347\232\204\350\257\246\347\273\206\350\256\262\350\247\243/code/spring_aop_study/target/classes/com/mashibing/service/Calculator.class"
new file mode 100644
index 00000000..59fe5455
Binary files /dev/null and "b/javaframework/spring/06SpringAOP\347\232\204\350\257\246\347\273\206\350\256\262\350\247\243/code/spring_aop_study/target/classes/com/mashibing/service/Calculator.class" differ
diff --git "a/javaframework/spring/06SpringAOP\347\232\204\350\257\246\347\273\206\350\256\262\350\247\243/code/spring_aop_study/target/classes/com/mashibing/service/MyCalculator.class" "b/javaframework/spring/06SpringAOP\347\232\204\350\257\246\347\273\206\350\256\262\350\247\243/code/spring_aop_study/target/classes/com/mashibing/service/MyCalculator.class"
new file mode 100644
index 00000000..99ed1e20
Binary files /dev/null and "b/javaframework/spring/06SpringAOP\347\232\204\350\257\246\347\273\206\350\256\262\350\247\243/code/spring_aop_study/target/classes/com/mashibing/service/MyCalculator.class" differ
diff --git "a/javaframework/spring/06SpringAOP\347\232\204\350\257\246\347\273\206\350\256\262\350\247\243/code/spring_aop_study/target/classes/com/mashibing/service/SecondCalculator.class" "b/javaframework/spring/06SpringAOP\347\232\204\350\257\246\347\273\206\350\256\262\350\247\243/code/spring_aop_study/target/classes/com/mashibing/service/SecondCalculator.class"
new file mode 100644
index 00000000..1459abc9
Binary files /dev/null and "b/javaframework/spring/06SpringAOP\347\232\204\350\257\246\347\273\206\350\256\262\350\247\243/code/spring_aop_study/target/classes/com/mashibing/service/SecondCalculator.class" differ
diff --git "a/javaframework/spring/06SpringAOP\347\232\204\350\257\246\347\273\206\350\256\262\350\247\243/code/spring_aop_study/target/classes/com/mashibing/service/impl/MyCalculator2.class" "b/javaframework/spring/06SpringAOP\347\232\204\350\257\246\347\273\206\350\256\262\350\247\243/code/spring_aop_study/target/classes/com/mashibing/service/impl/MyCalculator2.class"
new file mode 100644
index 00000000..a2617950
Binary files /dev/null and "b/javaframework/spring/06SpringAOP\347\232\204\350\257\246\347\273\206\350\256\262\350\247\243/code/spring_aop_study/target/classes/com/mashibing/service/impl/MyCalculator2.class" differ
diff --git "a/javaframework/spring/06SpringAOP\347\232\204\350\257\246\347\273\206\350\256\262\350\247\243/code/spring_aop_study/target/classes/com/mashibing/util/LogUtil.class" "b/javaframework/spring/06SpringAOP\347\232\204\350\257\246\347\273\206\350\256\262\350\247\243/code/spring_aop_study/target/classes/com/mashibing/util/LogUtil.class"
new file mode 100644
index 00000000..fc362cfd
Binary files /dev/null and "b/javaframework/spring/06SpringAOP\347\232\204\350\257\246\347\273\206\350\256\262\350\247\243/code/spring_aop_study/target/classes/com/mashibing/util/LogUtil.class" differ
diff --git "a/javaframework/spring/06SpringAOP\347\232\204\350\257\246\347\273\206\350\256\262\350\247\243/code/spring_aop_study/target/classes/com/mashibing/util/SecurityUtil.class" "b/javaframework/spring/06SpringAOP\347\232\204\350\257\246\347\273\206\350\256\262\350\247\243/code/spring_aop_study/target/classes/com/mashibing/util/SecurityUtil.class"
new file mode 100644
index 00000000..fda1af1a
Binary files /dev/null and "b/javaframework/spring/06SpringAOP\347\232\204\350\257\246\347\273\206\350\256\262\350\247\243/code/spring_aop_study/target/classes/com/mashibing/util/SecurityUtil.class" differ
diff --git "a/javaframework/spring/06SpringAOP\347\232\204\350\257\246\347\273\206\350\256\262\350\247\243/code/spring_aop_study/target/test-classes/MyTest.class" "b/javaframework/spring/06SpringAOP\347\232\204\350\257\246\347\273\206\350\256\262\350\247\243/code/spring_aop_study/target/test-classes/MyTest.class"
new file mode 100644
index 00000000..7445a117
Binary files /dev/null and "b/javaframework/spring/06SpringAOP\347\232\204\350\257\246\347\273\206\350\256\262\350\247\243/code/spring_aop_study/target/test-classes/MyTest.class" differ
diff --git "a/javaframework/spring/07SpringAOP\347\232\204\350\257\246\347\273\206\350\256\262\350\247\2432/05Spring AOP\347\232\204\351\253\230\347\272\247\345\272\224\347\224\250.md" "b/javaframework/spring/07SpringAOP\347\232\204\350\257\246\347\273\206\350\256\262\350\247\2432/05Spring AOP\347\232\204\351\253\230\347\272\247\345\272\224\347\224\250.md"
new file mode 100644
index 00000000..82070cfc
--- /dev/null
+++ "b/javaframework/spring/07SpringAOP\347\232\204\350\257\246\347\273\206\350\256\262\350\247\2432/05Spring AOP\347\232\204\351\253\230\347\272\247\345\272\224\347\224\250.md"
@@ -0,0 +1,1377 @@
+# 05Spring AOP的应用配置
+
+### 1、Spring JdbcTemplate
+
+ 在spring中为了更加方便的操作JDBC,在JDBC的基础之上定义了一个抽象层,此设计的目的是为不同类型的JDBC操作提供模板方法,每个模板方法都能控制整个过程,并允许覆盖过程中的特定任务,通过这种方式,可以尽可能保留灵活性,将数据库存取的工作量讲到最低。
+
+##### 1、配置并测试数据源
+
+pom.xml
+
+```xml
+
+
+ 4.0.0
+
+ com.mashibing
+ spring_demo
+ 1.0-SNAPSHOT
+
+
+
+
+ org.springframework
+ spring-context
+ 5.2.3.RELEASE
+
+
+
+
+ com.alibaba
+ druid
+ 1.1.21
+
+
+
+ mysql
+ mysql-connector-java
+ 5.1.47
+
+
+
+ cglib
+ cglib
+ 3.3.0
+
+
+
+ org.aspectj
+ aspectjweaver
+ 1.9.5
+
+
+
+ aopalliance
+ aopalliance
+ 1.0
+
+
+
+ org.springframework
+ spring-aspects
+ 5.2.3.RELEASE
+
+
+
+
+```
+
+dbconfig.properties
+
+```properties
+jdbc.username=root123
+password=123456
+url=jdbc:mysql://localhost:3306/demo
+driverClassName=com.mysql.jdbc.Driver
+```
+
+applicationContext.xml
+
+```xml
+
+
+
+
+
+
+
+
+
+
+```
+
+MyTest.java
+
+```java
+import com.alibaba.druid.pool.DruidDataSource;
+import org.springframework.context.ApplicationContext;
+import org.springframework.context.support.ClassPathXmlApplicationContext;
+import java.sql.SQLException;
+
+public class MyTest {
+ public static void main(String[] args) throws SQLException {
+ ApplicationContext context = new ClassPathXmlApplicationContext("jdbcTemplate.xml");
+ DruidDataSource dataSource = context.getBean("dataSource", DruidDataSource.class);
+ System.out.println(dataSource);
+ System.out.println(dataSource.getConnection());
+ }
+}
+```
+
+##### 2、给spring容器添加JdbcTemplate
+
+ spring容器提供了一个JdbcTemplate类,用来方便操作数据库。
+
+1、添加pom依赖
+
+pom.xml
+
+```xml
+
+
+ org.springframework
+ spring-orm
+ 5.2.3.RELEASE
+
+```
+
+jdbcTemplate.xml
+
+```xml
+
+
+
+
+
+
+
+
+
+
+
+
+
+```
+
+MyTest.java
+
+```java
+import com.alibaba.druid.pool.DruidDataSource;
+import org.springframework.context.ApplicationContext;
+import org.springframework.context.support.ClassPathXmlApplicationContext;
+import org.springframework.jdbc.core.JdbcTemplate;
+
+import java.sql.SQLException;
+
+public class MyTest {
+ public static void main(String[] args) throws SQLException {
+ ApplicationContext context = new ClassPathXmlApplicationContext("jdbcTemplate.xml");
+ JdbcTemplate jdbcTemplate = context.getBean("jdbcTemplate", JdbcTemplate.class);
+ System.out.println(jdbcTemplate);
+ }
+}
+```
+
+##### 3、插入数据
+
+MyTest.java
+
+```java
+import com.alibaba.druid.pool.DruidDataSource;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.ApplicationContext;
+import org.springframework.context.support.ClassPathXmlApplicationContext;
+import org.springframework.jdbc.core.JdbcTemplate;
+
+import java.sql.SQLException;
+
+public class MyTest {
+ public static void main(String[] args) throws SQLException {
+ ApplicationContext context = new ClassPathXmlApplicationContext("jdbcTemplate.xml");
+ JdbcTemplate jdbcTemplate = context.getBean("jdbcTemplate", JdbcTemplate.class);
+ String sql = "insert into emp(empno,ename) values(?,?)";
+ int result = jdbcTemplate.update(sql, 1111, "zhangsan");
+ System.out.println(result);
+ }
+}
+```
+
+##### 4、批量插入数据
+
+MyTest.java
+
+```java
+import com.alibaba.druid.pool.DruidDataSource;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.ApplicationContext;
+import org.springframework.context.support.ClassPathXmlApplicationContext;
+import org.springframework.jdbc.core.JdbcTemplate;
+
+import java.sql.SQLException;
+import java.util.ArrayList;
+import java.util.List;
+
+public class MyTest {
+ public static void main(String[] args) throws SQLException {
+ ApplicationContext context = new ClassPathXmlApplicationContext("jdbcTemplate.xml");
+ JdbcTemplate jdbcTemplate = context.getBean("jdbcTemplate", JdbcTemplate.class);
+ String sql = "insert into emp(empno,ename) values(?,?)";
+ List