Qing 1 жил өмнө
parent
commit
fac94eb029

+ 77 - 47
spring-demo/.idea/workspace.xml

@@ -4,26 +4,26 @@
     <option name="autoReloadType" value="SELECTIVE" />
   </component>
   <component name="ChangeListManager">
-    <list default="true" id="5aa6272e-23b4-48f4-9aaa-8caf45810aa0" name="Changes" comment="0424 spring proxy">
-      <change afterPath="$PROJECT_DIR$/src/main/java/com/sf/aop/BaseService.java" afterDir="false" />
-      <change afterPath="$PROJECT_DIR$/src/main/java/com/sf/aop/MyAfterAdvice.java" afterDir="false" />
-      <change afterPath="$PROJECT_DIR$/src/main/java/com/sf/aop/MyBeforeAdvice.java" afterDir="false" />
-      <change afterPath="$PROJECT_DIR$/src/main/java/com/sf/aop/Person.java" afterDir="false" />
-      <change afterPath="$PROJECT_DIR$/src/main/java/com/sf/aop/advisor/EatMethodMatcher.java" afterDir="false" />
-      <change afterPath="$PROJECT_DIR$/src/main/java/com/sf/aop/advisor/MyClassFilter.java" afterDir="false" />
-      <change afterPath="$PROJECT_DIR$/src/main/java/com/sf/aop/advisor/MyPointCut.java" afterDir="false" />
-      <change afterPath="$PROJECT_DIR$/src/main/java/com/sf/aop/advisor/MyPointCutAdvisor.java" afterDir="false" />
-      <change afterPath="$PROJECT_DIR$/src/main/java/com/sf/aop/advisor/WcMethodMatcher.java" afterDir="false" />
-      <change afterPath="$PROJECT_DIR$/src/main/java/com/sf/aspect/Audience.java" afterDir="false" />
-      <change afterPath="$PROJECT_DIR$/src/main/java/com/sf/aspect/CrossTalk.java" afterDir="false" />
-      <change afterPath="$PROJECT_DIR$/src/main/java/com/sf/aspect/Performance.java" afterDir="false" />
-      <change afterPath="$PROJECT_DIR$/src/main/resources/spring-advisor.xml" afterDir="false" />
-      <change afterPath="$PROJECT_DIR$/src/main/resources/spring-aop.xml" afterDir="false" />
-      <change afterPath="$PROJECT_DIR$/src/main/resources/spring-aspect.xml" afterDir="false" />
-      <change afterPath="$PROJECT_DIR$/src/test/java/com/sf/TestAop.java" afterDir="false" />
-      <change beforePath="$PROJECT_DIR$/.idea/misc.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/misc.xml" afterDir="false" />
+    <list default="true" id="5aa6272e-23b4-48f4-9aaa-8caf45810aa0" name="Changes" comment="0427 spring aop">
+      <change afterPath="$PROJECT_DIR$/src/main/java/com/sf/aspect/AopConfig.java" afterDir="false" />
+      <change afterPath="$PROJECT_DIR$/src/main/java/com/sf/aspect/AudienceAnno.java" afterDir="false" />
+      <change afterPath="$PROJECT_DIR$/src/main/java/com/sf/jdbc/DruidConfig.java" afterDir="false" />
+      <change afterPath="$PROJECT_DIR$/src/main/java/com/sf/jdbc/SpringJdbcConfig.java" afterDir="false" />
+      <change afterPath="$PROJECT_DIR$/src/main/java/com/sf/jdbc/dao/BookDao.java" afterDir="false" />
+      <change afterPath="$PROJECT_DIR$/src/main/java/com/sf/jdbc/dao/impl/BookDaoImpl.java" afterDir="false" />
+      <change afterPath="$PROJECT_DIR$/src/main/java/com/sf/jdbc/entity/Book.java" afterDir="false" />
+      <change afterPath="$PROJECT_DIR$/src/main/resources/db.properties" afterDir="false" />
+      <change afterPath="$PROJECT_DIR$/src/main/resources/spring-mysql.xml" afterDir="false" />
+      <change afterPath="$PROJECT_DIR$/src/test/java/com/sf/TestAopConfig.java" afterDir="false" />
+      <change afterPath="$PROJECT_DIR$/src/test/java/com/sf/TestDruid.java" afterDir="false" />
+      <change afterPath="$PROJECT_DIR$/src/test/java/com/sf/TestJdbc.java" afterDir="false" />
       <change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
       <change beforePath="$PROJECT_DIR$/pom.xml" beforeDir="false" afterPath="$PROJECT_DIR$/pom.xml" afterDir="false" />
