浏览代码

spring全篇

guyanqing 1 年之前
父节点
当前提交
85603772b7

+ 21 - 37
04maven/spring/.idea/workspace.xml

@@ -5,27 +5,11 @@
   </component>
   <component name="ChangeListManager">
     <list default="true" id="8c3e0ed0-6141-4ee9-a284-3fa2d43ee5eb" name="Changes" comment="">
-      <change afterPath="$PROJECT_DIR$/.idea/uiDesigner.xml" afterDir="false" />
-      <change afterPath="$PROJECT_DIR$/src/main/java/com/sf/aop/AopAspect.java" afterDir="false" />
-      <change afterPath="$PROJECT_DIR$/src/main/java/com/sf/aop/MathCalculator.java" afterDir="false" />
-      <change afterPath="$PROJECT_DIR$/src/main/java/com/sf/aop/MathCalculatorImpl.java" afterDir="false" />
-      <change afterPath="$PROJECT_DIR$/src/main/java/com/sf/dao/AccountDao.java" afterDir="false" />
-      <change afterPath="$PROJECT_DIR$/src/main/java/com/sf/dao/AccountDaoImpl.java" afterDir="false" />
-      <change afterPath="$PROJECT_DIR$/src/main/java/com/sf/proxy/ProxyUtils.java" afterDir="false" />
-      <change afterPath="$PROJECT_DIR$/src/main/java/com/sf/proxy/Secretary.java" afterDir="false" />
-      <change afterPath="$PROJECT_DIR$/src/main/java/com/sf/proxy/Sign.java" afterDir="false" />
-      <change afterPath="$PROJECT_DIR$/src/main/java/com/sf/proxy/TBoss.java" afterDir="false" />
-      <change afterPath="$PROJECT_DIR$/src/main/java/com/sf/service/AccountService.java" afterDir="false" />
-      <change afterPath="$PROJECT_DIR$/src/main/java/com/sf/service/AccountServiceImpl.java" afterDir="false" />
-      <change afterPath="$PROJECT_DIR$/src/main/resources/applicationContext.xml" afterDir="false" />
-      <change afterPath="$PROJECT_DIR$/src/main/resources/beanAop.xml" afterDir="false" />
-      <change afterPath="$PROJECT_DIR$/src/test/java/com/sf/aop/AopTest.java" afterDir="false" />
-      <change afterPath="$PROJECT_DIR$/src/test/java/com/sf/proxy/ProxyTest.java" afterDir="false" />
-      <change afterPath="$PROJECT_DIR$/src/test/java/com/sf/tx/TxTest.java" afterDir="false" />
+      <change afterPath="$PROJECT_DIR$/src/test/java/com/sf/tx/TxTest2.java" afterDir="false" />
+      <change afterPath="$PROJECT_DIR$/src/test/java/com/sf/tx/TxTest3.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/resources/db.properties" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/resources/db.properties" afterDir="false" />
-      <change beforePath="$PROJECT_DIR$/target/classes/db.properties" beforeDir="false" afterPath="$PROJECT_DIR$/target/classes/db.properties" afterDir="false" />
+      <change beforePath="$PROJECT_DIR$/target/classes/com/sf/service/AccountServiceImpl.class" beforeDir="false" afterPath="$PROJECT_DIR$/target/classes/com/sf/service/AccountServiceImpl.class" afterDir="false" />
     </list>
     <option name="SHOW_DIALOG" value="false" />
     <option name="HIGHLIGHT_CONFLICTS" value="true" />
@@ -72,7 +56,7 @@
     "vue.rearranger.settings.migration": "true"
   }
 }]]></component>
-  <component name="RunManager" selected="JUnit.TxTest.t1">
+  <component name="RunManager" selected="JUnit.TxTest3.t1">
     <configuration name="AopTest.t1 (1)" type="JUnit" factoryName="JUnit" temporary="true" nameIsGenerated="true">
       <module name="spring" />
       <extension name="coverage">
@@ -89,49 +73,49 @@
         <option name="Make" enabled="true" />
       </method>
     </configuration>
-    <configuration name="AopTest.t1" type="JUnit" factoryName="JUnit" temporary="true" nameIsGenerated="true">
+    <configuration name="ProxyTest.t2" type="JUnit" factoryName="JUnit" temporary="true" nameIsGenerated="true">
       <module name="spring" />
       <extension name="coverage">
         <pattern>
-          <option name="PATTERN" value="com.sf.*" />
+          <option name="PATTERN" value="com.sf.proxy.*" />
           <option name="ENABLED" value="true" />
         </pattern>
       </extension>
-      <option name="PACKAGE_NAME" value="com.sf" />
-      <option name="MAIN_CLASS_NAME" value="com.sf.AopTest" />
-      <option name="METHOD_NAME" value="t1" />
+      <option name="PACKAGE_NAME" value="com.sf.proxy" />
+      <option name="MAIN_CLASS_NAME" value="com.sf.proxy.ProxyTest" />
+      <option name="METHOD_NAME" value="t2" />
       <option name="TEST_OBJECT" value="method" />
       <method v="2">
         <option name="Make" enabled="true" />
       </method>
     </configuration>
-    <configuration name="ProxyTest.t1" type="JUnit" factoryName="JUnit" temporary="true" nameIsGenerated="true">
+    <configuration name="TxTest2.t1" type="JUnit" factoryName="JUnit" temporary="true" nameIsGenerated="true">
       <module name="spring" />
       <extension name="coverage">
         <pattern>