+      <change beforePath="$PROJECT_DIR$/src/main/java/com/sf/aspect/Audience.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/com/sf/aspect/Audience.java" afterDir="false" />
+      <change beforePath="$PROJECT_DIR$/src/main/java/com/sf/aspect/CrossTalk.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/com/sf/aspect/CrossTalk.java" afterDir="false" />
+      <change beforePath="$PROJECT_DIR$/src/main/java/com/sf/aspect/Performance.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/com/sf/aspect/Performance.java" afterDir="false" />
+      <change beforePath="$PROJECT_DIR$/src/main/resources/spring-aspect.xml" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/resources/spring-aspect.xml" afterDir="false" />
+      <change beforePath="$PROJECT_DIR$/src/test/java/com/sf/TestAop.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/test/java/com/sf/TestAop.java" afterDir="false" />
     </list>
     <option name="SHOW_DIALOG" value="false" />
     <option name="HIGHLIGHT_CONFLICTS" value="true" />
@@ -41,14 +41,20 @@
         <option value="Spring File" />
         <option value="AnnotationType" />
         <option value="Interface" />
-        <option value="Class" />
+        <option value="Properties File" />
         <option value="Spring Xml File" />
+        <option value="Kotlin Class" />
+        <option value="Class" />
       </list>
     </option>
   </component>
   <component name="Git.Settings">
     <option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$/.." />
   </component>
+  <component name="KubernetesApiPersistence"><![CDATA[{}]]></component>
+  <component name="KubernetesApiProvider"><![CDATA[{
+  "isMigrated": true
+}]]></component>
   <component name="ProjectColorInfo">{
   &quot;associatedIndex&quot;: 1
 }</component>
@@ -94,9 +100,14 @@
     "JUnit.TestAnno.testAnno.executor": "Run",
     "JUnit.TestAop.test.executor": "Run",
     "JUnit.TestAop.testAdvisor.executor": "Run",
+    "JUnit.TestAop.testAop.executor": "Run",
+    "JUnit.TestAop.testAspect.executor": "Run",
+    "JUnit.TestAopConfig.test.executor": "Run",
     "JUnit.TestAuto.test.executor": "Run",
     "JUnit.TestConfig.test.executor": "Run",
+    "JUnit.TestDruid.test.executor": "Run",
     "JUnit.TestFactory.test.executor": "Run",
+    "JUnit.TestJdbc.test.executor": "Run",
     "JUnit.TestSingleton.test.executor": "Run",
     "JUnit.TestSingleton.testLife.executor": "Run",
     "JUnit.TestUser.executor": "Run",
@@ -126,51 +137,61 @@
       <recent name="$PROJECT_DIR$/src/main/resources" />
     </key>
     <key name="CopyClassDialog.RECENTS_KEY">
+      <recent name="com.sf.aspect" />
       <recent name="com.sf.proxy.cglib" />
       <recent name="com.sf.anno" />
     </key>
   </component>
-  <component name="RunManager" selected="JUnit.TestAop.testAdvisor">
-    <configuration name="JdkDemo (2)" type="Application" factoryName="Application" temporary="true" nameIsGenerated="true">
-      <option name="MAIN_CLASS_NAME" value="com.sf.proxy.jdk.JdkDemo" />
+  <component name="RunManager" selected="JUnit.TestJdbc.test">
+    <configuration name="TestAopConfig.test" type="JUnit" factoryName="JUnit" temporary="true" nameIsGenerated="true">
       <module name="spring-demo" />
       <extension name="coverage">
         <pattern>
-          <option name="PATTERN" value="com.sf.proxy.jdk.*" />
+          <option name="PATTERN" value="com.sf.*" />
           <option name="ENABLED" value="true" />
         </pattern>
       </extension>
+      <option name="PACKAGE_NAME" value="com.sf" />
+      <option name="MAIN_CLASS_NAME" value="com.sf.TestAopConfig" />
+      <option name="METHOD_NAME" value="test" />
+      <option name="TEST_OBJECT" value="method" />
       <method v="2">
         <option name="Make" enabled="true" />
       </method>
     </configuration>
-    <configuration name="JdkDemo (3)" type="Application" factoryName="Application" temporary="true" nameIsGenerated="true">
-      <option name="MAIN_CLASS_NAME" value="com.sf.proxy.jdk.JdkDemo" />
+    <configuration name="TestAop.testAop" type="JUnit" factoryName="JUnit" temporary="true" nameIsGenerated="true">
       <module name="spring-demo" />
       <extension name="coverage">
         <pattern>
-          <option name="PATTERN" value="com.sf.proxy.jdk.*" />
+          <option name="PATTERN" value="com.sf.*" />
           <option name="ENABLED" value="true" />
         </pattern>
       </extension>
+      <option name="PACKAGE_NAME" value="com.sf" />
+      <option name="MAIN_CLASS_NAME" value="com.sf.TestAop" />
+      <option name="METHOD_NAME" value="testAop" />
+      <option name="TEST_OBJECT" value="method" />
       <method v="2">
         <option name="Make" enabled="true" />
       </method>
     </configuration>
-    <configuration name="JdkDemo" type="Application" factoryName="Application" temporary="true" nameIsGenerated="true">
-      <option name="MAIN_CLASS_NAME" value="com.sf.proxy.jdk.JdkDemo" />
+    <configuration name="TestAop.testAspect" type="JUnit" factoryName="JUnit" temporary="true" nameIsGenerated="true">
       <module name="spring-demo" />
       <extension name="coverage">
         <pattern>
-          <option name="PATTERN" value="com.sf.proxy.jdk.*" />
+          <option name="PATTERN" value="com.sf.*" />
           <option name="ENABLED" value="true" />
         </pattern>
       </extension>
+      <option name="PACKAGE_NAME" value="com.sf" />
+      <option name="MAIN_CLASS_NAME" value="com.sf.TestAop" />
+      <option name="METHOD_NAME" value="testAspect" />
+      <option name="TEST_OBJECT" value="method" />
       <method v="2">
         <option name="Make" enabled="true" />
       </method>
     </configuration>
-    <configuration name="TestAop.test" type="JUnit" factoryName="JUnit" temporary="true" nameIsGenerated="true">
+    <configuration name="TestDruid.test" type="JUnit" factoryName="JUnit" temporary="true" nameIsGenerated="true">
       <module name="spring-demo" />
       <extension name="coverage">
         <pattern>
@@ -179,14 +200,14 @@
         </pattern>
       </extension>
       <option name="PACKAGE_NAME" value="com.sf" />
-      <option name="MAIN_CLASS_NAME" value="com.sf.TestAop" />
+      <option name="MAIN_CLASS_NAME" value="com.sf.TestDruid" />
       <option name="METHOD_NAME" value="test" />
       <option name="TEST_OBJECT" value="method" />
       <method v="2">
         <option name="Make" enabled="true" />
       </method>
     </configuration>
-    <configuration name="TestAop.testAdvisor" type="JUnit" factoryName="JUnit" temporary="true" nameIsGenerated="true">
+    <configuration name="TestJdbc.test" type="JUnit" factoryName="JUnit" temporary="true" nameIsGenerated="true">
       <module name="spring-demo" />
       <extension name="coverage">
         <pattern>
@@ -195,27 +216,27 @@
         </pattern>
       </extension>
       <option name="PACKAGE_NAME" value="com.sf" />
-      <option name="MAIN_CLASS_NAME" value="com.sf.TestAop" />
-      <option name="METHOD_NAME" value="testAdvisor" />
+      <option name="MAIN_CLASS_NAME" value="com.sf.TestJdbc" />
+      <option name="METHOD_NAME" value="test" />
       <option name="TEST_OBJECT" value="method" />
       <method v="2">
         <option name="Make" enabled="true" />
       </method>
     </configuration>
     <list>