-          <option name="PATTERN" value="com.sf.proxy.*" />
+          <option name="PATTERN" value="com.sf.tx.*" />
           <option name="ENABLED" value="true" />
         </pattern>
       </extension>
-      <option name="PACKAGE_NAME" value="com.sf.proxy" />
-      <option name="MAIN_CLASS_NAME" value="com.sf.proxy.ProxyTest" />
+      <option name="PACKAGE_NAME" value="com.sf.tx" />
+      <option name="MAIN_CLASS_NAME" value="com.sf.tx.TxTest2" />
       <option name="METHOD_NAME" value="t1" />
       <option name="TEST_OBJECT" value="method" />
       <method v="2">
         <option name="Make" enabled="true" />
       </method>
     </configuration>
-    <configuration name="ProxyTest.t2" type="JUnit" factoryName="JUnit" temporary="true" nameIsGenerated="true">
+    <configuration name="TxTest3.t1" type="JUnit" factoryName="JUnit" temporary="true" nameIsGenerated="true">
       <module name="spring" />
       <extension name="coverage">
         <pattern>
-          <option name="PATTERN" value="com.sf.proxy.*" />
+          <option name="PATTERN" value="com.sf.tx.*" />
           <option name="ENABLED" value="true" />
         </pattern>
       </extension>
-      <option name="PACKAGE_NAME" value="com.sf.proxy" />
-      <option name="MAIN_CLASS_NAME" value="com.sf.proxy.ProxyTest" />
-      <option name="METHOD_NAME" value="t2" />
+      <option name="PACKAGE_NAME" value="com.sf.tx" />
+      <option name="MAIN_CLASS_NAME" value="com.sf.tx.TxTest3" />
+      <option name="METHOD_NAME" value="t1" />
       <option name="TEST_OBJECT" value="method" />
       <method v="2">
         <option name="Make" enabled="true" />
@@ -155,11 +139,11 @@
     </configuration>
     <recent_temporary>
       <list>
+        <item itemvalue="JUnit.TxTest3.t1" />
+        <item itemvalue="JUnit.TxTest2.t1" />
         <item itemvalue="JUnit.TxTest.t1" />
         <item itemvalue="JUnit.AopTest.t1 (1)" />
         <item itemvalue="JUnit.ProxyTest.t2" />
-        <item itemvalue="JUnit.ProxyTest.t1" />
-        <item itemvalue="JUnit.AopTest.t1" />
       </list>
     </recent_temporary>
   </component>
@@ -171,7 +155,7 @@
       <option name="number" value="Default" />
       <option name="presentableId" value="Default" />
       <updated>1689993904831</updated>
-      <workItem from="1689993906819" duration="63787000" />
+      <workItem from="1689993906819" duration="68491000" />
     </task>
     <servers />
   </component>

+ 6 - 0
04maven/spring/pom.xml

@@ -26,6 +26,12 @@
       <scope>test</scope>
     </dependency>
 
+    <dependency>
+      <groupId>org.springframework</groupId>
+      <artifactId>spring-test</artifactId>
+      <version>4.3.27.RELEASE</version>
+    </dependency>
+
 <!--    spring ioc 容器依赖-->
     <dependency>
       <groupId>org.springframework</groupId>

+ 0 - 2
04maven/spring/src/main/java/com/sf/service/AccountServiceImpl.java

@@ -23,11 +23,9 @@ public class AccountServiceImpl implements AccountService{
     public void transfer(String in, String out, Double money) {
 //        转入
         accountDao.inMoney(in,money);
-
 //        添加异常
 //        int y = 1/0;
 //        转出
         accountDao.outMoney(out,money);
-
     }
 }

+ 20 - 0
04maven/spring/src/test/java/com/sf/tx/TxTest2.java

@@ -0,0 +1,20 @@
+package com.sf.tx;
+
+import com.sf.service.AccountService;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+
+@RunWith(SpringJUnit4ClassRunner.class)
+@ContextConfiguration(locations = {"classpath:applicationContext.xml"})
+public class TxTest2 {
+    @Autowired
+    private AccountService accountService;
+
+    @Test
+    public void t1(){
+        accountService.transfer("li4","z3",500.00);
+    }
+}

+ 28 - 0
04maven/spring/src/test/java/com/sf/tx/TxTest3.java

@@ -0,0 +1,28 @@
+package com.sf.tx;
+
+import com.sf.service.AccountService;
+import com.sf.service.AccountServiceImpl;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.ApplicationContext;
+import org.springframework.context.support.ClassPathXmlApplicationContext;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+
+@RunWith(SpringJUnit4ClassRunner.class)
+@ContextConfiguration(locations = {"classpath:applicationContext.xml"})
+public class TxTest3 {
+//    通过自动注入资源
+    @Autowired
+    private AccountService accountService;
+
+    @Test
+    public void t1(){
+//        ApplicationContext ioc = new ClassPathXmlApplicationContext("applicationContext.xml");
+//        ioc.getBean();
+
+        accountService.transfer("z3","li4",500.00);
+
+    }
+}

二进制
04maven/spring/target/classes/com/sf/service/AccountServiceImpl.class


二进制
04maven/spring/target/test-classes/com/sf/tx/TxTest2.class


二进制
04maven/spring/target/test-classes/com/sf/tx/TxTest3.class