-      <item itemvalue="Application.JdkDemo (2)" />
-      <item itemvalue="Application.JdkDemo (3)" />
-      <item itemvalue="Application.JdkDemo" />
-      <item itemvalue="JUnit.TestAop.test" />
-      <item itemvalue="JUnit.TestAop.testAdvisor" />
+      <item itemvalue="JUnit.TestAop.testAop" />
+      <item itemvalue="JUnit.TestAop.testAspect" />
+      <item itemvalue="JUnit.TestAopConfig.test" />
+      <item itemvalue="JUnit.TestDruid.test" />
+      <item itemvalue="JUnit.TestJdbc.test" />
     </list>
     <recent_temporary>
       <list>
-        <item itemvalue="JUnit.TestAop.testAdvisor" />
-        <item itemvalue="JUnit.TestAop.test" />
-        <item itemvalue="Application.JdkDemo" />
-        <item itemvalue="Application.JdkDemo (3)" />
-        <item itemvalue="Application.JdkDemo (2)" />
+        <item itemvalue="JUnit.TestJdbc.test" />
+        <item itemvalue="JUnit.TestDruid.test" />
+        <item itemvalue="JUnit.TestAopConfig.test" />
+        <item itemvalue="JUnit.TestAop.testAop" />
+        <item itemvalue="JUnit.TestAop.testAspect" />
       </list>
     </recent_temporary>
   </component>
@@ -244,7 +265,7 @@
       <workItem from="1713574818502" duration="20981000" />
       <workItem from="1713936457175" duration="12171000" />
       <workItem from="1714183148490" duration="130000" />
-      <workItem from="1714183284857" duration="7089000" />
+      <workItem from="1714183284857" duration="21532000" />
     </task>
     <task id="LOCAL-00001" summary="0403 javaSE">
       <option name="closed" value="true" />
@@ -310,7 +331,15 @@
       <option name="project" value="LOCAL" />
       <updated>1713949306918</updated>
     </task>
-    <option name="localTasksCounter" value="9" />
+    <task id="LOCAL-00009" summary="0427 spring aop">
+      <option name="closed" value="true" />
+      <created>1714190748841</created>
+      <option name="number" value="00009" />
+      <option name="presentableId" value="LOCAL-00009" />
+      <option name="project" value="LOCAL" />
+      <updated>1714190748841</updated>
+    </task>
+    <option name="localTasksCounter" value="10" />
     <servers />
   </component>
   <component name="TypeScriptGeneratedFilesManager">
@@ -443,7 +472,8 @@
     <MESSAGE value="0420 spring lifecycle" />
     <MESSAGE value="0420 spring ioc" />
     <MESSAGE value="0424 spring proxy" />
-    <option name="LAST_COMMIT_MESSAGE" value="0424 spring proxy" />
+    <MESSAGE value="0427 spring aop" />
+    <option name="LAST_COMMIT_MESSAGE" value="0427 spring aop" />
   </component>
   <component name="XSLT-Support.FileAssociations.UIState">
     <expand />

+ 27 - 2
spring-demo/pom.xml

@@ -20,13 +20,25 @@
         <dependency>
             <groupId>org.springframework</groupId>
             <artifactId>spring-context</artifactId>
-            <version>6.1.5</version>
+            <version>6.1.6</version>
         </dependency>
 
         <dependency>
             <groupId>org.springframework</groupId>
             <artifactId>spring-test</artifactId>
-            <version>6.1.5</version>
+            <version>6.1.6</version>
+        </dependency>
+
+        <dependency>
+            <groupId>org.springframework</groupId>
+            <artifactId>spring-jdbc</artifactId>
+            <version>6.1.6</version>
+        </dependency>
+
+        <dependency>
+            <groupId>org.projectlombok</groupId>
+            <artifactId>lombok</artifactId>
+            <version>1.18.32</version>
         </dependency>
 
         <dependency>
@@ -53,6 +65,19 @@
             <version>1.9.22</version>
         </dependency>
 
+        <dependency>
+            <groupId>mysql</groupId>
+            <artifactId>mysql-connector-java</artifactId>
+            <version>8.0.33</version>
+        </dependency>
+        <dependency>
+            <groupId>com.alibaba</groupId>
+            <artifactId>druid</artifactId>
+            <version>1.2.22</version>
+        </dependency>
+
+
+
         <dependency>
             <groupId>org.junit.jupiter</groupId>
             <artifactId>junit-jupiter</artifactId>

+ 23 - 0
spring-demo/src/main/java/com/sf/aspect/AopConfig.java

@@ -0,0 +1,23 @@
+package com.sf.aspect;
+
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.ComponentScan;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.context.annotation.EnableAspectJAutoProxy;
+
+// 配置化来加载bean
+@Configuration
+// 扫描包 默认扫描当前路径 com.sf.aspect
+@ComponentScan
+// 开启AspectJ的使用开关
+@EnableAspectJAutoProxy
+public class AopConfig {
+
+    // <bean id = "audienceAnno"  class = "com.sf.aspect.AudienceAnno"/>
+    // @Bean可以结合@Configuration  在spring容器中声明对象
+    // 此时的beanId是方法名
+    @Bean
+    public AudienceAnno audienceAnno() {
+        return new AudienceAnno();
+    }
+}

+ 1 - 0
spring-demo/src/main/java/com/sf/aspect/Audience.java

@@ -1,5 +1,6 @@
 package com.sf.aspect;
 
+// 观众的切面类
 public class Audience {
 
     // 表演之前 入场

+ 31 - 0
spring-demo/src/main/java/com/sf/aspect/AudienceAnno.java

@@ -0,0 +1,31 @@
+package com.sf.aspect;
+
+import org.aspectj.lang.annotation.AfterReturning;
+import org.aspectj.lang.annotation.Aspect;
+import org.aspectj.lang.annotation.Before;
+import org.aspectj.lang.annotation.Pointcut;
+import org.springframework.stereotype.Component;
+
+// 观众的切面类
+// <bean id = "audienceAnno"  class = "com.sf.aspect.AudienceAnno"/>
+//@Component
+@Aspect
+public class AudienceAnno {
+
+    @Pointcut("execution(* com.sf.aspect.Performance.perform())")
+    public void perform(){
+    }
+
+    // 表演之前 入场
+    // 将配置文件中的表达式 放到注解的参数中
+    @Before("perform()")
+    public void takeSeats() {
+        System.out.println("入场,坐到位置上");
+    }
+
+    // 表演之后 鼓掌
+    @AfterReturning("perform()")
+    public void applause() {
+        System.out.println("呱唧呱唧");
+    }
+}

+ 8 - 0
spring-demo/src/main/java/com/sf/aspect/CrossTalk.java

@@ -1,10 +1,18 @@
 package com.sf.aspect;
 
+import org.springframework.stereotype.Component;
 
+// 相声表演的实现类
+@Component
 public class CrossTalk implements Performance{
 
     @Override
     public void perform() {
         System.out.println("表演一段相声");
     }
+
+    @Override
+    public void respond() {
+        System.out.println("谢幕");
+    }
 }

+ 2 - 0
spring-demo/src/main/java/com/sf/aspect/Performance.java

@@ -4,4 +4,6 @@ package com.sf.aspect;
 public interface Performance {
 
     void perform();
+
+    void respond();
 }

+ 44 - 0
spring-demo/src/main/java/com/sf/jdbc/DruidConfig.java

@@ -0,0 +1,44 @@
+package com.sf.jdbc;
+
+
+import com.alibaba.druid.pool.DruidDataSource;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.PropertySource;
+import org.springframework.jdbc.core.JdbcTemplate;
+
+import javax.sql.DataSource;
+
+//  @PropertySource注解可以加载配置文件
+@PropertySource("db.properties")
+public class DruidConfig {
+
+    @Value("${jdbc.url}")
+    private String url;
+
+    @Value("${jdbc.username}")
+    private String username;
+
+    @Value("${jdbc.password}")
+    private String password;
+
+    @Value("${jdbc.driverName}")
+    private String driverClassName;
+
+    @Bean
+    public DataSource dataSource() {
+        DruidDataSource ds = new DruidDataSource();
+        ds.setUrl(url);
+        ds.setUsername(username);
+        ds.setPassword(password);
+        ds.setDriverClassName(driverClassName);
+        return ds;
+    }
+
+    // spring提供了一个通用的jdbc模版 JdbcTemplate
+    // 只需要把dataSource注入进来
+    @Bean
+    public JdbcTemplate jdbcTemplate(DataSource dataSource) {
+        return new JdbcTemplate(dataSource);
+    }
+}

+ 12 - 0
spring-demo/src/main/java/com/sf/jdbc/SpringJdbcConfig.java

@@ -0,0 +1,12 @@
+package com.sf.jdbc;
+
+import org.springframework.context.annotation.ComponentScan;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.context.annotation.Import;
+
+// Import导入另一个配置文件的内容
+@ComponentScan
+@Configuration
+@Import(DruidConfig.class)
+public class SpringJdbcConfig {
+}

+ 9 - 0
spring-demo/src/main/java/com/sf/jdbc/dao/BookDao.java

@@ -0,0 +1,9 @@
+package com.sf.jdbc.dao;
+
+import com.sf.jdbc.entity.Book;
+
+import java.util.List;
+
+public interface BookDao {
+    List<Book> findAll();
+}

+ 28 - 0
spring-demo/src/main/java/com/sf/jdbc/dao/impl/BookDaoImpl.java

@@ -0,0 +1,28 @@
+package com.sf.jdbc.dao.impl;
+
+import com.sf.jdbc.dao.BookDao;
+import com.sf.jdbc.entity.Book;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.jdbc.core.BeanPropertyRowMapper;
+import org.springframework.jdbc.core.JdbcTemplate;
+import org.springframework.stereotype.Repository;
+
+import java.util.List;
+
+// 注入spring容器中  如果有更详细的分类 不使用@Component
+// 比如dao层 使用 @Repository 仓库的意思
+@Repository
+public class BookDaoImpl implements BookDao {
+
+    // 获取jdbc的工具类
+    @Autowired
+    private JdbcTemplate jdbcTemplate;
+
+    @Override
+    public List<Book> findAll() {
+        String sql = "select * from book";
+        // 调用 jdbc工具类的查询方法 处理过程使用BeanPropertyRowMapper 是将实体类和数据库中的字段一一对应
+        List<Book> bookList = jdbcTemplate.query(sql, new BeanPropertyRowMapper<Book>(Book.class));
+        return bookList;
+    }
+}

+ 28 - 0
spring-demo/src/main/java/com/sf/jdbc/entity/Book.java

@@ -0,0 +1,28 @@
+package com.sf.jdbc.entity;
+
+import lombok.Data;
+
+import java.io.Serializable;
+
+@Data
+public class Book implements Serializable {
+
+    private static final long serialVersionUID = 5047814726963775513L;
+
+    private Long id;
+
+    private String bookId;
+
+    private String bookName;
+
+    private String typeId;
+
+    private String authorId;
+
+    private String authorName;
+
+    private String bookImg;
+
+    private String bookDesc;
+
+}

+ 6 - 0
spring-demo/src/main/resources/db.properties

@@ -0,0 +1,6 @@
+jdbc.url=jdbc:mysql://localhost:3306/books?useUnicode=true&characterEncoding=utf-8&allowPublicKeyRetrieval=true&useSSL=false&serverTimezone=Asia/Shanghai
+jdbc.driverName=com.mysql.cj.jdbc.Driver
+# ??????username ???????????
+#username=root
+jdbc.username=root
+jdbc.password=root123456

+ 10 - 1
spring-demo/src/main/resources/spring-aspect.xml

@@ -12,10 +12,19 @@
     <!-- 非核心逻辑  核心逻辑前后要做的事儿 -->
     <bean id="audience" class="com.sf.aspect.Audience"></bean>
 
-
     <aop:config>
         <aop:aspect ref="audience">
+            <!-- 连接点  要关注的具体方法是谁  可以用表达式来表示 -->
+            <!-- 表达式的组成 execution(* com.sf.aspect.Performance.perform()) -->
+            <!-- 表达式的组成 执行(返回任意类型 包名.类名.方法名(参数)) -->
             <aop:pointcut id="pointcut" expression="execution(* com.sf.aspect.Performance.perform())"/>
+            <!-- pointcut 和 advice 组成 advisor的逻辑 简写如下 -->
+            <aop:before method="takeSeats" pointcut-ref="pointcut"></aop:before>
+        </aop:aspect>
+        <aop:aspect ref="audience">
+            <aop:pointcut id="pointcut1" expression="execution(* com.sf.aspect.Performance.respond())"/>
+            <aop:after-returning method="applause" pointcut-ref="pointcut1"></aop:after-returning>
         </aop:aspect>
     </aop:config>
+
 </beans>

+ 19 - 0
spring-demo/src/main/resources/spring-mysql.xml

@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<beans xmlns="http://www.springframework.org/schema/beans"
+       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+       xmlns:context="http://www.springframework.org/schema/context"
+       xsi:schemaLocation="http://www.springframework.org/schema/beans
+        https://www.springframework.org/schema/beans/spring-beans.xsd
+        http://www.springframework.org/schema/context
+        https://www.springframework.org/schema/context/spring-context.xsd">
+
+    <!-- 加载properties文件 -->
+    <context:property-placeholder location="classpath:db.properties"/>
+
+    <bean id="datasource" class="com.alibaba.druid.pool.DruidDataSource">
+        <property name="url" value="${jdbc.url}"></property>
+        <property name="username" value="${jdbc.username}"></property>
+        <property name="password" value="${jdbc.password}"></property>
+        <property name="driverClassName" value="${jdbc.driverName}"></property>
+    </bean>
+</beans>

+ 21 - 0
spring-demo/src/test/java/com/sf/TestAop.java

@@ -1,8 +1,11 @@
 package com.sf;
 
 import com.sf.aop.BaseService;
+import com.sf.aspect.AopConfig;
+import com.sf.aspect.Performance;
 import org.junit.jupiter.api.Test;
 import org.springframework.context.ApplicationContext;
+import org.springframework.context.annotation.AnnotationConfigApplicationContext;
 import org.springframework.context.support.ClassPathXmlApplicationContext;
 
 public class TestAop {
@@ -23,4 +26,22 @@ public class TestAop {
         personProxy.eat();
         personProxy.wc();
     }
+
+    @Test
+    public void testAspect(){
+        // 识别xml方式的配置文件
+        ApplicationContext context = new ClassPathXmlApplicationContext("spring-aspect.xml");
+        Performance performance = context.getBean(Performance.class);
+        performance.perform();
+        performance.respond();
+    }
+
+    @Test
+    public void testAop(){
+        // 识别注解方式的配置文件
+        ApplicationContext context = new AnnotationConfigApplicationContext(AopConfig.class);
+        Performance performance = context.getBean(Performance.class);
+        performance.perform();
+        performance.respond();
+    }
 }

+ 21 - 0
spring-demo/src/test/java/com/sf/TestAopConfig.java

@@ -0,0 +1,21 @@
+package com.sf;
+
+
+import com.sf.aspect.AopConfig;
+import com.sf.aspect.Performance;
+import org.junit.jupiter.api.Test;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
+
+@SpringJUnitConfig(AopConfig.class)
+public class TestAopConfig {
+
+    @Autowired
+    private Performance performance;
+
+    @Test
+    public void test(){
+        performance.perform();
+        performance.respond();
+    }
+}

+ 20 - 0
spring-demo/src/test/java/com/sf/TestDruid.java

@@ -0,0 +1,20 @@
+package com.sf;
+
+import com.alibaba.druid.pool.DruidDataSource;
+import org.junit.jupiter.api.Test;
+import org.springframework.context.ApplicationContext;
+import org.springframework.context.support.ClassPathXmlApplicationContext;
+
+public class TestDruid {
+
+    @Test
+    public void test(){
+        ApplicationContext context =
+                new ClassPathXmlApplicationContext("spring-mysql.xml");
+        DruidDataSource dataSource = context.getBean(DruidDataSource.class);
+        System.out.println(dataSource.getUrl());
+        System.out.println(dataSource.getUsername());
+        System.out.println(dataSource.getPassword());
+        System.out.println(dataSource.getDriverClassName());
+    }
+}

+ 23 - 0
spring-demo/src/test/java/com/sf/TestJdbc.java

@@ -0,0 +1,23 @@
+package com.sf;
+
+import com.sf.jdbc.SpringJdbcConfig;
+import com.sf.jdbc.dao.BookDao;
+import com.sf.jdbc.entity.Book;
+import org.junit.jupiter.api.Test;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
+
+import java.util.List;
+
+@SpringJUnitConfig(SpringJdbcConfig.class)
+public class TestJdbc {
+
+    @Autowired
+    private BookDao bookDao;
+
+    @Test
+    public void test() {
+        List<Book> books = bookDao.findAll();
+        System.out.println(books);
+    }
+}