Spring学习笔记

打印 上一主题 下一主题

主题 942|帖子 942|积分 2830

1 spring介绍

1)为什么学习spring

​<bean ></bean>       
<bean  id="myLogger"></bean>


<aop:aspectj-autoproxy></aop:aspectj-autoproxy>                1.  Spring技能是JavaEE开发必备技能,企业开发技能选型命中率>90%
​<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
<bean  scope="prototype">
       <property name="sid" value="1001"></property>
       <property name="sname" value="张三"></property>
       <property name="gender" value="男"></property>
</bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">

    <bean id="student" ></bean>

</beans><?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
<bean  scope="prototype">
       <property name="sid" value="1001"></property>
       <property name="sname" value="张三"></property>
       <property name="gender" value="男"></property>
</bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">

    <bean id="student" ></bean>

</beans><?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
<bean  scope="prototype">
       <property name="sid" value="1001"></property>
       <property name="sname" value="张三"></property>
       <property name="gender" value="男"></property>
</bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">

    <bean id="student" ></bean>

</beans>2.  简化开发,降低企业级开发的复杂性
​<bean ></bean>       
<bean  id="myLogger"></bean>


<aop:aspectj-autoproxy></aop:aspectj-autoproxy>                3.  框架整合,高效整合其他技能,提高企业级应用开发与运行效率
​        作为一个java程序员,  spring必学., 是必经之路!
2)spring框架学什么?

​<bean ></bean>       
<bean  id="myLogger"></bean>


<aop:aspectj-autoproxy></aop:aspectj-autoproxy>                1. IOC
​<bean ></bean>       
<bean  id="myLogger"></bean>


<aop:aspectj-autoproxy></aop:aspectj-autoproxy>                2. AOP
​<bean ></bean>       
<bean  id="myLogger"></bean>


<aop:aspectj-autoproxy></aop:aspectj-autoproxy>                3. 整合
3)spring中的设计模式

​        学习spring的, 先了解下spring中紧张的设计模式:
1. 工厂模式

​<bean ></bean>       
<bean  id="myLogger"></bean>


<aop:aspectj-autoproxy></aop:aspectj-autoproxy>        1.简朴工厂
​<bean ></bean>       
<bean  id="myLogger"></bean>


<aop:aspectj-autoproxy></aop:aspectj-autoproxy>                简朴工厂模式是一种创建型设计模式,用于根据给定的范例实例化不同的类
​<bean ></bean>       
<bean  id="myLogger"></bean>


<aop:aspectj-autoproxy></aop:aspectj-autoproxy>                比方:  不同的动物范例创建对应的动物实例。
  1. public interface Animal {
  2. <?xml version="1.0" encoding="UTF-8"?>
  3. <beans xmlns="http://www.springframework.org/schema/beans"
  4.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  5.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  6. <bean  scope="prototype">
  7.        <property name="sid" value="1001"></property>
  8.        <property name="sname" value="张三"></property>
  9.        <property name="gender" value="男"></property>
  10. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  11.     <bean id="student" ></bean>
  12. </beans>void speak();
  13. }
复制代码
  1. public class Dog implements Animal {
  2. <?xml version="1.0" encoding="UTF-8"?>
  3. <beans xmlns="http://www.springframework.org/schema/beans"
  4.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  5.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  6. <bean  scope="prototype">
  7.        <property name="sid" value="1001"></property>
  8.        <property name="sname" value="张三"></property>
  9.        <property name="gender" value="男"></property>
  10. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  11.     <bean id="student" ></bean>
  12. </beans>@Override
  13. <?xml version="1.0" encoding="UTF-8"?>
  14. <beans xmlns="http://www.springframework.org/schema/beans"
  15.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  16.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  17. <bean  scope="prototype">
  18.        <property name="sid" value="1001"></property>
  19.        <property name="sname" value="张三"></property>
  20.        <property name="gender" value="男"></property>
  21. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  22.     <bean id="student" ></bean>
  23. </beans>public void speak() {
  24. <?xml version="1.0" encoding="UTF-8"?>
  25. <beans xmlns="http://www.springframework.org/schema/beans"
  26.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  27.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  28. <bean  scope="prototype">
  29.        <property name="sid" value="1001"></property>
  30.        <property name="sname" value="张三"></property>
  31.        <property name="gender" value="男"></property>
  32. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  33.     <bean id="student" ></bean>
  34. </beans><?xml version="1.0" encoding="UTF-8"?>
  35. <beans xmlns="http://www.springframework.org/schema/beans"
  36.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  37.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  38. <bean  scope="prototype">
  39.        <property name="sid" value="1001"></property>
  40.        <property name="sname" value="张三"></property>
  41.        <property name="gender" value="男"></property>
  42. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  43.     <bean id="student" ></bean>
  44. </beans>System.out.println("Woof!");
  45. <?xml version="1.0" encoding="UTF-8"?>
  46. <beans xmlns="http://www.springframework.org/schema/beans"
  47.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  48.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  49. <bean  scope="prototype">
  50.        <property name="sid" value="1001"></property>
  51.        <property name="sname" value="张三"></property>
  52.        <property name="gender" value="男"></property>
  53. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  54.     <bean id="student" ></bean>
  55. </beans>}
  56. }
  57. public class Cat implements Animal {
  58. <?xml version="1.0" encoding="UTF-8"?>
  59. <beans xmlns="http://www.springframework.org/schema/beans"
  60.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  61.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  62. <bean  scope="prototype">
  63.        <property name="sid" value="1001"></property>
  64.        <property name="sname" value="张三"></property>
  65.        <property name="gender" value="男"></property>
  66. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  67.     <bean id="student" ></bean>
  68. </beans>@Override
  69. <?xml version="1.0" encoding="UTF-8"?>
  70. <beans xmlns="http://www.springframework.org/schema/beans"
  71.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  72.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  73. <bean  scope="prototype">
  74.        <property name="sid" value="1001"></property>
  75.        <property name="sname" value="张三"></property>
  76.        <property name="gender" value="男"></property>
  77. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  78.     <bean id="student" ></bean>
  79. </beans>public void speak() {
  80. <?xml version="1.0" encoding="UTF-8"?>
  81. <beans xmlns="http://www.springframework.org/schema/beans"
  82.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  83.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  84. <bean  scope="prototype">
  85.        <property name="sid" value="1001"></property>
  86.        <property name="sname" value="张三"></property>
  87.        <property name="gender" value="男"></property>
  88. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  89.     <bean id="student" ></bean>
  90. </beans><?xml version="1.0" encoding="UTF-8"?>
  91. <beans xmlns="http://www.springframework.org/schema/beans"
  92.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  93.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  94. <bean  scope="prototype">
  95.        <property name="sid" value="1001"></property>
  96.        <property name="sname" value="张三"></property>
  97.        <property name="gender" value="男"></property>
  98. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  99.     <bean id="student" ></bean>
  100. </beans>System.out.println("Meow");
  101. <?xml version="1.0" encoding="UTF-8"?>
  102. <beans xmlns="http://www.springframework.org/schema/beans"
  103.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  104.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  105. <bean  scope="prototype">
  106.        <property name="sid" value="1001"></property>
  107.        <property name="sname" value="张三"></property>
  108.        <property name="gender" value="男"></property>
  109. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  110.     <bean id="student" ></bean>
  111. </beans>}
  112. }
复制代码
然后,创建一个名为AnimalFactory的简朴工厂类,它负责根据给定的范例实例化相应的动物实例:
  1. public class AnimalFactory {
  2. <?xml version="1.0" encoding="UTF-8"?>
  3. <beans xmlns="http://www.springframework.org/schema/beans"
  4.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  5.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  6. <bean  scope="prototype">
  7.        <property name="sid" value="1001"></property>
  8.        <property name="sname" value="张三"></property>
  9.        <property name="gender" value="男"></property>
  10. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  11.     <bean id="student" ></bean>
  12. </beans>public enum AnimalType {
  13. <?xml version="1.0" encoding="UTF-8"?>
  14. <beans xmlns="http://www.springframework.org/schema/beans"
  15.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  16.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  17. <bean  scope="prototype">
  18.        <property name="sid" value="1001"></property>
  19.        <property name="sname" value="张三"></property>
  20.        <property name="gender" value="男"></property>
  21. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  22.     <bean id="student" ></bean>
  23. </beans><?xml version="1.0" encoding="UTF-8"?>
  24. <beans xmlns="http://www.springframework.org/schema/beans"
  25.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  26.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  27. <bean  scope="prototype">
  28.        <property name="sid" value="1001"></property>
  29.        <property name="sname" value="张三"></property>
  30.        <property name="gender" value="男"></property>
  31. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  32.     <bean id="student" ></bean>
  33. </beans>DOG,
  34. <?xml version="1.0" encoding="UTF-8"?>
  35. <beans xmlns="http://www.springframework.org/schema/beans"
  36.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  37.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  38. <bean  scope="prototype">
  39.        <property name="sid" value="1001"></property>
  40.        <property name="sname" value="张三"></property>
  41.        <property name="gender" value="男"></property>
  42. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  43.     <bean id="student" ></bean>
  44. </beans><?xml version="1.0" encoding="UTF-8"?>
  45. <beans xmlns="http://www.springframework.org/schema/beans"
  46.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  47.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  48. <bean  scope="prototype">
  49.        <property name="sid" value="1001"></property>
  50.        <property name="sname" value="张三"></property>
  51.        <property name="gender" value="男"></property>
  52. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  53.     <bean id="student" ></bean>
  54. </beans>CAT
  55. <?xml version="1.0" encoding="UTF-8"?>
  56. <beans xmlns="http://www.springframework.org/schema/beans"
  57.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  58.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  59. <bean  scope="prototype">
  60.        <property name="sid" value="1001"></property>
  61.        <property name="sname" value="张三"></property>
  62.        <property name="gender" value="男"></property>
  63. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  64.     <bean id="student" ></bean>
  65. </beans>}
  66. <?xml version="1.0" encoding="UTF-8"?>
  67. <beans xmlns="http://www.springframework.org/schema/beans"
  68.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  69.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  70. <bean  scope="prototype">
  71.        <property name="sid" value="1001"></property>
  72.        <property name="sname" value="张三"></property>
  73.        <property name="gender" value="男"></property>
  74. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  75.     <bean id="student" ></bean>
  76. </beans>public static Animal createAnimal(AnimalType type) {
  77. <?xml version="1.0" encoding="UTF-8"?>
  78. <beans xmlns="http://www.springframework.org/schema/beans"
  79.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  80.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  81. <bean  scope="prototype">
  82.        <property name="sid" value="1001"></property>
  83.        <property name="sname" value="张三"></property>
  84.        <property name="gender" value="男"></property>
  85. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  86.     <bean id="student" ></bean>
  87. </beans><?xml version="1.0" encoding="UTF-8"?>
  88. <beans xmlns="http://www.springframework.org/schema/beans"
  89.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  90.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  91. <bean  scope="prototype">
  92.        <property name="sid" value="1001"></property>
  93.        <property name="sname" value="张三"></property>
  94.        <property name="gender" value="男"></property>
  95. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  96.     <bean id="student" ></bean>
  97. </beans>switch (type) {
  98. <?xml version="1.0" encoding="UTF-8"?>
  99. <beans xmlns="http://www.springframework.org/schema/beans"
  100.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  101.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  102. <bean  scope="prototype">
  103.        <property name="sid" value="1001"></property>
  104.        <property name="sname" value="张三"></property>
  105.        <property name="gender" value="男"></property>
  106. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  107.     <bean id="student" ></bean>
  108. </beans><?xml version="1.0" encoding="UTF-8"?>
  109. <beans xmlns="http://www.springframework.org/schema/beans"
  110.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  111.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  112. <bean  scope="prototype">
  113.        <property name="sid" value="1001"></property>
  114.        <property name="sname" value="张三"></property>
  115.        <property name="gender" value="男"></property>
  116. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  117.     <bean id="student" ></bean>
  118. </beans><?xml version="1.0" encoding="UTF-8"?>
  119. <beans xmlns="http://www.springframework.org/schema/beans"
  120.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  121.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  122. <bean  scope="prototype">
  123.        <property name="sid" value="1001"></property>
  124.        <property name="sname" value="张三"></property>
  125.        <property name="gender" value="男"></property>
  126. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  127.     <bean id="student" ></bean>
  128. </beans>case DOG:
  129. <?xml version="1.0" encoding="UTF-8"?>
  130. <beans xmlns="http://www.springframework.org/schema/beans"
  131.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  132.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  133. <bean  scope="prototype">
  134.        <property name="sid" value="1001"></property>
  135.        <property name="sname" value="张三"></property>
  136.        <property name="gender" value="男"></property>
  137. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  138.     <bean id="student" ></bean>
  139. </beans><?xml version="1.0" encoding="UTF-8"?>
  140. <beans xmlns="http://www.springframework.org/schema/beans"
  141.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  142.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  143. <bean  scope="prototype">
  144.        <property name="sid" value="1001"></property>
  145.        <property name="sname" value="张三"></property>
  146.        <property name="gender" value="男"></property>
  147. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  148.     <bean id="student" ></bean>
  149. </beans><?xml version="1.0" encoding="UTF-8"?>
  150. <beans xmlns="http://www.springframework.org/schema/beans"
  151.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  152.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  153. <bean  scope="prototype">
  154.        <property name="sid" value="1001"></property>
  155.        <property name="sname" value="张三"></property>
  156.        <property name="gender" value="男"></property>
  157. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  158.     <bean id="student" ></bean>
  159. </beans><?xml version="1.0" encoding="UTF-8"?>
  160. <beans xmlns="http://www.springframework.org/schema/beans"
  161.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  162.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  163. <bean  scope="prototype">
  164.        <property name="sid" value="1001"></property>
  165.        <property name="sname" value="张三"></property>
  166.        <property name="gender" value="男"></property>
  167. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  168.     <bean id="student" ></bean>
  169. </beans>return new Dog();
  170. <?xml version="1.0" encoding="UTF-8"?>
  171. <beans xmlns="http://www.springframework.org/schema/beans"
  172.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  173.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  174. <bean  scope="prototype">
  175.        <property name="sid" value="1001"></property>
  176.        <property name="sname" value="张三"></property>
  177.        <property name="gender" value="男"></property>
  178. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  179.     <bean id="student" ></bean>
  180. </beans><?xml version="1.0" encoding="UTF-8"?>
  181. <beans xmlns="http://www.springframework.org/schema/beans"
  182.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  183.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  184. <bean  scope="prototype">
  185.        <property name="sid" value="1001"></property>
  186.        <property name="sname" value="张三"></property>
  187.        <property name="gender" value="男"></property>
  188. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  189.     <bean id="student" ></bean>
  190. </beans><?xml version="1.0" encoding="UTF-8"?>
  191. <beans xmlns="http://www.springframework.org/schema/beans"
  192.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  193.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  194. <bean  scope="prototype">
  195.        <property name="sid" value="1001"></property>
  196.        <property name="sname" value="张三"></property>
  197.        <property name="gender" value="男"></property>
  198. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  199.     <bean id="student" ></bean>
  200. </beans>case CAT:
  201. <?xml version="1.0" encoding="UTF-8"?>
  202. <beans xmlns="http://www.springframework.org/schema/beans"
  203.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  204.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  205. <bean  scope="prototype">
  206.        <property name="sid" value="1001"></property>
  207.        <property name="sname" value="张三"></property>
  208.        <property name="gender" value="男"></property>
  209. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  210.     <bean id="student" ></bean>
  211. </beans><?xml version="1.0" encoding="UTF-8"?>
  212. <beans xmlns="http://www.springframework.org/schema/beans"
  213.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  214.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  215. <bean  scope="prototype">
  216.        <property name="sid" value="1001"></property>
  217.        <property name="sname" value="张三"></property>
  218.        <property name="gender" value="男"></property>
  219. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  220.     <bean id="student" ></bean>
  221. </beans><?xml version="1.0" encoding="UTF-8"?>
  222. <beans xmlns="http://www.springframework.org/schema/beans"
  223.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  224.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  225. <bean  scope="prototype">
  226.        <property name="sid" value="1001"></property>
  227.        <property name="sname" value="张三"></property>
  228.        <property name="gender" value="男"></property>
  229. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  230.     <bean id="student" ></bean>
  231. </beans><?xml version="1.0" encoding="UTF-8"?>
  232. <beans xmlns="http://www.springframework.org/schema/beans"
  233.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  234.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  235. <bean  scope="prototype">
  236.        <property name="sid" value="1001"></property>
  237.        <property name="sname" value="张三"></property>
  238.        <property name="gender" value="男"></property>
  239. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  240.     <bean id="student" ></bean>
  241. </beans>return new Cat();
  242. <?xml version="1.0" encoding="UTF-8"?>
  243. <beans xmlns="http://www.springframework.org/schema/beans"
  244.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  245.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  246. <bean  scope="prototype">
  247.        <property name="sid" value="1001"></property>
  248.        <property name="sname" value="张三"></property>
  249.        <property name="gender" value="男"></property>
  250. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  251.     <bean id="student" ></bean>
  252. </beans><?xml version="1.0" encoding="UTF-8"?>
  253. <beans xmlns="http://www.springframework.org/schema/beans"
  254.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  255.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  256. <bean  scope="prototype">
  257.        <property name="sid" value="1001"></property>
  258.        <property name="sname" value="张三"></property>
  259.        <property name="gender" value="男"></property>
  260. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  261.     <bean id="student" ></bean>
  262. </beans><?xml version="1.0" encoding="UTF-8"?>
  263. <beans xmlns="http://www.springframework.org/schema/beans"
  264.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  265.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  266. <bean  scope="prototype">
  267.        <property name="sid" value="1001"></property>
  268.        <property name="sname" value="张三"></property>
  269.        <property name="gender" value="男"></property>
  270. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  271.     <bean id="student" ></bean>
  272. </beans>default:
  273. <?xml version="1.0" encoding="UTF-8"?>
  274. <beans xmlns="http://www.springframework.org/schema/beans"
  275.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  276.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  277. <bean  scope="prototype">
  278.        <property name="sid" value="1001"></property>
  279.        <property name="sname" value="张三"></property>
  280.        <property name="gender" value="男"></property>
  281. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  282.     <bean id="student" ></bean>
  283. </beans><?xml version="1.0" encoding="UTF-8"?>
  284. <beans xmlns="http://www.springframework.org/schema/beans"
  285.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  286.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  287. <bean  scope="prototype">
  288.        <property name="sid" value="1001"></property>
  289.        <property name="sname" value="张三"></property>
  290.        <property name="gender" value="男"></property>
  291. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  292.     <bean id="student" ></bean>
  293. </beans><?xml version="1.0" encoding="UTF-8"?>
  294. <beans xmlns="http://www.springframework.org/schema/beans"
  295.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  296.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  297. <bean  scope="prototype">
  298.        <property name="sid" value="1001"></property>
  299.        <property name="sname" value="张三"></property>
  300.        <property name="gender" value="男"></property>
  301. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  302.     <bean id="student" ></bean>
  303. </beans><?xml version="1.0" encoding="UTF-8"?>
  304. <beans xmlns="http://www.springframework.org/schema/beans"
  305.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  306.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  307. <bean  scope="prototype">
  308.        <property name="sid" value="1001"></property>
  309.        <property name="sname" value="张三"></property>
  310.        <property name="gender" value="男"></property>
  311. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  312.     <bean id="student" ></bean>
  313. </beans>throw new IllegalArgumentException("Invalid animal type: " + type);
  314. <?xml version="1.0" encoding="UTF-8"?>
  315. <beans xmlns="http://www.springframework.org/schema/beans"
  316.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  317.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  318. <bean  scope="prototype">
  319.        <property name="sid" value="1001"></property>
  320.        <property name="sname" value="张三"></property>
  321.        <property name="gender" value="男"></property>
  322. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  323.     <bean id="student" ></bean>
  324. </beans><?xml version="1.0" encoding="UTF-8"?>
  325. <beans xmlns="http://www.springframework.org/schema/beans"
  326.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  327.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  328. <bean  scope="prototype">
  329.        <property name="sid" value="1001"></property>
  330.        <property name="sname" value="张三"></property>
  331.        <property name="gender" value="男"></property>
  332. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  333.     <bean id="student" ></bean>
  334. </beans>}
  335. <?xml version="1.0" encoding="UTF-8"?>
  336. <beans xmlns="http://www.springframework.org/schema/beans"
  337.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  338.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  339. <bean  scope="prototype">
  340.        <property name="sid" value="1001"></property>
  341.        <property name="sname" value="张三"></property>
  342.        <property name="gender" value="男"></property>
  343. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  344.     <bean id="student" ></bean>
  345. </beans>}
  346. }
复制代码
末了,我们可以在主方法中使用这个简朴工厂类来创建不同范例的动物实例:
  1. public class Main {
  2. <?xml version="1.0" encoding="UTF-8"?>
  3. <beans xmlns="http://www.springframework.org/schema/beans"
  4.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  5.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  6. <bean  scope="prototype">
  7.        <property name="sid" value="1001"></property>
  8.        <property name="sname" value="张三"></property>
  9.        <property name="gender" value="男"></property>
  10. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  11.     <bean id="student" ></bean>
  12. </beans>public static void main(String[] args) {
  13. <?xml version="1.0" encoding="UTF-8"?>
  14. <beans xmlns="http://www.springframework.org/schema/beans"
  15.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  16.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  17. <bean  scope="prototype">
  18.        <property name="sid" value="1001"></property>
  19.        <property name="sname" value="张三"></property>
  20.        <property name="gender" value="男"></property>
  21. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  22.     <bean id="student" ></bean>
  23. </beans><?xml version="1.0" encoding="UTF-8"?>
  24. <beans xmlns="http://www.springframework.org/schema/beans"
  25.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  26.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  27. <bean  scope="prototype">
  28.        <property name="sid" value="1001"></property>
  29.        <property name="sname" value="张三"></property>
  30.        <property name="gender" value="男"></property>
  31. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  32.     <bean id="student" ></bean>
  33. </beans>Animal dog = AnimalFactory.createAnimal(AnimalFactory.AnimalType.DOG);
  34. <?xml version="1.0" encoding="UTF-8"?>
  35. <beans xmlns="http://www.springframework.org/schema/beans"
  36.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  37.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  38. <bean  scope="prototype">
  39.        <property name="sid" value="1001"></property>
  40.        <property name="sname" value="张三"></property>
  41.        <property name="gender" value="男"></property>
  42. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  43.     <bean id="student" ></bean>
  44. </beans><?xml version="1.0" encoding="UTF-8"?>
  45. <beans xmlns="http://www.springframework.org/schema/beans"
  46.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  47.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  48. <bean  scope="prototype">
  49.        <property name="sid" value="1001"></property>
  50.        <property name="sname" value="张三"></property>
  51.        <property name="gender" value="男"></property>
  52. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  53.     <bean id="student" ></bean>
  54. </beans>dog.speak();
  55. <?xml version="1.0" encoding="UTF-8"?>
  56. <beans xmlns="http://www.springframework.org/schema/beans"
  57.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  58.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  59. <bean  scope="prototype">
  60.        <property name="sid" value="1001"></property>
  61.        <property name="sname" value="张三"></property>
  62.        <property name="gender" value="男"></property>
  63. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  64.     <bean id="student" ></bean>
  65. </beans><?xml version="1.0" encoding="UTF-8"?>
  66. <beans xmlns="http://www.springframework.org/schema/beans"
  67.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  68.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  69. <bean  scope="prototype">
  70.        <property name="sid" value="1001"></property>
  71.        <property name="sname" value="张三"></property>
  72.        <property name="gender" value="男"></property>
  73. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  74.     <bean id="student" ></bean>
  75. </beans>Animal cat = AnimalFactory.createAnimal(AnimalFactory.AnimalType.CAT);
  76. <?xml version="1.0" encoding="UTF-8"?>
  77. <beans xmlns="http://www.springframework.org/schema/beans"
  78.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  79.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  80. <bean  scope="prototype">
  81.        <property name="sid" value="1001"></property>
  82.        <property name="sname" value="张三"></property>
  83.        <property name="gender" value="男"></property>
  84. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  85.     <bean id="student" ></bean>
  86. </beans><?xml version="1.0" encoding="UTF-8"?>
  87. <beans xmlns="http://www.springframework.org/schema/beans"
  88.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  89.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  90. <bean  scope="prototype">
  91.        <property name="sid" value="1001"></property>
  92.        <property name="sname" value="张三"></property>
  93.        <property name="gender" value="男"></property>
  94. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  95.     <bean id="student" ></bean>
  96. </beans>cat.speak();
  97. <?xml version="1.0" encoding="UTF-8"?>
  98. <beans xmlns="http://www.springframework.org/schema/beans"
  99.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  100.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  101. <bean  scope="prototype">
  102.        <property name="sid" value="1001"></property>
  103.        <property name="sname" value="张三"></property>
  104.        <property name="gender" value="男"></property>
  105. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  106.     <bean id="student" ></bean>
  107. </beans>}
  108. }
复制代码
​<bean ></bean>       
<bean  id="myLogger"></bean>


<aop:aspectj-autoproxy></aop:aspectj-autoproxy>        2.抽象工厂
​<bean ></bean>       
<bean  id="myLogger"></bean>


<aop:aspectj-autoproxy></aop:aspectj-autoproxy>                抽象工厂模式是一种创建型设计模式,它允许您根据不同的族系大概平台来实例化一组相关的对象;
​<bean ></bean>       
<bean  id="myLogger"></bean>


<aop:aspectj-autoproxy></aop:aspectj-autoproxy>                首先,我们定义两个接口,Animal和Plant
  1. public interface Animal {
  2. <?xml version="1.0" encoding="UTF-8"?>
  3. <beans xmlns="http://www.springframework.org/schema/beans"
  4.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  5.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  6. <bean  scope="prototype">
  7.        <property name="sid" value="1001"></property>
  8.        <property name="sname" value="张三"></property>
  9.        <property name="gender" value="男"></property>
  10. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  11.     <bean id="student" ></bean>
  12. </beans>void speak();
  13. }public interface Plant {<?xml version="1.0" encoding="UTF-8"?>
  14. <beans xmlns="http://www.springframework.org/schema/beans"
  15.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  16.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  17. <bean  scope="prototype">
  18.        <property name="sid" value="1001"></property>
  19.        <property name="sname" value="张三"></property>
  20.        <property name="gender" value="男"></property>
  21. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  22.     <bean id="student" ></bean>
  23. </beans>void grow();}
复制代码
接下来,为不同族系创建具体的Animal和Plant实现:
  1. // 陆地生物
  2. public class LandAnimal implements Animal {
  3. <?xml version="1.0" encoding="UTF-8"?>
  4. <beans xmlns="http://www.springframework.org/schema/beans"
  5.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  6.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  7. <bean  scope="prototype">
  8.        <property name="sid" value="1001"></property>
  9.        <property name="sname" value="张三"></property>
  10.        <property name="gender" value="男"></property>
  11. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  12.     <bean id="student" ></bean>
  13. </beans>@Override
  14. <?xml version="1.0" encoding="UTF-8"?>
  15. <beans xmlns="http://www.springframework.org/schema/beans"
  16.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  17.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  18. <bean  scope="prototype">
  19.        <property name="sid" value="1001"></property>
  20.        <property name="sname" value="张三"></property>
  21.        <property name="gender" value="男"></property>
  22. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  23.     <bean id="student" ></bean>
  24. </beans>public void speak() {
  25. <?xml version="1.0" encoding="UTF-8"?>
  26. <beans xmlns="http://www.springframework.org/schema/beans"
  27.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  28.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  29. <bean  scope="prototype">
  30.        <property name="sid" value="1001"></property>
  31.        <property name="sname" value="张三"></property>
  32.        <property name="gender" value="男"></property>
  33. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  34.     <bean id="student" ></bean>
  35. </beans><?xml version="1.0" encoding="UTF-8"?>
  36. <beans xmlns="http://www.springframework.org/schema/beans"
  37.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  38.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  39. <bean  scope="prototype">
  40.        <property name="sid" value="1001"></property>
  41.        <property name="sname" value="张三"></property>
  42.        <property name="gender" value="男"></property>
  43. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  44.     <bean id="student" ></bean>
  45. </beans>System.out.println("I am a land animal.");
  46. <?xml version="1.0" encoding="UTF-8"?>
  47. <beans xmlns="http://www.springframework.org/schema/beans"
  48.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  49.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  50. <bean  scope="prototype">
  51.        <property name="sid" value="1001"></property>
  52.        <property name="sname" value="张三"></property>
  53.        <property name="gender" value="男"></property>
  54. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  55.     <bean id="student" ></bean>
  56. </beans>}
  57. }
  58. public class LandPlant implements Plant {
  59. <?xml version="1.0" encoding="UTF-8"?>
  60. <beans xmlns="http://www.springframework.org/schema/beans"
  61.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  62.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  63. <bean  scope="prototype">
  64.        <property name="sid" value="1001"></property>
  65.        <property name="sname" value="张三"></property>
  66.        <property name="gender" value="男"></property>
  67. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  68.     <bean id="student" ></bean>
  69. </beans>@Override
  70. <?xml version="1.0" encoding="UTF-8"?>
  71. <beans xmlns="http://www.springframework.org/schema/beans"
  72.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  73.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  74. <bean  scope="prototype">
  75.        <property name="sid" value="1001"></property>
  76.        <property name="sname" value="张三"></property>
  77.        <property name="gender" value="男"></property>
  78. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  79.     <bean id="student" ></bean>
  80. </beans>public void grow() {
  81. <?xml version="1.0" encoding="UTF-8"?>
  82. <beans xmlns="http://www.springframework.org/schema/beans"
  83.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  84.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  85. <bean  scope="prototype">
  86.        <property name="sid" value="1001"></property>
  87.        <property name="sname" value="张三"></property>
  88.        <property name="gender" value="男"></property>
  89. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  90.     <bean id="student" ></bean>
  91. </beans><?xml version="1.0" encoding="UTF-8"?>
  92. <beans xmlns="http://www.springframework.org/schema/beans"
  93.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  94.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  95. <bean  scope="prototype">
  96.        <property name="sid" value="1001"></property>
  97.        <property name="sname" value="张三"></property>
  98.        <property name="gender" value="男"></property>
  99. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  100.     <bean id="student" ></bean>
  101. </beans>System.out.println("I am a land plant.");
  102. <?xml version="1.0" encoding="UTF-8"?>
  103. <beans xmlns="http://www.springframework.org/schema/beans"
  104.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  105.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  106. <bean  scope="prototype">
  107.        <property name="sid" value="1001"></property>
  108.        <property name="sname" value="张三"></property>
  109.        <property name="gender" value="男"></property>
  110. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  111.     <bean id="student" ></bean>
  112. </beans>}
  113. }
  114. // 水生生物
  115. public class AquaticAnimal implements Animal {
  116. <?xml version="1.0" encoding="UTF-8"?>
  117. <beans xmlns="http://www.springframework.org/schema/beans"
  118.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  119.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  120. <bean  scope="prototype">
  121.        <property name="sid" value="1001"></property>
  122.        <property name="sname" value="张三"></property>
  123.        <property name="gender" value="男"></property>
  124. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  125.     <bean id="student" ></bean>
  126. </beans>@Override
  127. <?xml version="1.0" encoding="UTF-8"?>
  128. <beans xmlns="http://www.springframework.org/schema/beans"
  129.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  130.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  131. <bean  scope="prototype">
  132.        <property name="sid" value="1001"></property>
  133.        <property name="sname" value="张三"></property>
  134.        <property name="gender" value="男"></property>
  135. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  136.     <bean id="student" ></bean>
  137. </beans>public void speak() {
  138. <?xml version="1.0" encoding="UTF-8"?>
  139. <beans xmlns="http://www.springframework.org/schema/beans"
  140.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  141.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  142. <bean  scope="prototype">
  143.        <property name="sid" value="1001"></property>
  144.        <property name="sname" value="张三"></property>
  145.        <property name="gender" value="男"></property>
  146. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  147.     <bean id="student" ></bean>
  148. </beans><?xml version="1.0" encoding="UTF-8"?>
  149. <beans xmlns="http://www.springframework.org/schema/beans"
  150.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  151.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  152. <bean  scope="prototype">
  153.        <property name="sid" value="1001"></property>
  154.        <property name="sname" value="张三"></property>
  155.        <property name="gender" value="男"></property>
  156. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  157.     <bean id="student" ></bean>
  158. </beans>System.out.println("I am an aquatic animal.");
  159. <?xml version="1.0" encoding="UTF-8"?>
  160. <beans xmlns="http://www.springframework.org/schema/beans"
  161.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  162.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  163. <bean  scope="prototype">
  164.        <property name="sid" value="1001"></property>
  165.        <property name="sname" value="张三"></property>
  166.        <property name="gender" value="男"></property>
  167. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  168.     <bean id="student" ></bean>
  169. </beans>}
  170. }
  171. public class AquaticPlant implements Plant {
  172. <?xml version="1.0" encoding="UTF-8"?>
  173. <beans xmlns="http://www.springframework.org/schema/beans"
  174.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  175.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  176. <bean  scope="prototype">
  177.        <property name="sid" value="1001"></property>
  178.        <property name="sname" value="张三"></property>
  179.        <property name="gender" value="男"></property>
  180. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  181.     <bean id="student" ></bean>
  182. </beans>@Override
  183. <?xml version="1.0" encoding="UTF-8"?>
  184. <beans xmlns="http://www.springframework.org/schema/beans"
  185.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  186.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  187. <bean  scope="prototype">
  188.        <property name="sid" value="1001"></property>
  189.        <property name="sname" value="张三"></property>
  190.        <property name="gender" value="男"></property>
  191. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  192.     <bean id="student" ></bean>
  193. </beans>public void grow() {
  194. <?xml version="1.0" encoding="UTF-8"?>
  195. <beans xmlns="http://www.springframework.org/schema/beans"
  196.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  197.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  198. <bean  scope="prototype">
  199.        <property name="sid" value="1001"></property>
  200.        <property name="sname" value="张三"></property>
  201.        <property name="gender" value="男"></property>
  202. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  203.     <bean id="student" ></bean>
  204. </beans><?xml version="1.0" encoding="UTF-8"?>
  205. <beans xmlns="http://www.springframework.org/schema/beans"
  206.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  207.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  208. <bean  scope="prototype">
  209.        <property name="sid" value="1001"></property>
  210.        <property name="sname" value="张三"></property>
  211.        <property name="gender" value="男"></property>
  212. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  213.     <bean id="student" ></bean>
  214. </beans>System.out.println("I am an aquatic plant.");
  215. <?xml version="1.0" encoding="UTF-8"?>
  216. <beans xmlns="http://www.springframework.org/schema/beans"
  217.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  218.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  219. <bean  scope="prototype">
  220.        <property name="sid" value="1001"></property>
  221.        <property name="sname" value="张三"></property>
  222.        <property name="gender" value="男"></property>
  223. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  224.     <bean id="student" ></bean>
  225. </beans>}
  226. }
复制代码
然后,创建一个名为NatureFactory的抽象工厂接口:
  1. public interface NatureFactory {
  2. <?xml version="1.0" encoding="UTF-8"?>
  3. <beans xmlns="http://www.springframework.org/schema/beans"
  4.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  5.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  6. <bean  scope="prototype">
  7.        <property name="sid" value="1001"></property>
  8.        <property name="sname" value="张三"></property>
  9.        <property name="gender" value="男"></property>
  10. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  11.     <bean id="student" ></bean>
  12. </beans>Animal createAnimal();
  13. <?xml version="1.0" encoding="UTF-8"?>
  14. <beans xmlns="http://www.springframework.org/schema/beans"
  15.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  16.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  17. <bean  scope="prototype">
  18.        <property name="sid" value="1001"></property>
  19.        <property name="sname" value="张三"></property>
  20.        <property name="gender" value="男"></property>
  21. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  22.     <bean id="student" ></bean>
  23. </beans>Plant createPlant();
  24. }
复制代码
接着,为不同族系创建具体的工厂实现:
  1. public class LandFactory implements NatureFactory {
  2. <?xml version="1.0" encoding="UTF-8"?>
  3. <beans xmlns="http://www.springframework.org/schema/beans"
  4.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  5.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  6. <bean  scope="prototype">
  7.        <property name="sid" value="1001"></property>
  8.        <property name="sname" value="张三"></property>
  9.        <property name="gender" value="男"></property>
  10. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  11.     <bean id="student" ></bean>
  12. </beans>@Override
  13. <?xml version="1.0" encoding="UTF-8"?>
  14. <beans xmlns="http://www.springframework.org/schema/beans"
  15.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  16.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  17. <bean  scope="prototype">
  18.        <property name="sid" value="1001"></property>
  19.        <property name="sname" value="张三"></property>
  20.        <property name="gender" value="男"></property>
  21. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  22.     <bean id="student" ></bean>
  23. </beans>public Animal createAnimal() {
  24. <?xml version="1.0" encoding="UTF-8"?>
  25. <beans xmlns="http://www.springframework.org/schema/beans"
  26.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  27.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  28. <bean  scope="prototype">
  29.        <property name="sid" value="1001"></property>
  30.        <property name="sname" value="张三"></property>
  31.        <property name="gender" value="男"></property>
  32. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  33.     <bean id="student" ></bean>
  34. </beans><?xml version="1.0" encoding="UTF-8"?>
  35. <beans xmlns="http://www.springframework.org/schema/beans"
  36.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  37.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  38. <bean  scope="prototype">
  39.        <property name="sid" value="1001"></property>
  40.        <property name="sname" value="张三"></property>
  41.        <property name="gender" value="男"></property>
  42. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  43.     <bean id="student" ></bean>
  44. </beans>return new LandAnimal();
  45. <?xml version="1.0" encoding="UTF-8"?>
  46. <beans xmlns="http://www.springframework.org/schema/beans"
  47.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  48.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  49. <bean  scope="prototype">
  50.        <property name="sid" value="1001"></property>
  51.        <property name="sname" value="张三"></property>
  52.        <property name="gender" value="男"></property>
  53. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  54.     <bean id="student" ></bean>
  55. </beans>}
  56. <?xml version="1.0" encoding="UTF-8"?>
  57. <beans xmlns="http://www.springframework.org/schema/beans"
  58.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  59.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  60. <bean  scope="prototype">
  61.        <property name="sid" value="1001"></property>
  62.        <property name="sname" value="张三"></property>
  63.        <property name="gender" value="男"></property>
  64. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  65.     <bean id="student" ></bean>
  66. </beans>@Override
  67. <?xml version="1.0" encoding="UTF-8"?>
  68. <beans xmlns="http://www.springframework.org/schema/beans"
  69.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  70.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  71. <bean  scope="prototype">
  72.        <property name="sid" value="1001"></property>
  73.        <property name="sname" value="张三"></property>
  74.        <property name="gender" value="男"></property>
  75. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  76.     <bean id="student" ></bean>
  77. </beans>public Plant createPlant() {
  78. <?xml version="1.0" encoding="UTF-8"?>
  79. <beans xmlns="http://www.springframework.org/schema/beans"
  80.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  81.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  82. <bean  scope="prototype">
  83.        <property name="sid" value="1001"></property>
  84.        <property name="sname" value="张三"></property>
  85.        <property name="gender" value="男"></property>
  86. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  87.     <bean id="student" ></bean>
  88. </beans><?xml version="1.0" encoding="UTF-8"?>
  89. <beans xmlns="http://www.springframework.org/schema/beans"
  90.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  91.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  92. <bean  scope="prototype">
  93.        <property name="sid" value="1001"></property>
  94.        <property name="sname" value="张三"></property>
  95.        <property name="gender" value="男"></property>
  96. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  97.     <bean id="student" ></bean>
  98. </beans>return new LandPlant();
  99. <?xml version="1.0" encoding="UTF-8"?>
  100. <beans xmlns="http://www.springframework.org/schema/beans"
  101.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  102.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  103. <bean  scope="prototype">
  104.        <property name="sid" value="1001"></property>
  105.        <property name="sname" value="张三"></property>
  106.        <property name="gender" value="男"></property>
  107. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  108.     <bean id="student" ></bean>
  109. </beans>}
  110. }
  111. public class AquaticFactory implements NatureFactory {
  112. <?xml version="1.0" encoding="UTF-8"?>
  113. <beans xmlns="http://www.springframework.org/schema/beans"
  114.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  115.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  116. <bean  scope="prototype">
  117.        <property name="sid" value="1001"></property>
  118.        <property name="sname" value="张三"></property>
  119.        <property name="gender" value="男"></property>
  120. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  121.     <bean id="student" ></bean>
  122. </beans>@Override
  123. <?xml version="1.0" encoding="UTF-8"?>
  124. <beans xmlns="http://www.springframework.org/schema/beans"
  125.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  126.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  127. <bean  scope="prototype">
  128.        <property name="sid" value="1001"></property>
  129.        <property name="sname" value="张三"></property>
  130.        <property name="gender" value="男"></property>
  131. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  132.     <bean id="student" ></bean>
  133. </beans>public Animal createAnimal() {
  134. <?xml version="1.0" encoding="UTF-8"?>
  135. <beans xmlns="http://www.springframework.org/schema/beans"
  136.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  137.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  138. <bean  scope="prototype">
  139.        <property name="sid" value="1001"></property>
  140.        <property name="sname" value="张三"></property>
  141.        <property name="gender" value="男"></property>
  142. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  143.     <bean id="student" ></bean>
  144. </beans><?xml version="1.0" encoding="UTF-8"?>
  145. <beans xmlns="http://www.springframework.org/schema/beans"
  146.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  147.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  148. <bean  scope="prototype">
  149.        <property name="sid" value="1001"></property>
  150.        <property name="sname" value="张三"></property>
  151.        <property name="gender" value="男"></property>
  152. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  153.     <bean id="student" ></bean>
  154. </beans>return new AquaticAnimal();
  155. <?xml version="1.0" encoding="UTF-8"?>
  156. <beans xmlns="http://www.springframework.org/schema/beans"
  157.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  158.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  159. <bean  scope="prototype">
  160.        <property name="sid" value="1001"></property>
  161.        <property name="sname" value="张三"></property>
  162.        <property name="gender" value="男"></property>
  163. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  164.     <bean id="student" ></bean>
  165. </beans>}
  166. <?xml version="1.0" encoding="UTF-8"?>
  167. <beans xmlns="http://www.springframework.org/schema/beans"
  168.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  169.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  170. <bean  scope="prototype">
  171.        <property name="sid" value="1001"></property>
  172.        <property name="sname" value="张三"></property>
  173.        <property name="gender" value="男"></property>
  174. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  175.     <bean id="student" ></bean>
  176. </beans>@Override
  177. <?xml version="1.0" encoding="UTF-8"?>
  178. <beans xmlns="http://www.springframework.org/schema/beans"
  179.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  180.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  181. <bean  scope="prototype">
  182.        <property name="sid" value="1001"></property>
  183.        <property name="sname" value="张三"></property>
  184.        <property name="gender" value="男"></property>
  185. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  186.     <bean id="student" ></bean>
  187. </beans>public Plant createPlant() {
  188. <?xml version="1.0" encoding="UTF-8"?>
  189. <beans xmlns="http://www.springframework.org/schema/beans"
  190.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  191.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  192. <bean  scope="prototype">
  193.        <property name="sid" value="1001"></property>
  194.        <property name="sname" value="张三"></property>
  195.        <property name="gender" value="男"></property>
  196. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  197.     <bean id="student" ></bean>
  198. </beans><?xml version="1.0" encoding="UTF-8"?>
  199. <beans xmlns="http://www.springframework.org/schema/beans"
  200.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  201.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  202. <bean  scope="prototype">
  203.        <property name="sid" value="1001"></property>
  204.        <property name="sname" value="张三"></property>
  205.        <property name="gender" value="男"></property>
  206. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  207.     <bean id="student" ></bean>
  208. </beans>return new AquaticPlant();
  209. <?xml version="1.0" encoding="UTF-8"?>
  210. <beans xmlns="http://www.springframework.org/schema/beans"
  211.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  212.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  213. <bean  scope="prototype">
  214.        <property name="sid" value="1001"></property>
  215.        <property name="sname" value="张三"></property>
  216.        <property name="gender" value="男"></property>
  217. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  218.     <bean id="student" ></bean>
  219. </beans>}
  220. }
复制代码
末了,在主方法中,我们可以使用这些抽象工厂类来创建不同族系的Animal和Plant实例:
  1. public class Main {
  2. <?xml version="1.0" encoding="UTF-8"?>
  3. <beans xmlns="http://www.springframework.org/schema/beans"
  4.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  5.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  6. <bean  scope="prototype">
  7.        <property name="sid" value="1001"></property>
  8.        <property name="sname" value="张三"></property>
  9.        <property name="gender" value="男"></property>
  10. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  11.     <bean id="student" ></bean>
  12. </beans>public static void main(String[] args) {
  13. <?xml version="1.0" encoding="UTF-8"?>
  14. <beans xmlns="http://www.springframework.org/schema/beans"
  15.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  16.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  17. <bean  scope="prototype">
  18.        <property name="sid" value="1001"></property>
  19.        <property name="sname" value="张三"></property>
  20.        <property name="gender" value="男"></property>
  21. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  22.     <bean id="student" ></bean>
  23. </beans><?xml version="1.0" encoding="UTF-8"?>
  24. <beans xmlns="http://www.springframework.org/schema/beans"
  25.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  26.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  27. <bean  scope="prototype">
  28.        <property name="sid" value="1001"></property>
  29.        <property name="sname" value="张三"></property>
  30.        <property name="gender" value="男"></property>
  31. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  32.     <bean id="student" ></bean>
  33. </beans>NatureFactory landFactory = new LandFactory();
  34. <?xml version="1.0" encoding="UTF-8"?>
  35. <beans xmlns="http://www.springframework.org/schema/beans"
  36.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  37.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  38. <bean  scope="prototype">
  39.        <property name="sid" value="1001"></property>
  40.        <property name="sname" value="张三"></property>
  41.        <property name="gender" value="男"></property>
  42. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  43.     <bean id="student" ></bean>
  44. </beans><?xml version="1.0" encoding="UTF-8"?>
  45. <beans xmlns="http://www.springframework.org/schema/beans"
  46.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  47.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  48. <bean  scope="prototype">
  49.        <property name="sid" value="1001"></property>
  50.        <property name="sname" value="张三"></property>
  51.        <property name="gender" value="男"></property>
  52. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  53.     <bean id="student" ></bean>
  54. </beans>Animal landAnimal = landFactory.createAnimal();
  55. <?xml version="1.0" encoding="UTF-8"?>
  56. <beans xmlns="http://www.springframework.org/schema/beans"
  57.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  58.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  59. <bean  scope="prototype">
  60.        <property name="sid" value="1001"></property>
  61.        <property name="sname" value="张三"></property>
  62.        <property name="gender" value="男"></property>
  63. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  64.     <bean id="student" ></bean>
  65. </beans><?xml version="1.0" encoding="UTF-8"?>
  66. <beans xmlns="http://www.springframework.org/schema/beans"
  67.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  68.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  69. <bean  scope="prototype">
  70.        <property name="sid" value="1001"></property>
  71.        <property name="sname" value="张三"></property>
  72.        <property name="gender" value="男"></property>
  73. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  74.     <bean id="student" ></bean>
  75. </beans>Plant landPlant = landFactory.createPlant();
  76. <?xml version="1.0" encoding="UTF-8"?>
  77. <beans xmlns="http://www.springframework.org/schema/beans"
  78.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  79.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  80. <bean  scope="prototype">
  81.        <property name="sid" value="1001"></property>
  82.        <property name="sname" value="张三"></property>
  83.        <property name="gender" value="男"></property>
  84. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  85.     <bean id="student" ></bean>
  86. </beans><?xml version="1.0" encoding="UTF-8"?>
  87. <beans xmlns="http://www.springframework.org/schema/beans"
  88.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  89.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  90. <bean  scope="prototype">
  91.        <property name="sid" value="1001"></property>
  92.        <property name="sname" value="张三"></property>
  93.        <property name="gender" value="男"></property>
  94. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  95.     <bean id="student" ></bean>
  96. </beans>landAnimal.speak();
  97. <?xml version="1.0" encoding="UTF-8"?>
  98. <beans xmlns="http://www.springframework.org/schema/beans"
  99.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  100.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  101. <bean  scope="prototype">
  102.        <property name="sid" value="1001"></property>
  103.        <property name="sname" value="张三"></property>
  104.        <property name="gender" value="男"></property>
  105. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  106.     <bean id="student" ></bean>
  107. </beans><?xml version="1.0" encoding="UTF-8"?>
  108. <beans xmlns="http://www.springframework.org/schema/beans"
  109.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  110.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  111. <bean  scope="prototype">
  112.        <property name="sid" value="1001"></property>
  113.        <property name="sname" value="张三"></property>
  114.        <property name="gender" value="男"></property>
  115. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  116.     <bean id="student" ></bean>
  117. </beans>landPlant.grow();
  118. <?xml version="1.0" encoding="UTF-8"?>
  119. <beans xmlns="http://www.springframework.org/schema/beans"
  120.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  121.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  122. <bean  scope="prototype">
  123.        <property name="sid" value="1001"></property>
  124.        <property name="sname" value="张三"></property>
  125.        <property name="gender" value="男"></property>
  126. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  127.     <bean id="student" ></bean>
  128. </beans><?xml version="1.0" encoding="UTF-8"?>
  129. <beans xmlns="http://www.springframework.org/schema/beans"
  130.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  131.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  132. <bean  scope="prototype">
  133.        <property name="sid" value="1001"></property>
  134.        <property name="sname" value="张三"></property>
  135.        <property name="gender" value="男"></property>
  136. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  137.     <bean id="student" ></bean>
  138. </beans>NatureFactory aquaticFactory = new AquaticFactory();
  139. <?xml version="1.0" encoding="UTF-8"?>
  140. <beans xmlns="http://www.springframework.org/schema/beans"
  141.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  142.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  143. <bean  scope="prototype">
  144.        <property name="sid" value="1001"></property>
  145.        <property name="sname" value="张三"></property>
  146.        <property name="gender" value="男"></property>
  147. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  148.     <bean id="student" ></bean>
  149. </beans><?xml version="1.0" encoding="UTF-8"?>
  150. <beans xmlns="http://www.springframework.org/schema/beans"
  151.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  152.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  153. <bean  scope="prototype">
  154.        <property name="sid" value="1001"></property>
  155.        <property name="sname" value="张三"></property>
  156.        <property name="gender" value="男"></property>
  157. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  158.     <bean id="student" ></bean>
  159. </beans>Animal aquaticAnimal = aquaticFactory.createAnimal();
  160. <?xml version="1.0" encoding="UTF-8"?>
  161. <beans xmlns="http://www.springframework.org/schema/beans"
  162.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  163.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  164. <bean  scope="prototype">
  165.        <property name="sid" value="1001"></property>
  166.        <property name="sname" value="张三"></property>
  167.        <property name="gender" value="男"></property>
  168. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  169.     <bean id="student" ></bean>
  170. </beans><?xml version="1.0" encoding="UTF-8"?>
  171. <beans xmlns="http://www.springframework.org/schema/beans"
  172.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  173.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  174. <bean  scope="prototype">
  175.        <property name="sid" value="1001"></property>
  176.        <property name="sname" value="张三"></property>
  177.        <property name="gender" value="男"></property>
  178. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  179.     <bean id="student" ></bean>
  180. </beans>Plant aquaticPlant = aquaticFactory.createPlant();
  181. <?xml version="1.0" encoding="UTF-8"?>
  182. <beans xmlns="http://www.springframework.org/schema/beans"
  183.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  184.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  185. <bean  scope="prototype">
  186.        <property name="sid" value="1001"></property>
  187.        <property name="sname" value="张三"></property>
  188.        <property name="gender" value="男"></property>
  189. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  190.     <bean id="student" ></bean>
  191. </beans><?xml version="1.0" encoding="UTF-8"?>
  192. <beans xmlns="http://www.springframework.org/schema/beans"
  193.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  194.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  195. <bean  scope="prototype">
  196.        <property name="sid" value="1001"></property>
  197.        <property name="sname" value="张三"></property>
  198.        <property name="gender" value="男"></property>
  199. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  200.     <bean id="student" ></bean>
  201. </beans>aquaticAnimal.speak();
  202. <?xml version="1.0" encoding="UTF-8"?>
  203. <beans xmlns="http://www.springframework.org/schema/beans"
  204.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  205.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  206. <bean  scope="prototype">
  207.        <property name="sid" value="1001"></property>
  208.        <property name="sname" value="张三"></property>
  209.        <property name="gender" value="男"></property>
  210. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  211.     <bean id="student" ></bean>
  212. </beans><?xml version="1.0" encoding="UTF-8"?>
  213. <beans xmlns="http://www.springframework.org/schema/beans"
  214.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  215.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  216. <bean  scope="prototype">
  217.        <property name="sid" value="1001"></property>
  218.        <property name="sname" value="张三"></property>
  219.        <property name="gender" value="男"></property>
  220. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  221.     <bean id="student" ></bean>
  222. </beans>aquaticPlant.grow();
  223. <?xml version="1.0" encoding="UTF-8"?>
  224. <beans xmlns="http://www.springframework.org/schema/beans"
  225.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  226.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  227. <bean  scope="prototype">
  228.        <property name="sid" value="1001"></property>
  229.        <property name="sname" value="张三"></property>
  230.        <property name="gender" value="男"></property>
  231. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  232.     <bean id="student" ></bean>
  233. </beans>}
  234. }
复制代码
通过使用抽象工厂模式,您可以轻松地在不同的族系之间切换,同时保持代码的可扩展性和封装
2.单例模式

​        1.饿汉式(可用)
​<bean ></bean>       
<bean  id="myLogger"></bean>


<aop:aspectj-autoproxy></aop:aspectj-autoproxy>        饿汉式单例模式是一种创建型设计模式,它在类加载时就创建了对象实例,并确保只有一个实例存在.
  1. public class Singleton {
  2. <?xml version="1.0" encoding="UTF-8"?>
  3. <beans xmlns="http://www.springframework.org/schema/beans"
  4.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  5.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  6. <bean  scope="prototype">
  7.        <property name="sid" value="1001"></property>
  8.        <property name="sname" value="张三"></property>
  9.        <property name="gender" value="男"></property>
  10. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  11.     <bean id="student" ></bean>
  12. </beans>// 在类加载时创建唯一的实例
  13. <?xml version="1.0" encoding="UTF-8"?>
  14. <beans xmlns="http://www.springframework.org/schema/beans"
  15.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  16.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  17. <bean  scope="prototype">
  18.        <property name="sid" value="1001"></property>
  19.        <property name="sname" value="张三"></property>
  20.        <property name="gender" value="男"></property>
  21. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  22.     <bean id="student" ></bean>
  23. </beans>private static final Singleton INSTANCE = new Singleton();
  24. <?xml version="1.0" encoding="UTF-8"?>
  25. <beans xmlns="http://www.springframework.org/schema/beans"
  26.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  27.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  28. <bean  scope="prototype">
  29.        <property name="sid" value="1001"></property>
  30.        <property name="sname" value="张三"></property>
  31.        <property name="gender" value="男"></property>
  32. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  33.     <bean id="student" ></bean>
  34. </beans>// 将构造方法设为私有,防止外部创建新实例
  35. <?xml version="1.0" encoding="UTF-8"?>
  36. <beans xmlns="http://www.springframework.org/schema/beans"
  37.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  38.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  39. <bean  scope="prototype">
  40.        <property name="sid" value="1001"></property>
  41.        <property name="sname" value="张三"></property>
  42.        <property name="gender" value="男"></property>
  43. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  44.     <bean id="student" ></bean>
  45. </beans>private Singleton() {}
  46. <?xml version="1.0" encoding="UTF-8"?>
  47. <beans xmlns="http://www.springframework.org/schema/beans"
  48.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  49.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  50. <bean  scope="prototype">
  51.        <property name="sid" value="1001"></property>
  52.        <property name="sname" value="张三"></property>
  53.        <property name="gender" value="男"></property>
  54. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  55.     <bean id="student" ></bean>
  56. </beans>// 提供获取唯一实例的公共方法
  57. <?xml version="1.0" encoding="UTF-8"?>
  58. <beans xmlns="http://www.springframework.org/schema/beans"
  59.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  60.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  61. <bean  scope="prototype">
  62.        <property name="sid" value="1001"></property>
  63.        <property name="sname" value="张三"></property>
  64.        <property name="gender" value="男"></property>
  65. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  66.     <bean id="student" ></bean>
  67. </beans>public static Singleton getInstance() {
  68. <?xml version="1.0" encoding="UTF-8"?>
  69. <beans xmlns="http://www.springframework.org/schema/beans"
  70.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  71.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  72. <bean  scope="prototype">
  73.        <property name="sid" value="1001"></property>
  74.        <property name="sname" value="张三"></property>
  75.        <property name="gender" value="男"></property>
  76. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  77.     <bean id="student" ></bean>
  78. </beans><?xml version="1.0" encoding="UTF-8"?>
  79. <beans xmlns="http://www.springframework.org/schema/beans"
  80.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  81.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  82. <bean  scope="prototype">
  83.        <property name="sid" value="1001"></property>
  84.        <property name="sname" value="张三"></property>
  85.        <property name="gender" value="男"></property>
  86. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  87.     <bean id="student" ></bean>
  88. </beans>return INSTANCE;
  89. <?xml version="1.0" encoding="UTF-8"?>
  90. <beans xmlns="http://www.springframework.org/schema/beans"
  91.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  92.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  93. <bean  scope="prototype">
  94.        <property name="sid" value="1001"></property>
  95.        <property name="sname" value="张三"></property>
  96.        <property name="gender" value="男"></property>
  97. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  98.     <bean id="student" ></bean>
  99. </beans>}
  100. }
复制代码
  1. public class Main {
  2. <?xml version="1.0" encoding="UTF-8"?>
  3. <beans xmlns="http://www.springframework.org/schema/beans"
  4.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  5.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  6. <bean  scope="prototype">
  7.        <property name="sid" value="1001"></property>
  8.        <property name="sname" value="张三"></property>
  9.        <property name="gender" value="男"></property>
  10. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  11.     <bean id="student" ></bean>
  12. </beans>public static void main(String[] args) {
  13. <?xml version="1.0" encoding="UTF-8"?>
  14. <beans xmlns="http://www.springframework.org/schema/beans"
  15.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  16.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  17. <bean  scope="prototype">
  18.        <property name="sid" value="1001"></property>
  19.        <property name="sname" value="张三"></property>
  20.        <property name="gender" value="男"></property>
  21. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  22.     <bean id="student" ></bean>
  23. </beans><?xml version="1.0" encoding="UTF-8"?>
  24. <beans xmlns="http://www.springframework.org/schema/beans"
  25.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  26.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  27. <bean  scope="prototype">
  28.        <property name="sid" value="1001"></property>
  29.        <property name="sname" value="张三"></property>
  30.        <property name="gender" value="男"></property>
  31. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  32.     <bean id="student" ></bean>
  33. </beans>Singleton singletonInstance = Singleton.getInstance();
  34. <?xml version="1.0" encoding="UTF-8"?>
  35. <beans xmlns="http://www.springframework.org/schema/beans"
  36.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  37.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  38. <bean  scope="prototype">
  39.        <property name="sid" value="1001"></property>
  40.        <property name="sname" value="张三"></property>
  41.        <property name="gender" value="男"></property>
  42. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  43.     <bean id="student" ></bean>
  44. </beans>}
  45. }
复制代码
饿汉式单例模式在类加载时就创建了实例,这意味着即使您从未使用过该实例,它也会占用内存。这可能导致资源浪费,特殊是在实例创建成本较高的情况下.
​        2.懒汉式(不可用,线程不安全)
​<bean ></bean>       
<bean  id="myLogger"></bean>


<aop:aspectj-autoproxy></aop:aspectj-autoproxy>        懒汉式单例模式是一种创建型设计模式,它在第一次哀求实例时才创建唯一的实例,并确保整个应用程序中仅存在一个实例.
  1. public class Singleton {
  2. <?xml version="1.0" encoding="UTF-8"?>
  3. <beans xmlns="http://www.springframework.org/schema/beans"
  4.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  5.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  6. <bean  scope="prototype">
  7.        <property name="sid" value="1001"></property>
  8.        <property name="sname" value="张三"></property>
  9.        <property name="gender" value="男"></property>
  10. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  11.     <bean id="student" ></bean>
  12. </beans>// 初始化唯一实例为空
  13. <?xml version="1.0" encoding="UTF-8"?>
  14. <beans xmlns="http://www.springframework.org/schema/beans"
  15.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  16.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  17. <bean  scope="prototype">
  18.        <property name="sid" value="1001"></property>
  19.        <property name="sname" value="张三"></property>
  20.        <property name="gender" value="男"></property>
  21. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  22.     <bean id="student" ></bean>
  23. </beans>private static Singleton instance = null;
  24. <?xml version="1.0" encoding="UTF-8"?>
  25. <beans xmlns="http://www.springframework.org/schema/beans"
  26.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  27.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  28. <bean  scope="prototype">
  29.        <property name="sid" value="1001"></property>
  30.        <property name="sname" value="张三"></property>
  31.        <property name="gender" value="男"></property>
  32. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  33.     <bean id="student" ></bean>
  34. </beans>// 将构造方法设为私有,防止外部创建新实例
  35. <?xml version="1.0" encoding="UTF-8"?>
  36. <beans xmlns="http://www.springframework.org/schema/beans"
  37.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  38.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  39. <bean  scope="prototype">
  40.        <property name="sid" value="1001"></property>
  41.        <property name="sname" value="张三"></property>
  42.        <property name="gender" value="男"></property>
  43. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  44.     <bean id="student" ></bean>
  45. </beans>private Singleton() {}
  46. <?xml version="1.0" encoding="UTF-8"?>
  47. <beans xmlns="http://www.springframework.org/schema/beans"
  48.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  49.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  50. <bean  scope="prototype">
  51.        <property name="sid" value="1001"></property>
  52.        <property name="sname" value="张三"></property>
  53.        <property name="gender" value="男"></property>
  54. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  55.     <bean id="student" ></bean>
  56. </beans>// 提供获取唯一实例的公共方法
  57. <?xml version="1.0" encoding="UTF-8"?>
  58. <beans xmlns="http://www.springframework.org/schema/beans"
  59.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  60.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  61. <bean  scope="prototype">
  62.        <property name="sid" value="1001"></property>
  63.        <property name="sname" value="张三"></property>
  64.        <property name="gender" value="男"></property>
  65. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  66.     <bean id="student" ></bean>
  67. </beans>public static synchronized Singleton getInstance() {
  68. <?xml version="1.0" encoding="UTF-8"?>
  69. <beans xmlns="http://www.springframework.org/schema/beans"
  70.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  71.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  72. <bean  scope="prototype">
  73.        <property name="sid" value="1001"></property>
  74.        <property name="sname" value="张三"></property>
  75.        <property name="gender" value="男"></property>
  76. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  77.     <bean id="student" ></bean>
  78. </beans><?xml version="1.0" encoding="UTF-8"?>
  79. <beans xmlns="http://www.springframework.org/schema/beans"
  80.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  81.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  82. <bean  scope="prototype">
  83.        <property name="sid" value="1001"></property>
  84.        <property name="sname" value="张三"></property>
  85.        <property name="gender" value="男"></property>
  86. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  87.     <bean id="student" ></bean>
  88. </beans>if (instance == null) {
  89. <?xml version="1.0" encoding="UTF-8"?>
  90. <beans xmlns="http://www.springframework.org/schema/beans"
  91.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  92.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  93. <bean  scope="prototype">
  94.        <property name="sid" value="1001"></property>
  95.        <property name="sname" value="张三"></property>
  96.        <property name="gender" value="男"></property>
  97. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  98.     <bean id="student" ></bean>
  99. </beans><?xml version="1.0" encoding="UTF-8"?>
  100. <beans xmlns="http://www.springframework.org/schema/beans"
  101.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  102.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  103. <bean  scope="prototype">
  104.        <property name="sid" value="1001"></property>
  105.        <property name="sname" value="张三"></property>
  106.        <property name="gender" value="男"></property>
  107. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  108.     <bean id="student" ></bean>
  109. </beans><?xml version="1.0" encoding="UTF-8"?>
  110. <beans xmlns="http://www.springframework.org/schema/beans"
  111.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  112.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  113. <bean  scope="prototype">
  114.        <property name="sid" value="1001"></property>
  115.        <property name="sname" value="张三"></property>
  116.        <property name="gender" value="男"></property>
  117. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  118.     <bean id="student" ></bean>
  119. </beans>instance = new Singleton();
  120. <?xml version="1.0" encoding="UTF-8"?>
  121. <beans xmlns="http://www.springframework.org/schema/beans"
  122.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  123.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  124. <bean  scope="prototype">
  125.        <property name="sid" value="1001"></property>
  126.        <property name="sname" value="张三"></property>
  127.        <property name="gender" value="男"></property>
  128. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  129.     <bean id="student" ></bean>
  130. </beans><?xml version="1.0" encoding="UTF-8"?>
  131. <beans xmlns="http://www.springframework.org/schema/beans"
  132.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  133.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  134. <bean  scope="prototype">
  135.        <property name="sid" value="1001"></property>
  136.        <property name="sname" value="张三"></property>
  137.        <property name="gender" value="男"></property>
  138. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  139.     <bean id="student" ></bean>
  140. </beans>}
  141. <?xml version="1.0" encoding="UTF-8"?>
  142. <beans xmlns="http://www.springframework.org/schema/beans"
  143.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  144.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  145. <bean  scope="prototype">
  146.        <property name="sid" value="1001"></property>
  147.        <property name="sname" value="张三"></property>
  148.        <property name="gender" value="男"></property>
  149. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  150.     <bean id="student" ></bean>
  151. </beans><?xml version="1.0" encoding="UTF-8"?>
  152. <beans xmlns="http://www.springframework.org/schema/beans"
  153.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  154.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  155. <bean  scope="prototype">
  156.        <property name="sid" value="1001"></property>
  157.        <property name="sname" value="张三"></property>
  158.        <property name="gender" value="男"></property>
  159. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  160.     <bean id="student" ></bean>
  161. </beans>return instance;
  162. <?xml version="1.0" encoding="UTF-8"?>
  163. <beans xmlns="http://www.springframework.org/schema/beans"
  164.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  165.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  166. <bean  scope="prototype">
  167.        <property name="sid" value="1001"></property>
  168.        <property name="sname" value="张三"></property>
  169.        <property name="gender" value="男"></property>
  170. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  171.     <bean id="student" ></bean>
  172. </beans>}
  173. }
复制代码
​        3.懒汉式(锁方法, 不推荐使用)
​<bean ></bean>       
<bean  id="myLogger"></bean>


<aop:aspectj-autoproxy></aop:aspectj-autoproxy>        同上, 在创建对象的静态方法上加上同步锁synchronized .
​        4.双重检查(推荐使用)
​<bean ></bean>       
<bean  id="myLogger"></bean>


<aop:aspectj-autoproxy></aop:aspectj-autoproxy>        双重检查锁定(Double-Checked Locking,DCL)是一种用于确保在多线程情况下懒汉式单例模式的线程安全性的方法.
  1. public class Singleton {
  2. <?xml version="1.0" encoding="UTF-8"?>
  3. <beans xmlns="http://www.springframework.org/schema/beans"
  4.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  5.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  6. <bean  scope="prototype">
  7.        <property name="sid" value="1001"></property>
  8.        <property name="sname" value="张三"></property>
  9.        <property name="gender" value="男"></property>
  10. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  11.     <bean id="student" ></bean>
  12. </beans>// 使用volatile关键字确保内存可见性
  13. <?xml version="1.0" encoding="UTF-8"?>
  14. <beans xmlns="http://www.springframework.org/schema/beans"
  15.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  16.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  17. <bean  scope="prototype">
  18.        <property name="sid" value="1001"></property>
  19.        <property name="sname" value="张三"></property>
  20.        <property name="gender" value="男"></property>
  21. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  22.     <bean id="student" ></bean>
  23. </beans>private static volatile Singleton instance = null;
  24. <?xml version="1.0" encoding="UTF-8"?>
  25. <beans xmlns="http://www.springframework.org/schema/beans"
  26.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  27.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  28. <bean  scope="prototype">
  29.        <property name="sid" value="1001"></property>
  30.        <property name="sname" value="张三"></property>
  31.        <property name="gender" value="男"></property>
  32. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  33.     <bean id="student" ></bean>
  34. </beans>// 将构造方法设为私有,防止外部创建新实例
  35. <?xml version="1.0" encoding="UTF-8"?>
  36. <beans xmlns="http://www.springframework.org/schema/beans"
  37.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  38.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  39. <bean  scope="prototype">
  40.        <property name="sid" value="1001"></property>
  41.        <property name="sname" value="张三"></property>
  42.        <property name="gender" value="男"></property>
  43. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  44.     <bean id="student" ></bean>
  45. </beans>private Singleton() {}
  46. <?xml version="1.0" encoding="UTF-8"?>
  47. <beans xmlns="http://www.springframework.org/schema/beans"
  48.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  49.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  50. <bean  scope="prototype">
  51.        <property name="sid" value="1001"></property>
  52.        <property name="sname" value="张三"></property>
  53.        <property name="gender" value="男"></property>
  54. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  55.     <bean id="student" ></bean>
  56. </beans>// 提供获取唯一实例的公共方法,并使用双重检查锁定
  57. <?xml version="1.0" encoding="UTF-8"?>
  58. <beans xmlns="http://www.springframework.org/schema/beans"
  59.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  60.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  61. <bean  scope="prototype">
  62.        <property name="sid" value="1001"></property>
  63.        <property name="sname" value="张三"></property>
  64.        <property name="gender" value="男"></property>
  65. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  66.     <bean id="student" ></bean>
  67. </beans>public static Singleton getInstance() {
  68. <?xml version="1.0" encoding="UTF-8"?>
  69. <beans xmlns="http://www.springframework.org/schema/beans"
  70.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  71.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  72. <bean  scope="prototype">
  73.        <property name="sid" value="1001"></property>
  74.        <property name="sname" value="张三"></property>
  75.        <property name="gender" value="男"></property>
  76. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  77.     <bean id="student" ></bean>
  78. </beans><?xml version="1.0" encoding="UTF-8"?>
  79. <beans xmlns="http://www.springframework.org/schema/beans"
  80.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  81.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  82. <bean  scope="prototype">
  83.        <property name="sid" value="1001"></property>
  84.        <property name="sname" value="张三"></property>
  85.        <property name="gender" value="男"></property>
  86. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  87.     <bean id="student" ></bean>
  88. </beans>if (instance == null) {
  89. <?xml version="1.0" encoding="UTF-8"?>
  90. <beans xmlns="http://www.springframework.org/schema/beans"
  91.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  92.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  93. <bean  scope="prototype">
  94.        <property name="sid" value="1001"></property>
  95.        <property name="sname" value="张三"></property>
  96.        <property name="gender" value="男"></property>
  97. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  98.     <bean id="student" ></bean>
  99. </beans><?xml version="1.0" encoding="UTF-8"?>
  100. <beans xmlns="http://www.springframework.org/schema/beans"
  101.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  102.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  103. <bean  scope="prototype">
  104.        <property name="sid" value="1001"></property>
  105.        <property name="sname" value="张三"></property>
  106.        <property name="gender" value="男"></property>
  107. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  108.     <bean id="student" ></bean>
  109. </beans><?xml version="1.0" encoding="UTF-8"?>
  110. <beans xmlns="http://www.springframework.org/schema/beans"
  111.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  112.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  113. <bean  scope="prototype">
  114.        <property name="sid" value="1001"></property>
  115.        <property name="sname" value="张三"></property>
  116.        <property name="gender" value="男"></property>
  117. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  118.     <bean id="student" ></bean>
  119. </beans>synchronized (Singleton.class) {
  120. <?xml version="1.0" encoding="UTF-8"?>
  121. <beans xmlns="http://www.springframework.org/schema/beans"
  122.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  123.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  124. <bean  scope="prototype">
  125.        <property name="sid" value="1001"></property>
  126.        <property name="sname" value="张三"></property>
  127.        <property name="gender" value="男"></property>
  128. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  129.     <bean id="student" ></bean>
  130. </beans><?xml version="1.0" encoding="UTF-8"?>
  131. <beans xmlns="http://www.springframework.org/schema/beans"
  132.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  133.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  134. <bean  scope="prototype">
  135.        <property name="sid" value="1001"></property>
  136.        <property name="sname" value="张三"></property>
  137.        <property name="gender" value="男"></property>
  138. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  139.     <bean id="student" ></bean>
  140. </beans><?xml version="1.0" encoding="UTF-8"?>
  141. <beans xmlns="http://www.springframework.org/schema/beans"
  142.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  143.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  144. <bean  scope="prototype">
  145.        <property name="sid" value="1001"></property>
  146.        <property name="sname" value="张三"></property>
  147.        <property name="gender" value="男"></property>
  148. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  149.     <bean id="student" ></bean>
  150. </beans><?xml version="1.0" encoding="UTF-8"?>
  151. <beans xmlns="http://www.springframework.org/schema/beans"
  152.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  153.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  154. <bean  scope="prototype">
  155.        <property name="sid" value="1001"></property>
  156.        <property name="sname" value="张三"></property>
  157.        <property name="gender" value="男"></property>
  158. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  159.     <bean id="student" ></bean>
  160. </beans>if (instance == null) {
  161. <?xml version="1.0" encoding="UTF-8"?>
  162. <beans xmlns="http://www.springframework.org/schema/beans"
  163.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  164.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  165. <bean  scope="prototype">
  166.        <property name="sid" value="1001"></property>
  167.        <property name="sname" value="张三"></property>
  168.        <property name="gender" value="男"></property>
  169. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  170.     <bean id="student" ></bean>
  171. </beans><?xml version="1.0" encoding="UTF-8"?>
  172. <beans xmlns="http://www.springframework.org/schema/beans"
  173.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  174.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  175. <bean  scope="prototype">
  176.        <property name="sid" value="1001"></property>
  177.        <property name="sname" value="张三"></property>
  178.        <property name="gender" value="男"></property>
  179. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  180.     <bean id="student" ></bean>
  181. </beans><?xml version="1.0" encoding="UTF-8"?>
  182. <beans xmlns="http://www.springframework.org/schema/beans"
  183.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  184.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  185. <bean  scope="prototype">
  186.        <property name="sid" value="1001"></property>
  187.        <property name="sname" value="张三"></property>
  188.        <property name="gender" value="男"></property>
  189. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  190.     <bean id="student" ></bean>
  191. </beans><?xml version="1.0" encoding="UTF-8"?>
  192. <beans xmlns="http://www.springframework.org/schema/beans"
  193.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  194.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  195. <bean  scope="prototype">
  196.        <property name="sid" value="1001"></property>
  197.        <property name="sname" value="张三"></property>
  198.        <property name="gender" value="男"></property>
  199. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  200.     <bean id="student" ></bean>
  201. </beans><?xml version="1.0" encoding="UTF-8"?>
  202. <beans xmlns="http://www.springframework.org/schema/beans"
  203.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  204.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  205. <bean  scope="prototype">
  206.        <property name="sid" value="1001"></property>
  207.        <property name="sname" value="张三"></property>
  208.        <property name="gender" value="男"></property>
  209. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  210.     <bean id="student" ></bean>
  211. </beans>instance = new Singleton();
  212. <?xml version="1.0" encoding="UTF-8"?>
  213. <beans xmlns="http://www.springframework.org/schema/beans"
  214.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  215.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  216. <bean  scope="prototype">
  217.        <property name="sid" value="1001"></property>
  218.        <property name="sname" value="张三"></property>
  219.        <property name="gender" value="男"></property>
  220. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  221.     <bean id="student" ></bean>
  222. </beans><?xml version="1.0" encoding="UTF-8"?>
  223. <beans xmlns="http://www.springframework.org/schema/beans"
  224.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  225.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  226. <bean  scope="prototype">
  227.        <property name="sid" value="1001"></property>
  228.        <property name="sname" value="张三"></property>
  229.        <property name="gender" value="男"></property>
  230. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  231.     <bean id="student" ></bean>
  232. </beans><?xml version="1.0" encoding="UTF-8"?>
  233. <beans xmlns="http://www.springframework.org/schema/beans"
  234.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  235.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  236. <bean  scope="prototype">
  237.        <property name="sid" value="1001"></property>
  238.        <property name="sname" value="张三"></property>
  239.        <property name="gender" value="男"></property>
  240. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  241.     <bean id="student" ></bean>
  242. </beans><?xml version="1.0" encoding="UTF-8"?>
  243. <beans xmlns="http://www.springframework.org/schema/beans"
  244.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  245.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  246. <bean  scope="prototype">
  247.        <property name="sid" value="1001"></property>
  248.        <property name="sname" value="张三"></property>
  249.        <property name="gender" value="男"></property>
  250. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  251.     <bean id="student" ></bean>
  252. </beans>}
  253. <?xml version="1.0" encoding="UTF-8"?>
  254. <beans xmlns="http://www.springframework.org/schema/beans"
  255.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  256.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  257. <bean  scope="prototype">
  258.        <property name="sid" value="1001"></property>
  259.        <property name="sname" value="张三"></property>
  260.        <property name="gender" value="男"></property>
  261. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  262.     <bean id="student" ></bean>
  263. </beans><?xml version="1.0" encoding="UTF-8"?>
  264. <beans xmlns="http://www.springframework.org/schema/beans"
  265.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  266.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  267. <bean  scope="prototype">
  268.        <property name="sid" value="1001"></property>
  269.        <property name="sname" value="张三"></property>
  270.        <property name="gender" value="男"></property>
  271. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  272.     <bean id="student" ></bean>
  273. </beans><?xml version="1.0" encoding="UTF-8"?>
  274. <beans xmlns="http://www.springframework.org/schema/beans"
  275.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  276.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  277. <bean  scope="prototype">
  278.        <property name="sid" value="1001"></property>
  279.        <property name="sname" value="张三"></property>
  280.        <property name="gender" value="男"></property>
  281. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  282.     <bean id="student" ></bean>
  283. </beans>}
  284. <?xml version="1.0" encoding="UTF-8"?>
  285. <beans xmlns="http://www.springframework.org/schema/beans"
  286.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  287.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  288. <bean  scope="prototype">
  289.        <property name="sid" value="1001"></property>
  290.        <property name="sname" value="张三"></property>
  291.        <property name="gender" value="男"></property>
  292. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  293.     <bean id="student" ></bean>
  294. </beans><?xml version="1.0" encoding="UTF-8"?>
  295. <beans xmlns="http://www.springframework.org/schema/beans"
  296.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  297.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  298. <bean  scope="prototype">
  299.        <property name="sid" value="1001"></property>
  300.        <property name="sname" value="张三"></property>
  301.        <property name="gender" value="男"></property>
  302. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  303.     <bean id="student" ></bean>
  304. </beans>}
  305. <?xml version="1.0" encoding="UTF-8"?>
  306. <beans xmlns="http://www.springframework.org/schema/beans"
  307.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  308.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  309. <bean  scope="prototype">
  310.        <property name="sid" value="1001"></property>
  311.        <property name="sname" value="张三"></property>
  312.        <property name="gender" value="男"></property>
  313. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  314.     <bean id="student" ></bean>
  315. </beans><?xml version="1.0" encoding="UTF-8"?>
  316. <beans xmlns="http://www.springframework.org/schema/beans"
  317.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  318.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  319. <bean  scope="prototype">
  320.        <property name="sid" value="1001"></property>
  321.        <property name="sname" value="张三"></property>
  322.        <property name="gender" value="男"></property>
  323. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  324.     <bean id="student" ></bean>
  325. </beans>return instance;
  326. <?xml version="1.0" encoding="UTF-8"?>
  327. <beans xmlns="http://www.springframework.org/schema/beans"
  328.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  329.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  330. <bean  scope="prototype">
  331.        <property name="sid" value="1001"></property>
  332.        <property name="sname" value="张三"></property>
  333.        <property name="gender" value="男"></property>
  334. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  335.     <bean id="student" ></bean>
  336. </beans>}
  337. }
复制代码
​<bean ></bean>       
<bean  id="myLogger"></bean>


<aop:aspectj-autoproxy></aop:aspectj-autoproxy>        首先,我们进行第一次检查:如果instance为空,阐明实例尚未创建,此时需要获取Singleton.class的锁。当线程成功得到锁后,进行第二次检查:确保在其他线程得到锁之前实例仍未被创建。如果instance仍然为空,则创建新的实例;否则,直接返回已创建的实例。
​<bean ></bean>       
<bean  id="myLogger"></bean>


<aop:aspectj-autoproxy></aop:aspectj-autoproxy>        此实现在多线程情况中是线程安全的,并且相对于每次都获取锁的懒汉式单例模式具有更好的性能
​        5.静态内部类(推荐使用)
  1. public class Singleton {
  2.    // 将构造方法设为私有,防止外部创建新实例
  3. <?xml version="1.0" encoding="UTF-8"?>
  4. <beans xmlns="http://www.springframework.org/schema/beans"
  5.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  6.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  7. <bean  scope="prototype">
  8.        <property name="sid" value="1001"></property>
  9.        <property name="sname" value="张三"></property>
  10.        <property name="gender" value="男"></property>
  11. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  12.     <bean id="student" ></bean>
  13. </beans>private Singleton() {}
  14. <?xml version="1.0" encoding="UTF-8"?>
  15. <beans xmlns="http://www.springframework.org/schema/beans"
  16.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  17.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  18. <bean  scope="prototype">
  19.        <property name="sid" value="1001"></property>
  20.        <property name="sname" value="张三"></property>
  21.        <property name="gender" value="男"></property>
  22. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  23.     <bean id="student" ></bean>
  24. </beans>// 静态内部类负责创建唯一实例
  25. <?xml version="1.0" encoding="UTF-8"?>
  26. <beans xmlns="http://www.springframework.org/schema/beans"
  27.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  28.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  29. <bean  scope="prototype">
  30.        <property name="sid" value="1001"></property>
  31.        <property name="sname" value="张三"></property>
  32.        <property name="gender" value="男"></property>
  33. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  34.     <bean id="student" ></bean>
  35. </beans>private static class SingletonHolder {
  36. <?xml version="1.0" encoding="UTF-8"?>
  37. <beans xmlns="http://www.springframework.org/schema/beans"
  38.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  39.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  40. <bean  scope="prototype">
  41.        <property name="sid" value="1001"></property>
  42.        <property name="sname" value="张三"></property>
  43.        <property name="gender" value="男"></property>
  44. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  45.     <bean id="student" ></bean>
  46. </beans><?xml version="1.0" encoding="UTF-8"?>
  47. <beans xmlns="http://www.springframework.org/schema/beans"
  48.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  49.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  50. <bean  scope="prototype">
  51.        <property name="sid" value="1001"></property>
  52.        <property name="sname" value="张三"></property>
  53.        <property name="gender" value="男"></property>
  54. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  55.     <bean id="student" ></bean>
  56. </beans>private static final Singleton INSTANCE = new Singleton();
  57. <?xml version="1.0" encoding="UTF-8"?>
  58. <beans xmlns="http://www.springframework.org/schema/beans"
  59.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  60.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  61. <bean  scope="prototype">
  62.        <property name="sid" value="1001"></property>
  63.        <property name="sname" value="张三"></property>
  64.        <property name="gender" value="男"></property>
  65. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  66.     <bean id="student" ></bean>
  67. </beans>}
  68. <?xml version="1.0" encoding="UTF-8"?>
  69. <beans xmlns="http://www.springframework.org/schema/beans"
  70.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  71.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  72. <bean  scope="prototype">
  73.        <property name="sid" value="1001"></property>
  74.        <property name="sname" value="张三"></property>
  75.        <property name="gender" value="男"></property>
  76. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  77.     <bean id="student" ></bean>
  78. </beans>// 提供获取唯一实例的公共方法
  79. <?xml version="1.0" encoding="UTF-8"?>
  80. <beans xmlns="http://www.springframework.org/schema/beans"
  81.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  82.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  83. <bean  scope="prototype">
  84.        <property name="sid" value="1001"></property>
  85.        <property name="sname" value="张三"></property>
  86.        <property name="gender" value="男"></property>
  87. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  88.     <bean id="student" ></bean>
  89. </beans>public static Singleton getInstance() {
  90. <?xml version="1.0" encoding="UTF-8"?>
  91. <beans xmlns="http://www.springframework.org/schema/beans"
  92.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  93.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  94. <bean  scope="prototype">
  95.        <property name="sid" value="1001"></property>
  96.        <property name="sname" value="张三"></property>
  97.        <property name="gender" value="男"></property>
  98. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  99.     <bean id="student" ></bean>
  100. </beans><?xml version="1.0" encoding="UTF-8"?>
  101. <beans xmlns="http://www.springframework.org/schema/beans"
  102.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  103.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  104. <bean  scope="prototype">
  105.        <property name="sid" value="1001"></property>
  106.        <property name="sname" value="张三"></property>
  107.        <property name="gender" value="男"></property>
  108. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  109.     <bean id="student" ></bean>
  110. </beans>return SingletonHolder.INSTANCE;
  111. <?xml version="1.0" encoding="UTF-8"?>
  112. <beans xmlns="http://www.springframework.org/schema/beans"
  113.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  114.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  115. <bean  scope="prototype">
  116.        <property name="sid" value="1001"></property>
  117.        <property name="sname" value="张三"></property>
  118.        <property name="gender" value="男"></property>
  119. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  120.     <bean id="student" ></bean>
  121. </beans>}
  122. }<bean ></bean>       
  123. <bean  id="myLogger"></bean>
  124. <aop:aspectj-autoproxy></aop:aspectj-autoproxy>               
复制代码
当Singleton类加载时, 由于静态内部类在外部内加载时并不会加载, 而时在静态内部内调用时才加载, 所以该方法并不会像饿汉式那样浪费资源, 同时Java规范保证了静态初始化是线程安全的,因此在类加载时会创建唯一的实例, 所以次方法比力推荐;
​        6.枚举(推荐使用)
  1. public enum Singleton {
  2. <?xml version="1.0" encoding="UTF-8"?>
  3. <beans xmlns="http://www.springframework.org/schema/beans"
  4.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  5.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  6. <bean  scope="prototype">
  7.        <property name="sid" value="1001"></property>
  8.        <property name="sname" value="张三"></property>
  9.        <property name="gender" value="男"></property>
  10. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  11.     <bean id="student" ></bean>
  12. </beans>INSTANCE;
  13. <?xml version="1.0" encoding="UTF-8"?>
  14. <beans xmlns="http://www.springframework.org/schema/beans"
  15.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  16.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  17. <bean  scope="prototype">
  18.        <property name="sid" value="1001"></property>
  19.        <property name="sname" value="张三"></property>
  20.        <property name="gender" value="男"></property>
  21. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  22.     <bean id="student" ></bean>
  23. </beans>// 可以添加其他方法和属性
  24. <?xml version="1.0" encoding="UTF-8"?>
  25. <beans xmlns="http://www.springframework.org/schema/beans"
  26.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  27.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  28. <bean  scope="prototype">
  29.        <property name="sid" value="1001"></property>
  30.        <property name="sname" value="张三"></property>
  31.        <property name="gender" value="男"></property>
  32. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  33.     <bean id="student" ></bean>
  34. </beans>public void doSomething() {
  35. <?xml version="1.0" encoding="UTF-8"?>
  36. <beans xmlns="http://www.springframework.org/schema/beans"
  37.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  38.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  39. <bean  scope="prototype">
  40.        <property name="sid" value="1001"></property>
  41.        <property name="sname" value="张三"></property>
  42.        <property name="gender" value="男"></property>
  43. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  44.     <bean id="student" ></bean>
  45. </beans><?xml version="1.0" encoding="UTF-8"?>
  46. <beans xmlns="http://www.springframework.org/schema/beans"
  47.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  48.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  49. <bean  scope="prototype">
  50.        <property name="sid" value="1001"></property>
  51.        <property name="sname" value="张三"></property>
  52.        <property name="gender" value="男"></property>
  53. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  54.     <bean id="student" ></bean>
  55. </beans>System.out.println("Singleton enum is doing something");
  56. <?xml version="1.0" encoding="UTF-8"?>
  57. <beans xmlns="http://www.springframework.org/schema/beans"
  58.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  59.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  60. <bean  scope="prototype">
  61.        <property name="sid" value="1001"></property>
  62.        <property name="sname" value="张三"></property>
  63.        <property name="gender" value="男"></property>
  64. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  65.     <bean id="student" ></bean>
  66. </beans>}
  67. }
复制代码
  1. public class Main {
  2. <?xml version="1.0" encoding="UTF-8"?>
  3. <beans xmlns="http://www.springframework.org/schema/beans"
  4.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  5.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  6. <bean  scope="prototype">
  7.        <property name="sid" value="1001"></property>
  8.        <property name="sname" value="张三"></property>
  9.        <property name="gender" value="男"></property>
  10. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  11.     <bean id="student" ></bean>
  12. </beans>public static void main(String[] args) {
  13. <?xml version="1.0" encoding="UTF-8"?>
  14. <beans xmlns="http://www.springframework.org/schema/beans"
  15.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  16.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  17. <bean  scope="prototype">
  18.        <property name="sid" value="1001"></property>
  19.        <property name="sname" value="张三"></property>
  20.        <property name="gender" value="男"></property>
  21. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  22.     <bean id="student" ></bean>
  23. </beans><?xml version="1.0" encoding="UTF-8"?>
  24. <beans xmlns="http://www.springframework.org/schema/beans"
  25.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  26.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  27. <bean  scope="prototype">
  28.        <property name="sid" value="1001"></property>
  29.        <property name="sname" value="张三"></property>
  30.        <property name="gender" value="男"></property>
  31. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  32.     <bean id="student" ></bean>
  33. </beans>Singleton singletonInstance = Singleton.INSTANCE;
  34. <?xml version="1.0" encoding="UTF-8"?>
  35. <beans xmlns="http://www.springframework.org/schema/beans"
  36.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  37.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  38. <bean  scope="prototype">
  39.        <property name="sid" value="1001"></property>
  40.        <property name="sname" value="张三"></property>
  41.        <property name="gender" value="男"></property>
  42. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  43.     <bean id="student" ></bean>
  44. </beans><?xml version="1.0" encoding="UTF-8"?>
  45. <beans xmlns="http://www.springframework.org/schema/beans"
  46.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  47.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  48. <bean  scope="prototype">
  49.        <property name="sid" value="1001"></property>
  50.        <property name="sname" value="张三"></property>
  51.        <property name="gender" value="男"></property>
  52. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  53.     <bean id="student" ></bean>
  54. </beans>singletonInstance.doSomething();
  55. <?xml version="1.0" encoding="UTF-8"?>
  56. <beans xmlns="http://www.springframework.org/schema/beans"
  57.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  58.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  59. <bean  scope="prototype">
  60.        <property name="sid" value="1001"></property>
  61.        <property name="sname" value="张三"></property>
  62.        <property name="gender" value="男"></property>
  63. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  64.     <bean id="student" ></bean>
  65. </beans>}
  66. }
复制代码
使用枚举实现单例模式是一种简洁且安全的方法。在Java中,枚举范例可以确保线程安全和实例唯一性;
3.代理模式

​        代理模式是一种布局型设计模式,其目的是通过代理来控制对实际对象的访问。代理通常与实际对象具有相同的接口,并将哀求转发给实际对象,可能会在转发之前或之后执行其他操作;
  1. public interface Subject {
  2. <?xml version="1.0" encoding="UTF-8"?>
  3. <beans xmlns="http://www.springframework.org/schema/beans"
  4.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  5.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  6. <bean  scope="prototype">
  7.        <property name="sid" value="1001"></property>
  8.        <property name="sname" value="张三"></property>
  9.        <property name="gender" value="男"></property>
  10. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  11.     <bean id="student" ></bean>
  12. </beans>void operation();
  13. }
复制代码
  1. public class RealSubject implements Subject {
  2. <?xml version="1.0" encoding="UTF-8"?>
  3. <beans xmlns="http://www.springframework.org/schema/beans"
  4.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  5.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  6. <bean  scope="prototype">
  7.        <property name="sid" value="1001"></property>
  8.        <property name="sname" value="张三"></property>
  9.        <property name="gender" value="男"></property>
  10. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  11.     <bean id="student" ></bean>
  12. </beans>@Override
  13. <?xml version="1.0" encoding="UTF-8"?>
  14. <beans xmlns="http://www.springframework.org/schema/beans"
  15.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  16.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  17. <bean  scope="prototype">
  18.        <property name="sid" value="1001"></property>
  19.        <property name="sname" value="张三"></property>
  20.        <property name="gender" value="男"></property>
  21. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  22.     <bean id="student" ></bean>
  23. </beans>public void operation() {
  24. <?xml version="1.0" encoding="UTF-8"?>
  25. <beans xmlns="http://www.springframework.org/schema/beans"
  26.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  27.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  28. <bean  scope="prototype">
  29.        <property name="sid" value="1001"></property>
  30.        <property name="sname" value="张三"></property>
  31.        <property name="gender" value="男"></property>
  32. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  33.     <bean id="student" ></bean>
  34. </beans><?xml version="1.0" encoding="UTF-8"?>
  35. <beans xmlns="http://www.springframework.org/schema/beans"
  36.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  37.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  38. <bean  scope="prototype">
  39.        <property name="sid" value="1001"></property>
  40.        <property name="sname" value="张三"></property>
  41.        <property name="gender" value="男"></property>
  42. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  43.     <bean id="student" ></bean>
  44. </beans>System.out.println("RealSubject is performing the operation");
  45. <?xml version="1.0" encoding="UTF-8"?>
  46. <beans xmlns="http://www.springframework.org/schema/beans"
  47.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  48.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  49. <bean  scope="prototype">
  50.        <property name="sid" value="1001"></property>
  51.        <property name="sname" value="张三"></property>
  52.        <property name="gender" value="男"></property>
  53. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  54.     <bean id="student" ></bean>
  55. </beans>}
  56. }
复制代码
  1. public class ProxySubject implements Subject {
  2. <?xml version="1.0" encoding="UTF-8"?>
  3. <beans xmlns="http://www.springframework.org/schema/beans"
  4.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  5.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  6. <bean  scope="prototype">
  7.        <property name="sid" value="1001"></property>
  8.        <property name="sname" value="张三"></property>
  9.        <property name="gender" value="男"></property>
  10. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  11.     <bean id="student" ></bean>
  12. </beans>private final RealSubject realSubject;
  13. <?xml version="1.0" encoding="UTF-8"?>
  14. <beans xmlns="http://www.springframework.org/schema/beans"
  15.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  16.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  17. <bean  scope="prototype">
  18.        <property name="sid" value="1001"></property>
  19.        <property name="sname" value="张三"></property>
  20.        <property name="gender" value="男"></property>
  21. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  22.     <bean id="student" ></bean>
  23. </beans>public ProxySubject(RealSubject realSubject) {
  24. <?xml version="1.0" encoding="UTF-8"?>
  25. <beans xmlns="http://www.springframework.org/schema/beans"
  26.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  27.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  28. <bean  scope="prototype">
  29.        <property name="sid" value="1001"></property>
  30.        <property name="sname" value="张三"></property>
  31.        <property name="gender" value="男"></property>
  32. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  33.     <bean id="student" ></bean>
  34. </beans><?xml version="1.0" encoding="UTF-8"?>
  35. <beans xmlns="http://www.springframework.org/schema/beans"
  36.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  37.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  38. <bean  scope="prototype">
  39.        <property name="sid" value="1001"></property>
  40.        <property name="sname" value="张三"></property>
  41.        <property name="gender" value="男"></property>
  42. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  43.     <bean id="student" ></bean>
  44. </beans>this.realSubject = realSubject;
  45. <?xml version="1.0" encoding="UTF-8"?>
  46. <beans xmlns="http://www.springframework.org/schema/beans"
  47.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  48.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  49. <bean  scope="prototype">
  50.        <property name="sid" value="1001"></property>
  51.        <property name="sname" value="张三"></property>
  52.        <property name="gender" value="男"></property>
  53. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  54.     <bean id="student" ></bean>
  55. </beans>}
  56. <?xml version="1.0" encoding="UTF-8"?>
  57. <beans xmlns="http://www.springframework.org/schema/beans"
  58.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  59.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  60. <bean  scope="prototype">
  61.        <property name="sid" value="1001"></property>
  62.        <property name="sname" value="张三"></property>
  63.        <property name="gender" value="男"></property>
  64. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  65.     <bean id="student" ></bean>
  66. </beans>@Override
  67. <?xml version="1.0" encoding="UTF-8"?>
  68. <beans xmlns="http://www.springframework.org/schema/beans"
  69.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  70.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  71. <bean  scope="prototype">
  72.        <property name="sid" value="1001"></property>
  73.        <property name="sname" value="张三"></property>
  74.        <property name="gender" value="男"></property>
  75. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  76.     <bean id="student" ></bean>
  77. </beans>public void operation() {
  78. <?xml version="1.0" encoding="UTF-8"?>
  79. <beans xmlns="http://www.springframework.org/schema/beans"
  80.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  81.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  82. <bean  scope="prototype">
  83.        <property name="sid" value="1001"></property>
  84.        <property name="sname" value="张三"></property>
  85.        <property name="gender" value="男"></property>
  86. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  87.     <bean id="student" ></bean>
  88. </beans><?xml version="1.0" encoding="UTF-8"?>
  89. <beans xmlns="http://www.springframework.org/schema/beans"
  90.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  91.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  92. <bean  scope="prototype">
  93.        <property name="sid" value="1001"></property>
  94.        <property name="sname" value="张三"></property>
  95.        <property name="gender" value="男"></property>
  96. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  97.     <bean id="student" ></bean>
  98. </beans>preOperation();
  99. <?xml version="1.0" encoding="UTF-8"?>
  100. <beans xmlns="http://www.springframework.org/schema/beans"
  101.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  102.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  103. <bean  scope="prototype">
  104.        <property name="sid" value="1001"></property>
  105.        <property name="sname" value="张三"></property>
  106.        <property name="gender" value="男"></property>
  107. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  108.     <bean id="student" ></bean>
  109. </beans><?xml version="1.0" encoding="UTF-8"?>
  110. <beans xmlns="http://www.springframework.org/schema/beans"
  111.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  112.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  113. <bean  scope="prototype">
  114.        <property name="sid" value="1001"></property>
  115.        <property name="sname" value="张三"></property>
  116.        <property name="gender" value="男"></property>
  117. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  118.     <bean id="student" ></bean>
  119. </beans>realSubject.operation();
  120. <?xml version="1.0" encoding="UTF-8"?>
  121. <beans xmlns="http://www.springframework.org/schema/beans"
  122.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  123.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  124. <bean  scope="prototype">
  125.        <property name="sid" value="1001"></property>
  126.        <property name="sname" value="张三"></property>
  127.        <property name="gender" value="男"></property>
  128. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  129.     <bean id="student" ></bean>
  130. </beans><?xml version="1.0" encoding="UTF-8"?>
  131. <beans xmlns="http://www.springframework.org/schema/beans"
  132.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  133.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  134. <bean  scope="prototype">
  135.        <property name="sid" value="1001"></property>
  136.        <property name="sname" value="张三"></property>
  137.        <property name="gender" value="男"></property>
  138. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  139.     <bean id="student" ></bean>
  140. </beans>postOperation();
  141. <?xml version="1.0" encoding="UTF-8"?>
  142. <beans xmlns="http://www.springframework.org/schema/beans"
  143.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  144.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  145. <bean  scope="prototype">
  146.        <property name="sid" value="1001"></property>
  147.        <property name="sname" value="张三"></property>
  148.        <property name="gender" value="男"></property>
  149. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  150.     <bean id="student" ></bean>
  151. </beans>}
  152. <?xml version="1.0" encoding="UTF-8"?>
  153. <beans xmlns="http://www.springframework.org/schema/beans"
  154.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  155.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  156. <bean  scope="prototype">
  157.        <property name="sid" value="1001"></property>
  158.        <property name="sname" value="张三"></property>
  159.        <property name="gender" value="男"></property>
  160. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  161.     <bean id="student" ></bean>
  162. </beans>private void preOperation() {
  163. <?xml version="1.0" encoding="UTF-8"?>
  164. <beans xmlns="http://www.springframework.org/schema/beans"
  165.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  166.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  167. <bean  scope="prototype">
  168.        <property name="sid" value="1001"></property>
  169.        <property name="sname" value="张三"></property>
  170.        <property name="gender" value="男"></property>
  171. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  172.     <bean id="student" ></bean>
  173. </beans><?xml version="1.0" encoding="UTF-8"?>
  174. <beans xmlns="http://www.springframework.org/schema/beans"
  175.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  176.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  177. <bean  scope="prototype">
  178.        <property name="sid" value="1001"></property>
  179.        <property name="sname" value="张三"></property>
  180.        <property name="gender" value="男"></property>
  181. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  182.     <bean id="student" ></bean>
  183. </beans>System.out.println("Executing pre-operation tasks in proxy");
  184. <?xml version="1.0" encoding="UTF-8"?>
  185. <beans xmlns="http://www.springframework.org/schema/beans"
  186.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  187.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  188. <bean  scope="prototype">
  189.        <property name="sid" value="1001"></property>
  190.        <property name="sname" value="张三"></property>
  191.        <property name="gender" value="男"></property>
  192. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  193.     <bean id="student" ></bean>
  194. </beans>}
  195. <?xml version="1.0" encoding="UTF-8"?>
  196. <beans xmlns="http://www.springframework.org/schema/beans"
  197.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  198.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  199. <bean  scope="prototype">
  200.        <property name="sid" value="1001"></property>
  201.        <property name="sname" value="张三"></property>
  202.        <property name="gender" value="男"></property>
  203. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  204.     <bean id="student" ></bean>
  205. </beans>private void postOperation() {
  206. <?xml version="1.0" encoding="UTF-8"?>
  207. <beans xmlns="http://www.springframework.org/schema/beans"
  208.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  209.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  210. <bean  scope="prototype">
  211.        <property name="sid" value="1001"></property>
  212.        <property name="sname" value="张三"></property>
  213.        <property name="gender" value="男"></property>
  214. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  215.     <bean id="student" ></bean>
  216. </beans><?xml version="1.0" encoding="UTF-8"?>
  217. <beans xmlns="http://www.springframework.org/schema/beans"
  218.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  219.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  220. <bean  scope="prototype">
  221.        <property name="sid" value="1001"></property>
  222.        <property name="sname" value="张三"></property>
  223.        <property name="gender" value="男"></property>
  224. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  225.     <bean id="student" ></bean>
  226. </beans>System.out.println("Executing post-operation tasks in proxy");
  227. <?xml version="1.0" encoding="UTF-8"?>
  228. <beans xmlns="http://www.springframework.org/schema/beans"
  229.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  230.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  231. <bean  scope="prototype">
  232.        <property name="sid" value="1001"></property>
  233.        <property name="sname" value="张三"></property>
  234.        <property name="gender" value="男"></property>
  235. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  236.     <bean id="student" ></bean>
  237. </beans>}
  238. }
复制代码
  1. public class Main {
  2. <?xml version="1.0" encoding="UTF-8"?>
  3. <beans xmlns="http://www.springframework.org/schema/beans"
  4.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  5.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  6. <bean  scope="prototype">
  7.        <property name="sid" value="1001"></property>
  8.        <property name="sname" value="张三"></property>
  9.        <property name="gender" value="男"></property>
  10. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  11.     <bean id="student" ></bean>
  12. </beans>public static void main(String[] args) {
  13. <?xml version="1.0" encoding="UTF-8"?>
  14. <beans xmlns="http://www.springframework.org/schema/beans"
  15.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  16.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  17. <bean  scope="prototype">
  18.        <property name="sid" value="1001"></property>
  19.        <property name="sname" value="张三"></property>
  20.        <property name="gender" value="男"></property>
  21. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  22.     <bean id="student" ></bean>
  23. </beans><?xml version="1.0" encoding="UTF-8"?>
  24. <beans xmlns="http://www.springframework.org/schema/beans"
  25.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  26.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  27. <bean  scope="prototype">
  28.        <property name="sid" value="1001"></property>
  29.        <property name="sname" value="张三"></property>
  30.        <property name="gender" value="男"></property>
  31. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  32.     <bean id="student" ></bean>
  33. </beans>RealSubject realSubject = new RealSubject();
  34. <?xml version="1.0" encoding="UTF-8"?>
  35. <beans xmlns="http://www.springframework.org/schema/beans"
  36.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  37.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  38. <bean  scope="prototype">
  39.        <property name="sid" value="1001"></property>
  40.        <property name="sname" value="张三"></property>
  41.        <property name="gender" value="男"></property>
  42. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  43.     <bean id="student" ></bean>
  44. </beans><?xml version="1.0" encoding="UTF-8"?>
  45. <beans xmlns="http://www.springframework.org/schema/beans"
  46.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  47.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  48. <bean  scope="prototype">
  49.        <property name="sid" value="1001"></property>
  50.        <property name="sname" value="张三"></property>
  51.        <property name="gender" value="男"></property>
  52. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  53.     <bean id="student" ></bean>
  54. </beans>ProxySubject proxySubject = new ProxySubject(realSubject);
  55. <?xml version="1.0" encoding="UTF-8"?>
  56. <beans xmlns="http://www.springframework.org/schema/beans"
  57.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  58.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  59. <bean  scope="prototype">
  60.        <property name="sid" value="1001"></property>
  61.        <property name="sname" value="张三"></property>
  62.        <property name="gender" value="男"></property>
  63. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  64.     <bean id="student" ></bean>
  65. </beans><?xml version="1.0" encoding="UTF-8"?>
  66. <beans xmlns="http://www.springframework.org/schema/beans"
  67.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  68.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  69. <bean  scope="prototype">
  70.        <property name="sid" value="1001"></property>
  71.        <property name="sname" value="张三"></property>
  72.        <property name="gender" value="男"></property>
  73. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  74.     <bean id="student" ></bean>
  75. </beans>// 使用代理执行操作,它将执行预/后操作并调用RealSubject的operation()
  76. <?xml version="1.0" encoding="UTF-8"?>
  77. <beans xmlns="http://www.springframework.org/schema/beans"
  78.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  79.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  80. <bean  scope="prototype">
  81.        <property name="sid" value="1001"></property>
  82.        <property name="sname" value="张三"></property>
  83.        <property name="gender" value="男"></property>
  84. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  85.     <bean id="student" ></bean>
  86. </beans><?xml version="1.0" encoding="UTF-8"?>
  87. <beans xmlns="http://www.springframework.org/schema/beans"
  88.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  89.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  90. <bean  scope="prototype">
  91.        <property name="sid" value="1001"></property>
  92.        <property name="sname" value="张三"></property>
  93.        <property name="gender" value="男"></property>
  94. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  95.     <bean id="student" ></bean>
  96. </beans>proxySubject.operation();
  97. <?xml version="1.0" encoding="UTF-8"?>
  98. <beans xmlns="http://www.springframework.org/schema/beans"
  99.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  100.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  101. <bean  scope="prototype">
  102.        <property name="sid" value="1001"></property>
  103.        <property name="sname" value="张三"></property>
  104.        <property name="gender" value="男"></property>
  105. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  106.     <bean id="student" ></bean>
  107. </beans>}
  108. }
复制代码
在实际应用中,代理模式可以被用于实现许多功能,比方安全性检查、日志记录、缓存和远程访问等.
4)了解Spring大家族

​        Spring发展到本日已经形成了一种开发的生态圈,Spring提供了若干个项目,每个项目用于完成特定的功能;官网: Spring | Home
1.spring framework

​<bean ></bean>       
<bean  id="myLogger"></bean>


<aop:aspectj-autoproxy></aop:aspectj-autoproxy>        也就是我们经常说的spring框架,紧张分为IOC和AOP两大块;
2.spring boot

​<bean ></bean>       
<bean  id="myLogger"></bean>


<aop:aspectj-autoproxy></aop:aspectj-autoproxy>        它的目标是简化Spring应用和服务的创建、开发与摆设,简化了配置文件,使用嵌入式web服务器,含有诸多开箱即用的微服务功能,可以和spring cloud联合摆设。
​<bean ></bean>       
<bean  id="myLogger"></bean>


<aop:aspectj-autoproxy></aop:aspectj-autoproxy>        Spring Boot的焦点头脑是约定大于配置,应用只需要很少的配置即可,简化了应用开发模式。
3.Spring Data

​<bean ></bean>       
<bean  id="myLogger"></bean>


<aop:aspectj-autoproxy></aop:aspectj-autoproxy>        是一个数据访问及操作的工具集,封装了多种数据源的操作本领,包括:jdbc、Redis、MongoDB等
4.Spring Cloud

​<bean ></bean>       
<bean  id="myLogger"></bean>


<aop:aspectj-autoproxy></aop:aspectj-autoproxy>        是一套完备的微服务解决方案,是一系列不同功能的微服务框架的集合
5. Spring Security

​<bean ></bean>       
<bean  id="myLogger"></bean>


<aop:aspectj-autoproxy></aop:aspectj-autoproxy>        紧张用于快速构建安全的应用程序和服务, 负责进行应用程序的认证, 授权;
5)spring framework构成

​<bean ></bean>       
<bean  id="myLogger"></bean>


<aop:aspectj-autoproxy></aop:aspectj-autoproxy>                spring框架分为两大块, IOC和AOP;
​<bean ></bean>       
<bean  id="myLogger"></bean>


<aop:aspectj-autoproxy></aop:aspectj-autoproxy>                spring框架包含一下几大模块:

1、 Core Container(焦点容器)
​<bean ></bean>       
<bean  id="myLogger"></bean>


<aop:aspectj-autoproxy></aop:aspectj-autoproxy>        Beans模块:提供了BeanFactory,是工厂模式的经典实现,Spring将管理对象称为Bean。
​<bean ></bean>       
<bean  id="myLogger"></bean>


<aop:aspectj-autoproxy></aop:aspectj-autoproxy>        Core焦点模块:提供了Spring框架的基本构成部门,包括IoC和DI功能。
​<bean ></bean>       
<bean  id="myLogger"></bean>


<aop:aspectj-autoproxy></aop:aspectj-autoproxy>        Context上下文模块:创建在Core和Beans模块的基础之上,它是访问定义和配置的任何对象的媒介。
​<bean ></bean>       
<bean  id="myLogger"></bean>


<aop:aspectj-autoproxy></aop:aspectj-autoproxy>        SpEL模块:它提供了Spring Expression Language支持,是运行时查询和操作对象图的强盛的表达式语言
2、Data Access/Integration(数据访问/集成)
​<bean ></bean>       
<bean  id="myLogger"></bean>


<aop:aspectj-autoproxy></aop:aspectj-autoproxy>        JDBC模块:提供了一个JDBC的抽象层,大幅度地减少了在开发过程中对数据库操作的编码。
​<bean ></bean>       
<bean  id="myLogger"></bean>


<aop:aspectj-autoproxy></aop:aspectj-autoproxy>        ORM模块:对流行的对象关系映射API,包括JPA、JDO和Hibernate提供了集成层支持。
​<bean ></bean>       
<bean  id="myLogger"></bean>


<aop:aspectj-autoproxy></aop:aspectj-autoproxy>        OXM模块:提供了一个支持对象/ XML映射的抽象层实现,如JAXB、Castor、XMLBeans、JiBX和XStream。
​<bean ></bean>       
<bean  id="myLogger"></bean>


<aop:aspectj-autoproxy></aop:aspectj-autoproxy>        JMS 模块:指 Java 消息通报服务,包含使用和产生信息的特性,自 4.1 版本后支持与Spring-message模块的集成。
​<bean ></bean>       
<bean  id="myLogger"></bean>


<aop:aspectj-autoproxy></aop:aspectj-autoproxy>        Transactions事务模块:支持对实现特殊接口以及所有POJO类的编程和声明式的事务管理。
3、 Web
​<bean ></bean>       
<bean  id="myLogger"></bean>


<aop:aspectj-autoproxy></aop:aspectj-autoproxy>        WebSocket模块:Spring 4.0以后新增的模块,它提供了WebSocket 和SockJS的实现,以及对STOMP的支持。
​<bean ></bean>       
<bean  id="myLogger"></bean>


<aop:aspectj-autoproxy></aop:aspectj-autoproxy>        Servlet模块:也称为Spring-webmvc模块,包含了Spring的模型—视图—控制器(MVC)和REST Web Services实现的Web应用程序。
​<bean ></bean>       
<bean  id="myLogger"></bean>


<aop:aspectj-autoproxy></aop:aspectj-autoproxy>        Web模块:提供了基本的Web开发集成特性,比方:多文件上传功能、使用Servlet监听器来初始化IoC容器以及Web应用上下文。
​<bean ></bean>       
<bean  id="myLogger"></bean>


<aop:aspectj-autoproxy></aop:aspectj-autoproxy>        Portlet模块:提供了在Portlet情况中使用MVC实现,雷同Servlet模块的功能。
4、 其他模块
​<bean ></bean>       
<bean  id="myLogger"></bean>


<aop:aspectj-autoproxy></aop:aspectj-autoproxy>        AOP 模块:提供了面向切面编程实现,允许定义方法拦截器和切入点,将代码按照功能进行分离,以降低耦合性。
​<bean ></bean>       
<bean  id="myLogger"></bean>


<aop:aspectj-autoproxy></aop:aspectj-autoproxy>        Aspects 模块:提供了与AspectJ的集成功能,AspectJ是一个功能强盛且成熟的面向切面编程(AOP)框架。
​<bean ></bean>       
<bean  id="myLogger"></bean>


<aop:aspectj-autoproxy></aop:aspectj-autoproxy>        Instrumentation 模块:提供了类工具的支持和类加载器的实现,可以在特定的应用服务器中使用。
​<bean ></bean>       
<bean  id="myLogger"></bean>


<aop:aspectj-autoproxy></aop:aspectj-autoproxy>        Messaging模块:Spring 4.0以后新增的模块,它提供了对消息通报体系布局和协议的支持。
​<bean ></bean>       
<bean  id="myLogger"></bean>


<aop:aspectj-autoproxy></aop:aspectj-autoproxy>        Test模块:提供了对单元测试和集成测试的支持
2 IoC和DI

1)IoC介绍和使用

​<bean ></bean>       
<bean  id="myLogger"></bean>


<aop:aspectj-autoproxy></aop:aspectj-autoproxy>        IoC(Inversion of Control)控制反转, 它将对象之间的依赖关系与对象本身的创建和管理分脱离来。这有助于降低程序中各个组件之间的耦合度,并提高代码可维护性、可测试性以及扩展性。
​<bean ></bean>       
<bean  id="myLogger"></bean>


<aop:aspectj-autoproxy></aop:aspectj-autoproxy>        在Spring IoC容器中,对象的生命周期由容器进行管理,而不是由对象自己管理。IoC容器负责实例化、配置和装配Bean,然后将这些Bean注入到需要的组件中。使用IoC可以使您专注于业务逻辑的实现,而不必关心底层的对象创建和依赖解析工作。
​<bean ></bean>       
<bean  id="myLogger"></bean>


<aop:aspectj-autoproxy></aop:aspectj-autoproxy>        Spring IoC容器紧张包括两种范例:
​<bean ></bean>       
<bean  id="myLogger"></bean>


<aop:aspectj-autoproxy></aop:aspectj-autoproxy>        1.BeanFactory:BeanFactory是一个简朴的容器,它负责实例化、定位、配置应用程序中的对象,并解决它们之间的依赖关系。XmlBeanFactory是最常用的BeanFactory实现。
​<bean ></bean>       
<bean  id="myLogger"></bean>


<aop:aspectj-autoproxy></aop:aspectj-autoproxy>        2.ApplicationContext:ApplicationContext是BeanFactory的子接口,它为应用程序提供了更多的企业级特性,如消息资源处理、事件发布、声明式事务处理等。通常,我们会使用ApplicationContext作为Spring IoC容器,常见的实现有ClassPathXmlApplicationContext、FileSystemXmlApplicationContext等
IOC简朴示例

导入jar;
  1. public interface GreetingService {
  2.         void sayHello();
  3. }<bean ></bean>       
  4. <bean  id="myLogger"></bean>
  5. <aop:aspectj-autoproxy></aop:aspectj-autoproxy>       
复制代码
  1. public class Student {
  2. <?xml version="1.0" encoding="UTF-8"?>
  3. <beans xmlns="http://www.springframework.org/schema/beans"
  4.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  5.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  6. <bean  scope="prototype">
  7.        <property name="sid" value="1001"></property>
  8.        <property name="sname" value="张三"></property>
  9.        <property name="gender" value="男"></property>
  10. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  11.     <bean id="student" ></bean>
  12. </beans>
  13. <?xml version="1.0" encoding="UTF-8"?>
  14. <beans xmlns="http://www.springframework.org/schema/beans"
  15.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  16.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  17. <bean  scope="prototype">
  18.        <property name="sid" value="1001"></property>
  19.        <property name="sname" value="张三"></property>
  20.        <property name="gender" value="男"></property>
  21. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  22.     <bean id="student" ></bean>
  23. </beans>public void sayHello() {
  24. <?xml version="1.0" encoding="UTF-8"?>
  25. <beans xmlns="http://www.springframework.org/schema/beans"
  26.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  27.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  28. <bean  scope="prototype">
  29.        <property name="sid" value="1001"></property>
  30.        <property name="sname" value="张三"></property>
  31.        <property name="gender" value="男"></property>
  32. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  33.     <bean id="student" ></bean>
  34. </beans><?xml version="1.0" encoding="UTF-8"?>
  35. <beans xmlns="http://www.springframework.org/schema/beans"
  36.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  37.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  38. <bean  scope="prototype">
  39.        <property name="sid" value="1001"></property>
  40.        <property name="sname" value="张三"></property>
  41.        <property name="gender" value="男"></property>
  42. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  43.     <bean id="student" ></bean>
  44. </beans>System.out.println("Hello, Spring IoC!");
  45. <?xml version="1.0" encoding="UTF-8"?>
  46. <beans xmlns="http://www.springframework.org/schema/beans"
  47.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  48.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  49. <bean  scope="prototype">
  50.        <property name="sid" value="1001"></property>
  51.        <property name="sname" value="张三"></property>
  52.        <property name="gender" value="男"></property>
  53. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  54.     <bean id="student" ></bean>
  55. </beans>}
  56. }
复制代码
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <beans xmlns="http://www.springframework.org/schema/beans"
  3.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  4.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  5. <bean  scope="prototype">
  6.        <property name="sid" value="1001"></property>
  7.        <property name="sname" value="张三"></property>
  8.        <property name="gender" value="男"></property>
  9. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  10.     <bean id="student" ></bean>
  11. </beans>
复制代码
  1. public static void main(String[] args) {<?xml version="1.0" encoding="UTF-8"?>
  2. <beans xmlns="http://www.springframework.org/schema/beans"
  3.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  4.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  5. <bean  scope="prototype">
  6.        <property name="sid" value="1001"></property>
  7.        <property name="sname" value="张三"></property>
  8.        <property name="gender" value="男"></property>
  9. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  10.     <bean id="student" ></bean>
  11. </beans><?xml version="1.0" encoding="UTF-8"?>
  12. <beans xmlns="http://www.springframework.org/schema/beans"
  13.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  14.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  15. <bean  scope="prototype">
  16.        <property name="sid" value="1001"></property>
  17.        <property name="sname" value="张三"></property>
  18.        <property name="gender" value="男"></property>
  19. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  20.     <bean id="student" ></bean>
  21. </beans>// 加载Spring配置文件<?xml version="1.0" encoding="UTF-8"?>
  22. <beans xmlns="http://www.springframework.org/schema/beans"
  23.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  24.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  25. <bean  scope="prototype">
  26.        <property name="sid" value="1001"></property>
  27.        <property name="sname" value="张三"></property>
  28.        <property name="gender" value="男"></property>
  29. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  30.     <bean id="student" ></bean>
  31. </beans><?xml version="1.0" encoding="UTF-8"?>
  32. <beans xmlns="http://www.springframework.org/schema/beans"
  33.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  34.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  35. <bean  scope="prototype">
  36.        <property name="sid" value="1001"></property>
  37.        <property name="sname" value="张三"></property>
  38.        <property name="gender" value="男"></property>
  39. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  40.     <bean id="student" ></bean>
  41. </beans>ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");<?xml version="1.0" encoding="UTF-8"?>
  42. <beans xmlns="http://www.springframework.org/schema/beans"
  43.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  44.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  45. <bean  scope="prototype">
  46.        <property name="sid" value="1001"></property>
  47.        <property name="sname" value="张三"></property>
  48.        <property name="gender" value="男"></property>
  49. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  50.     <bean id="student" ></bean>
  51. </beans><?xml version="1.0" encoding="UTF-8"?>
  52. <beans xmlns="http://www.springframework.org/schema/beans"
  53.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  54.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  55. <bean  scope="prototype">
  56.        <property name="sid" value="1001"></property>
  57.        <property name="sname" value="张三"></property>
  58.        <property name="gender" value="男"></property>
  59. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  60.     <bean id="student" ></bean>
  61. </beans>// 获取Bean并使用sayHello()方法<?xml version="1.0" encoding="UTF-8"?>
  62. <beans xmlns="http://www.springframework.org/schema/beans"
  63.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  64.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  65. <bean  scope="prototype">
  66.        <property name="sid" value="1001"></property>
  67.        <property name="sname" value="张三"></property>
  68.        <property name="gender" value="男"></property>
  69. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  70.     <bean id="student" ></bean>
  71. </beans><?xml version="1.0" encoding="UTF-8"?>
  72. <beans xmlns="http://www.springframework.org/schema/beans"
  73.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  74.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  75. <bean  scope="prototype">
  76.        <property name="sid" value="1001"></property>
  77.        <property name="sname" value="张三"></property>
  78.        <property name="gender" value="男"></property>
  79. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  80.     <bean id="student" ></bean>
  81. </beans>Student student = (Student) context.getBean("student");<?xml version="1.0" encoding="UTF-8"?>
  82. <beans xmlns="http://www.springframework.org/schema/beans"
  83.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  84.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  85. <bean  scope="prototype">
  86.        <property name="sid" value="1001"></property>
  87.        <property name="sname" value="张三"></property>
  88.        <property name="gender" value="男"></property>
  89. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  90.     <bean id="student" ></bean>
  91. </beans><?xml version="1.0" encoding="UTF-8"?>
  92. <beans xmlns="http://www.springframework.org/schema/beans"
  93.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  94.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  95. <bean  scope="prototype">
  96.        <property name="sid" value="1001"></property>
  97.        <property name="sname" value="张三"></property>
  98.        <property name="gender" value="男"></property>
  99. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  100.     <bean id="student" ></bean>
  101. </beans>student.sayHello();}
复制代码
bean的作用范围
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <beans xmlns="http://www.springframework.org/schema/beans"
  3.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  4.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  5. <bean  scope="prototype">
  6.        <property name="sid" value="1001"></property>
  7.        <property name="sname" value="张三"></property>
  8.        <property name="gender" value="男"></property>
  9. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  10.     <bean id="student" ></bean>
  11. </beans><?xml version="1.0" encoding="UTF-8"?>
  12. <beans xmlns="http://www.springframework.org/schema/beans"
  13.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  14.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  15. <bean  scope="prototype">
  16.        <property name="sid" value="1001"></property>
  17.        <property name="sname" value="张三"></property>
  18.        <property name="gender" value="男"></property>
  19. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  20.     <bean id="student" ></bean>
  21. </beans><?xml version="1.0" encoding="UTF-8"?>
  22. <beans xmlns="http://www.springframework.org/schema/beans"
  23.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  24.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  25. <bean  scope="prototype">
  26.        <property name="sid" value="1001"></property>
  27.        <property name="sname" value="张三"></property>
  28.        <property name="gender" value="男"></property>
  29. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  30.     <bean id="student" ></bean>
  31. </beans><?xml version="1.0" encoding="UTF-8"?>
  32. <beans xmlns="http://www.springframework.org/schema/beans"
  33.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  34.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  35. <bean  scope="prototype">
  36.        <property name="sid" value="1001"></property>
  37.        <property name="sname" value="张三"></property>
  38.        <property name="gender" value="男"></property>
  39. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  40.     <bean id="student" ></bean>
  41. </beans><?xml version="1.0" encoding="UTF-8"?>
  42. <beans xmlns="http://www.springframework.org/schema/beans"
  43.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  44.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  45. <bean  scope="prototype">
  46.        <property name="sid" value="1001"></property>
  47.        <property name="sname" value="张三"></property>
  48.        <property name="gender" value="男"></property>
  49. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  50.     <bean id="student" ></bean>
  51. </beans>
复制代码
当scope为prototype, 是多例;为singleton大概默认都是单例;
bean的生命周期


  • 实例化:Spring根据配置文件或注解定义创建Bean实例。
  • 属性添补:Spring通过依赖注入将指定的属性值和引用设置到Bean的属性中,这可以是基于构造方法、setter方法或字段的注入。
  • 容器回调(Aware接口):如果Bean实现了某些特定的Aware接口(如BeanNameAware、BeanFactoryAware等),Spring会自动调用相应的回调方法,将容器相关的信息通报给Bean。
  • BeanPostProcessor前置处理:Spring会调用已注册的所有BeanPostProcessor接口实现类的postProcessBeforeInitialization方法,允许您进行自定义处理,比方修改Bean属性或改变Bean引用。
  • 初始化:当Bean的所有属性都设置好后,Spring会检查Bean是否实现了InitializingBean接口,如果实现了该接口,Spring会调用afterPropertiesSet()方法。别的,如果Bean定义中包含init-method属性(XML配置)或@PostConstruct注解(注解配置),也会执行对应的初始化方法。
  • BeanPostProcessor后置处理:Spring会调用已注册的所有BeanPostProcessor接口实现类的postProcessAfterInitialization方法,同样允许您进行自定义处理。
  • Bean准备停当:至此,Bean已经准备好了,可以被应用程序使用。
  • 销毁:当容器关闭时,Spring会检查Bean是否实现了DisposableBean接口,如果实现了该接口,Spring会调用destroy()方法。别的,如果Bean定义中包含destroy-method属性(XML配置)或@PreDestroy注解(注解配置),也会执行对应的销毁方法。
注意:在整个生命周期中,BeanPostProcessor前置/后置处理和Aware接口回调等特性可以通过编程方式自定义,以满足具体需求。
2)DI的介绍和使用

​          依赖注入(Dependency Injection,DI)是Spring框架的焦点概念之一。它是一种将组件之间的依赖关系从组件内部移除的设计模式,使得组件之间的耦合度降低,代码更加机动和可维护.
​          在Spring框架中,DI通过控制反转(Inversion of Control,IoC)容器实现。IoC容器负责管理应用程序中的对象(称为Bean)以及它们之间的依赖关系。简朴来说,DI允许我们将对象的创建和配置委托给IoC容器,并在需要时将这些对象注入其它对象.
​          Spring提供了以下几种紧张的依赖注入方式:

  • 基于构造函数的注入:通过构造函数将依赖项通报给需要它们的类。在XML配置中,使用元素实现;而在基于注解的配置中,可以在构造函数上添加@Autowired注解。
  • 基于Setter方法的注入:通过调用setter方法将依赖项通报给需要它们的类。在XML配置中,使用元素实现;而在基于注解的配置中,可以在setter方法上添加@Autowired注解。
  • 基于字段的注入:直接向类的字段注入依赖项,而无需使用构造函数或setter方法。在基于注解的配置中,可以在字段上添加@Autowired注解。
基于构造函数的注入:

​        导入jar;
​<bean ></bean>       
<bean  id="myLogger"></bean>


<aop:aspectj-autoproxy></aop:aspectj-autoproxy>       


​<bean ></bean>       
<bean  id="myLogger"></bean>


<aop:aspectj-autoproxy></aop:aspectj-autoproxy>        需要进行注入的实体类;
  1. public class Student {<?xml version="1.0" encoding="UTF-8"?>
  2. <beans xmlns="http://www.springframework.org/schema/beans"
  3.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  4.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  5. <bean  scope="prototype">
  6.        <property name="sid" value="1001"></property>
  7.        <property name="sname" value="张三"></property>
  8.        <property name="gender" value="男"></property>
  9. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  10.     <bean id="student" ></bean>
  11. </beans>private  Integer sid;<?xml version="1.0" encoding="UTF-8"?>
  12. <beans xmlns="http://www.springframework.org/schema/beans"
  13.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  14.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  15. <bean  scope="prototype">
  16.        <property name="sid" value="1001"></property>
  17.        <property name="sname" value="张三"></property>
  18.        <property name="gender" value="男"></property>
  19. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  20.     <bean id="student" ></bean>
  21. </beans>private  String sname;<?xml version="1.0" encoding="UTF-8"?>
  22. <beans xmlns="http://www.springframework.org/schema/beans"
  23.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  24.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  25. <bean  scope="prototype">
  26.        <property name="sid" value="1001"></property>
  27.        <property name="sname" value="张三"></property>
  28.        <property name="gender" value="男"></property>
  29. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  30.     <bean id="student" ></bean>
  31. </beans>private  String gender;<?xml version="1.0" encoding="UTF-8"?>
  32. <beans xmlns="http://www.springframework.org/schema/beans"
  33.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  34.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  35. <bean  scope="prototype">
  36.        <property name="sid" value="1001"></property>
  37.        <property name="sname" value="张三"></property>
  38.        <property name="gender" value="男"></property>
  39. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  40.     <bean id="student" ></bean>
  41. </beans>public Student(Integer sid, String sname, String gender) {<?xml version="1.0" encoding="UTF-8"?>
  42. <beans xmlns="http://www.springframework.org/schema/beans"
  43.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  44.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  45. <bean  scope="prototype">
  46.        <property name="sid" value="1001"></property>
  47.        <property name="sname" value="张三"></property>
  48.        <property name="gender" value="男"></property>
  49. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  50.     <bean id="student" ></bean>
  51. </beans><?xml version="1.0" encoding="UTF-8"?>
  52. <beans xmlns="http://www.springframework.org/schema/beans"
  53.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  54.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  55. <bean  scope="prototype">
  56.        <property name="sid" value="1001"></property>
  57.        <property name="sname" value="张三"></property>
  58.        <property name="gender" value="男"></property>
  59. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  60.     <bean id="student" ></bean>
  61. </beans>this.sid = sid;<?xml version="1.0" encoding="UTF-8"?>
  62. <beans xmlns="http://www.springframework.org/schema/beans"
  63.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  64.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  65. <bean  scope="prototype">
  66.        <property name="sid" value="1001"></property>
  67.        <property name="sname" value="张三"></property>
  68.        <property name="gender" value="男"></property>
  69. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  70.     <bean id="student" ></bean>
  71. </beans><?xml version="1.0" encoding="UTF-8"?>
  72. <beans xmlns="http://www.springframework.org/schema/beans"
  73.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  74.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  75. <bean  scope="prototype">
  76.        <property name="sid" value="1001"></property>
  77.        <property name="sname" value="张三"></property>
  78.        <property name="gender" value="男"></property>
  79. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  80.     <bean id="student" ></bean>
  81. </beans>this.sname = sname;<?xml version="1.0" encoding="UTF-8"?>
  82. <beans xmlns="http://www.springframework.org/schema/beans"
  83.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  84.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  85. <bean  scope="prototype">
  86.        <property name="sid" value="1001"></property>
  87.        <property name="sname" value="张三"></property>
  88.        <property name="gender" value="男"></property>
  89. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  90.     <bean id="student" ></bean>
  91. </beans><?xml version="1.0" encoding="UTF-8"?>
  92. <beans xmlns="http://www.springframework.org/schema/beans"
  93.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  94.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  95. <bean  scope="prototype">
  96.        <property name="sid" value="1001"></property>
  97.        <property name="sname" value="张三"></property>
  98.        <property name="gender" value="男"></property>
  99. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  100.     <bean id="student" ></bean>
  101. </beans>this.gender = gender;<?xml version="1.0" encoding="UTF-8"?>
  102. <beans xmlns="http://www.springframework.org/schema/beans"
  103.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  104.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  105. <bean  scope="prototype">
  106.        <property name="sid" value="1001"></property>
  107.        <property name="sname" value="张三"></property>
  108.        <property name="gender" value="男"></property>
  109. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  110.     <bean id="student" ></bean>
  111. </beans>}}
复制代码
​         xml文件中构造注入:
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <beans xmlns="http://www.springframework.org/schema/beans"
  3.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  4.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  5. <bean  scope="prototype">
  6.        <property name="sid" value="1001"></property>
  7.        <property name="sname" value="张三"></property>
  8.        <property name="gender" value="男"></property>
  9. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  10.     <bean id="student" ></bean>
  11. </beans><?xml version="1.0" encoding="UTF-8"?>
  12. <beans xmlns="http://www.springframework.org/schema/beans"
  13.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  14.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  15. <bean  scope="prototype">
  16.        <property name="sid" value="1001"></property>
  17.        <property name="sname" value="张三"></property>
  18.        <property name="gender" value="男"></property>
  19. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  20.     <bean id="student" ></bean>
  21. </beans><?xml version="1.0" encoding="UTF-8"?>
  22. <beans xmlns="http://www.springframework.org/schema/beans"
  23.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  24.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  25. <bean  scope="prototype">
  26.        <property name="sid" value="1001"></property>
  27.        <property name="sname" value="张三"></property>
  28.        <property name="gender" value="男"></property>
  29. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  30.     <bean id="student" ></bean>
  31. </beans><?xml version="1.0" encoding="UTF-8"?>
  32. <beans xmlns="http://www.springframework.org/schema/beans"
  33.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  34.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  35. <bean  scope="prototype">
  36.        <property name="sid" value="1001"></property>
  37.        <property name="sname" value="张三"></property>
  38.        <property name="gender" value="男"></property>
  39. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  40.     <bean id="student" ></bean>
  41. </beans><?xml version="1.0" encoding="UTF-8"?>
  42. <beans xmlns="http://www.springframework.org/schema/beans"
  43.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  44.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  45. <bean  scope="prototype">
  46.        <property name="sid" value="1001"></property>
  47.        <property name="sname" value="张三"></property>
  48.        <property name="gender" value="男"></property>
  49. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  50.     <bean id="student" ></bean>
  51. </beans>
复制代码

基于Setter方法的注入:
  1. public class Student {<?xml version="1.0" encoding="UTF-8"?>
  2. <beans xmlns="http://www.springframework.org/schema/beans"
  3.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  4.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  5. <bean  scope="prototype">
  6.        <property name="sid" value="1001"></property>
  7.        <property name="sname" value="张三"></property>
  8.        <property name="gender" value="男"></property>
  9. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  10.     <bean id="student" ></bean>
  11. </beans>private  Integer sid;<?xml version="1.0" encoding="UTF-8"?>
  12. <beans xmlns="http://www.springframework.org/schema/beans"
  13.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  14.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  15. <bean  scope="prototype">
  16.        <property name="sid" value="1001"></property>
  17.        <property name="sname" value="张三"></property>
  18.        <property name="gender" value="男"></property>
  19. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  20.     <bean id="student" ></bean>
  21. </beans>private  String sname;<?xml version="1.0" encoding="UTF-8"?>
  22. <beans xmlns="http://www.springframework.org/schema/beans"
  23.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  24.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  25. <bean  scope="prototype">
  26.        <property name="sid" value="1001"></property>
  27.        <property name="sname" value="张三"></property>
  28.        <property name="gender" value="男"></property>
  29. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  30.     <bean id="student" ></bean>
  31. </beans>private  String gender;<?xml version="1.0" encoding="UTF-8"?>
  32. <beans xmlns="http://www.springframework.org/schema/beans"
  33.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  34.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  35. <bean  scope="prototype">
  36.        <property name="sid" value="1001"></property>
  37.        <property name="sname" value="张三"></property>
  38.        <property name="gender" value="男"></property>
  39. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  40.     <bean id="student" ></bean>
  41. </beans>public Integer getSid() {<?xml version="1.0" encoding="UTF-8"?>
  42. <beans xmlns="http://www.springframework.org/schema/beans"
  43.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  44.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  45. <bean  scope="prototype">
  46.        <property name="sid" value="1001"></property>
  47.        <property name="sname" value="张三"></property>
  48.        <property name="gender" value="男"></property>
  49. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  50.     <bean id="student" ></bean>
  51. </beans><?xml version="1.0" encoding="UTF-8"?>
  52. <beans xmlns="http://www.springframework.org/schema/beans"
  53.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  54.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  55. <bean  scope="prototype">
  56.        <property name="sid" value="1001"></property>
  57.        <property name="sname" value="张三"></property>
  58.        <property name="gender" value="男"></property>
  59. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  60.     <bean id="student" ></bean>
  61. </beans>return sid;<?xml version="1.0" encoding="UTF-8"?>
  62. <beans xmlns="http://www.springframework.org/schema/beans"
  63.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  64.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  65. <bean  scope="prototype">
  66.        <property name="sid" value="1001"></property>
  67.        <property name="sname" value="张三"></property>
  68.        <property name="gender" value="男"></property>
  69. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  70.     <bean id="student" ></bean>
  71. </beans>}<?xml version="1.0" encoding="UTF-8"?>
  72. <beans xmlns="http://www.springframework.org/schema/beans"
  73.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  74.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  75. <bean  scope="prototype">
  76.        <property name="sid" value="1001"></property>
  77.        <property name="sname" value="张三"></property>
  78.        <property name="gender" value="男"></property>
  79. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  80.     <bean id="student" ></bean>
  81. </beans>public void setSid(Integer sid) {<?xml version="1.0" encoding="UTF-8"?>
  82. <beans xmlns="http://www.springframework.org/schema/beans"
  83.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  84.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  85. <bean  scope="prototype">
  86.        <property name="sid" value="1001"></property>
  87.        <property name="sname" value="张三"></property>
  88.        <property name="gender" value="男"></property>
  89. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  90.     <bean id="student" ></bean>
  91. </beans><?xml version="1.0" encoding="UTF-8"?>
  92. <beans xmlns="http://www.springframework.org/schema/beans"
  93.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  94.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  95. <bean  scope="prototype">
  96.        <property name="sid" value="1001"></property>
  97.        <property name="sname" value="张三"></property>
  98.        <property name="gender" value="男"></property>
  99. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  100.     <bean id="student" ></bean>
  101. </beans>this.sid = sid;<?xml version="1.0" encoding="UTF-8"?>
  102. <beans xmlns="http://www.springframework.org/schema/beans"
  103.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  104.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  105. <bean  scope="prototype">
  106.        <property name="sid" value="1001"></property>
  107.        <property name="sname" value="张三"></property>
  108.        <property name="gender" value="男"></property>
  109. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  110.     <bean id="student" ></bean>
  111. </beans>}<?xml version="1.0" encoding="UTF-8"?>
  112. <beans xmlns="http://www.springframework.org/schema/beans"
  113.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  114.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  115. <bean  scope="prototype">
  116.        <property name="sid" value="1001"></property>
  117.        <property name="sname" value="张三"></property>
  118.        <property name="gender" value="男"></property>
  119. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  120.     <bean id="student" ></bean>
  121. </beans>public String getSname() {<?xml version="1.0" encoding="UTF-8"?>
  122. <beans xmlns="http://www.springframework.org/schema/beans"
  123.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  124.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  125. <bean  scope="prototype">
  126.        <property name="sid" value="1001"></property>
  127.        <property name="sname" value="张三"></property>
  128.        <property name="gender" value="男"></property>
  129. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  130.     <bean id="student" ></bean>
  131. </beans><?xml version="1.0" encoding="UTF-8"?>
  132. <beans xmlns="http://www.springframework.org/schema/beans"
  133.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  134.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  135. <bean  scope="prototype">
  136.        <property name="sid" value="1001"></property>
  137.        <property name="sname" value="张三"></property>
  138.        <property name="gender" value="男"></property>
  139. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  140.     <bean id="student" ></bean>
  141. </beans>return sname;<?xml version="1.0" encoding="UTF-8"?>
  142. <beans xmlns="http://www.springframework.org/schema/beans"
  143.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  144.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  145. <bean  scope="prototype">
  146.        <property name="sid" value="1001"></property>
  147.        <property name="sname" value="张三"></property>
  148.        <property name="gender" value="男"></property>
  149. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  150.     <bean id="student" ></bean>
  151. </beans>}<?xml version="1.0" encoding="UTF-8"?>
  152. <beans xmlns="http://www.springframework.org/schema/beans"
  153.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  154.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  155. <bean  scope="prototype">
  156.        <property name="sid" value="1001"></property>
  157.        <property name="sname" value="张三"></property>
  158.        <property name="gender" value="男"></property>
  159. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  160.     <bean id="student" ></bean>
  161. </beans>public void setSname(String sname) {<?xml version="1.0" encoding="UTF-8"?>
  162. <beans xmlns="http://www.springframework.org/schema/beans"
  163.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  164.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  165. <bean  scope="prototype">
  166.        <property name="sid" value="1001"></property>
  167.        <property name="sname" value="张三"></property>
  168.        <property name="gender" value="男"></property>
  169. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  170.     <bean id="student" ></bean>
  171. </beans><?xml version="1.0" encoding="UTF-8"?>
  172. <beans xmlns="http://www.springframework.org/schema/beans"
  173.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  174.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  175. <bean  scope="prototype">
  176.        <property name="sid" value="1001"></property>
  177.        <property name="sname" value="张三"></property>
  178.        <property name="gender" value="男"></property>
  179. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  180.     <bean id="student" ></bean>
  181. </beans>this.sname = sname;<?xml version="1.0" encoding="UTF-8"?>
  182. <beans xmlns="http://www.springframework.org/schema/beans"
  183.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  184.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  185. <bean  scope="prototype">
  186.        <property name="sid" value="1001"></property>
  187.        <property name="sname" value="张三"></property>
  188.        <property name="gender" value="男"></property>
  189. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  190.     <bean id="student" ></bean>
  191. </beans>}<?xml version="1.0" encoding="UTF-8"?>
  192. <beans xmlns="http://www.springframework.org/schema/beans"
  193.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  194.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  195. <bean  scope="prototype">
  196.        <property name="sid" value="1001"></property>
  197.        <property name="sname" value="张三"></property>
  198.        <property name="gender" value="男"></property>
  199. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  200.     <bean id="student" ></bean>
  201. </beans>public String getGender() {<?xml version="1.0" encoding="UTF-8"?>
  202. <beans xmlns="http://www.springframework.org/schema/beans"
  203.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  204.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  205. <bean  scope="prototype">
  206.        <property name="sid" value="1001"></property>
  207.        <property name="sname" value="张三"></property>
  208.        <property name="gender" value="男"></property>
  209. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  210.     <bean id="student" ></bean>
  211. </beans><?xml version="1.0" encoding="UTF-8"?>
  212. <beans xmlns="http://www.springframework.org/schema/beans"
  213.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  214.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  215. <bean  scope="prototype">
  216.        <property name="sid" value="1001"></property>
  217.        <property name="sname" value="张三"></property>
  218.        <property name="gender" value="男"></property>
  219. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  220.     <bean id="student" ></bean>
  221. </beans>return gender;<?xml version="1.0" encoding="UTF-8"?>
  222. <beans xmlns="http://www.springframework.org/schema/beans"
  223.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  224.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  225. <bean  scope="prototype">
  226.        <property name="sid" value="1001"></property>
  227.        <property name="sname" value="张三"></property>
  228.        <property name="gender" value="男"></property>
  229. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  230.     <bean id="student" ></bean>
  231. </beans>}<?xml version="1.0" encoding="UTF-8"?>
  232. <beans xmlns="http://www.springframework.org/schema/beans"
  233.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  234.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  235. <bean  scope="prototype">
  236.        <property name="sid" value="1001"></property>
  237.        <property name="sname" value="张三"></property>
  238.        <property name="gender" value="男"></property>
  239. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  240.     <bean id="student" ></bean>
  241. </beans>public void setGender(String gender) {<?xml version="1.0" encoding="UTF-8"?>
  242. <beans xmlns="http://www.springframework.org/schema/beans"
  243.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  244.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  245. <bean  scope="prototype">
  246.        <property name="sid" value="1001"></property>
  247.        <property name="sname" value="张三"></property>
  248.        <property name="gender" value="男"></property>
  249. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  250.     <bean id="student" ></bean>
  251. </beans><?xml version="1.0" encoding="UTF-8"?>
  252. <beans xmlns="http://www.springframework.org/schema/beans"
  253.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  254.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  255. <bean  scope="prototype">
  256.        <property name="sid" value="1001"></property>
  257.        <property name="sname" value="张三"></property>
  258.        <property name="gender" value="男"></property>
  259. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  260.     <bean id="student" ></bean>
  261. </beans>this.gender = gender;<?xml version="1.0" encoding="UTF-8"?>
  262. <beans xmlns="http://www.springframework.org/schema/beans"
  263.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  264.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  265. <bean  scope="prototype">
  266.        <property name="sid" value="1001"></property>
  267.        <property name="sname" value="张三"></property>
  268.        <property name="gender" value="男"></property>
  269. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  270.     <bean id="student" ></bean>
  271. </beans>}
复制代码
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <beans xmlns="http://www.springframework.org/schema/beans"
  3.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  4.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  5. <bean  scope="prototype">
  6.        <property name="sid" value="1001"></property>
  7.        <property name="sname" value="张三"></property>
  8.        <property name="gender" value="男"></property>
  9. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  10.     <bean id="student" ></bean>
  11. </beans><?xml version="1.0" encoding="UTF-8"?>
  12. <beans xmlns="http://www.springframework.org/schema/beans"
  13.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  14.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  15. <bean  scope="prototype">
  16.        <property name="sid" value="1001"></property>
  17.        <property name="sname" value="张三"></property>
  18.        <property name="gender" value="男"></property>
  19. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  20.     <bean id="student" ></bean>
  21. </beans>
复制代码
​<bean ></bean>       
<bean  id="myLogger"></bean>


<aop:aspectj-autoproxy></aop:aspectj-autoproxy>        属性值为对象的注入:
  1. public class Student {<?xml version="1.0" encoding="UTF-8"?>
  2. <beans xmlns="http://www.springframework.org/schema/beans"
  3.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  4.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  5. <bean  scope="prototype">
  6.        <property name="sid" value="1001"></property>
  7.        <property name="sname" value="张三"></property>
  8.        <property name="gender" value="男"></property>
  9. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  10.     <bean id="student" ></bean>
  11. </beans>...<?xml version="1.0" encoding="UTF-8"?>
  12. <beans xmlns="http://www.springframework.org/schema/beans"
  13.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  14.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  15. <bean  scope="prototype">
  16.        <property name="sid" value="1001"></property>
  17.        <property name="sname" value="张三"></property>
  18.        <property name="gender" value="男"></property>
  19. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  20.     <bean id="student" ></bean>
  21. </beans>...<?xml version="1.0" encoding="UTF-8"?>
  22. <beans xmlns="http://www.springframework.org/schema/beans"
  23.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  24.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  25. <bean  scope="prototype">
  26.        <property name="sid" value="1001"></property>
  27.        <property name="sname" value="张三"></property>
  28.        <property name="gender" value="男"></property>
  29. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  30.     <bean id="student" ></bean>
  31. </beans>private Clazz clazz;<?xml version="1.0" encoding="UTF-8"?>
  32. <beans xmlns="http://www.springframework.org/schema/beans"
  33.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  34.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  35. <bean  scope="prototype">
  36.        <property name="sid" value="1001"></property>
  37.        <property name="sname" value="张三"></property>
  38.        <property name="gender" value="男"></property>
  39. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  40.     <bean id="student" ></bean>
  41. </beans>public Clazz getClazz() {<?xml version="1.0" encoding="UTF-8"?>
  42. <beans xmlns="http://www.springframework.org/schema/beans"
  43.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  44.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  45. <bean  scope="prototype">
  46.        <property name="sid" value="1001"></property>
  47.        <property name="sname" value="张三"></property>
  48.        <property name="gender" value="男"></property>
  49. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  50.     <bean id="student" ></bean>
  51. </beans><?xml version="1.0" encoding="UTF-8"?>
  52. <beans xmlns="http://www.springframework.org/schema/beans"
  53.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  54.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  55. <bean  scope="prototype">
  56.        <property name="sid" value="1001"></property>
  57.        <property name="sname" value="张三"></property>
  58.        <property name="gender" value="男"></property>
  59. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  60.     <bean id="student" ></bean>
  61. </beans>return clazz;<?xml version="1.0" encoding="UTF-8"?>
  62. <beans xmlns="http://www.springframework.org/schema/beans"
  63.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  64.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  65. <bean  scope="prototype">
  66.        <property name="sid" value="1001"></property>
  67.        <property name="sname" value="张三"></property>
  68.        <property name="gender" value="男"></property>
  69. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  70.     <bean id="student" ></bean>
  71. </beans>}<?xml version="1.0" encoding="UTF-8"?>
  72. <beans xmlns="http://www.springframework.org/schema/beans"
  73.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  74.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  75. <bean  scope="prototype">
  76.        <property name="sid" value="1001"></property>
  77.        <property name="sname" value="张三"></property>
  78.        <property name="gender" value="男"></property>
  79. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  80.     <bean id="student" ></bean>
  81. </beans>public void setClazz(Clazz clazz) {<?xml version="1.0" encoding="UTF-8"?>
  82. <beans xmlns="http://www.springframework.org/schema/beans"
  83.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  84.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  85. <bean  scope="prototype">
  86.        <property name="sid" value="1001"></property>
  87.        <property name="sname" value="张三"></property>
  88.        <property name="gender" value="男"></property>
  89. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  90.     <bean id="student" ></bean>
  91. </beans><?xml version="1.0" encoding="UTF-8"?>
  92. <beans xmlns="http://www.springframework.org/schema/beans"
  93.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  94.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  95. <bean  scope="prototype">
  96.        <property name="sid" value="1001"></property>
  97.        <property name="sname" value="张三"></property>
  98.        <property name="gender" value="男"></property>
  99. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  100.     <bean id="student" ></bean>
  101. </beans>this.clazz = clazz;<?xml version="1.0" encoding="UTF-8"?>
  102. <beans xmlns="http://www.springframework.org/schema/beans"
  103.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  104.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  105. <bean  scope="prototype">
  106.        <property name="sid" value="1001"></property>
  107.        <property name="sname" value="张三"></property>
  108.        <property name="gender" value="男"></property>
  109. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  110.     <bean id="student" ></bean>
  111. </beans>}        ...        ...}       
复制代码
  1.         <bean >
  2. <bean ></bean>       
  3. <bean  id="myLogger"></bean>
  4. <aop:aspectj-autoproxy></aop:aspectj-autoproxy>        <property name="sid" value="1001"></property>
  5. <bean ></bean>       
  6. <bean  id="myLogger"></bean>
  7. <aop:aspectj-autoproxy></aop:aspectj-autoproxy>        <property name="sname" value="张三"></property>
  8. <bean ></bean>       
  9. <bean  id="myLogger"></bean>
  10. <aop:aspectj-autoproxy></aop:aspectj-autoproxy>        <property name="gender" value="男"></property>
  11. <bean ></bean>       
  12. <bean  id="myLogger"></bean>
  13. <aop:aspectj-autoproxy></aop:aspectj-autoproxy>        <property name="clazz" ref="clazz"></property>
  14.         </bean>
  15.         <bean  id="clazz">
  16. <bean ></bean>       
  17. <bean  id="myLogger"></bean>
  18. <aop:aspectj-autoproxy></aop:aspectj-autoproxy>        <property name="cid" value="1001"></property>
  19. <bean ></bean>       
  20. <bean  id="myLogger"></bean>
  21. <aop:aspectj-autoproxy></aop:aspectj-autoproxy>        <property name="cname" value="DT117"></property>
  22.         </bean>
复制代码
​<bean ></bean>       
<bean  id="myLogger"></bean>


<aop:aspectj-autoproxy></aop:aspectj-autoproxy>        自动注入:  当需要注入的值是对象并且IOC容器中也存在该对象时, 可以选择自动注入: autowire;
byType: 根据范例自动注入;
byName: 根据id的值和属性名称自动注入;
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <beans xmlns="http://www.springframework.org/schema/beans"
  3.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  4.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  5. <bean  scope="prototype">
  6.        <property name="sid" value="1001"></property>
  7.        <property name="sname" value="张三"></property>
  8.        <property name="gender" value="男"></property>
  9. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  10.     <bean id="student" ></bean>
  11. </beans><?xml version="1.0" encoding="UTF-8"?>
  12. <beans xmlns="http://www.springframework.org/schema/beans"
  13.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  14.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  15. <bean  scope="prototype">
  16.        <property name="sid" value="1001"></property>
  17.        <property name="sname" value="张三"></property>
  18.        <property name="gender" value="男"></property>
  19. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  20.     <bean id="student" ></bean>
  21. </beans><?xml version="1.0" encoding="UTF-8"?>
  22. <beans xmlns="http://www.springframework.org/schema/beans"
  23.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  24.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  25. <bean  scope="prototype">
  26.        <property name="sid" value="1001"></property>
  27.        <property name="sname" value="张三"></property>
  28.        <property name="gender" value="男"></property>
  29. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  30.     <bean id="student" ></bean>
  31. </beans><?xml version="1.0" encoding="UTF-8"?>
  32. <beans xmlns="http://www.springframework.org/schema/beans"
  33.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  34.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  35. <bean  scope="prototype">
  36.        <property name="sid" value="1001"></property>
  37.        <property name="sname" value="张三"></property>
  38.        <property name="gender" value="男"></property>
  39. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  40.     <bean id="student" ></bean>
  41. </beans><?xml version="1.0" encoding="UTF-8"?>
  42. <beans xmlns="http://www.springframework.org/schema/beans"
  43.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  44.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  45. <bean  scope="prototype">
  46.        <property name="sid" value="1001"></property>
  47.        <property name="sname" value="张三"></property>
  48.        <property name="gender" value="男"></property>
  49. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  50.     <bean id="student" ></bean>
  51. </beans><?xml version="1.0" encoding="UTF-8"?>
  52. <beans xmlns="http://www.springframework.org/schema/beans"
  53.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  54.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  55. <bean  scope="prototype">
  56.        <property name="sid" value="1001"></property>
  57.        <property name="sname" value="张三"></property>
  58.        <property name="gender" value="男"></property>
  59. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  60.     <bean id="student" ></bean>
  61. </beans><?xml version="1.0" encoding="UTF-8"?>
  62. <beans xmlns="http://www.springframework.org/schema/beans"
  63.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  64.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  65. <bean  scope="prototype">
  66.        <property name="sid" value="1001"></property>
  67.        <property name="sname" value="张三"></property>
  68.        <property name="gender" value="男"></property>
  69. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  70.     <bean id="student" ></bean>
  71. </beans><?xml version="1.0" encoding="UTF-8"?>
  72. <beans xmlns="http://www.springframework.org/schema/beans"
  73.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  74.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  75. <bean  scope="prototype">
  76.        <property name="sid" value="1001"></property>
  77.        <property name="sname" value="张三"></property>
  78.        <property name="gender" value="男"></property>
  79. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  80.     <bean id="student" ></bean>
  81. </beans>   
复制代码
​<bean ></bean>       
<bean  id="myLogger"></bean>


<aop:aspectj-autoproxy></aop:aspectj-autoproxy>        属性值为数组, 集合等注入:
  1. public class Student {<?xml version="1.0" encoding="UTF-8"?>
  2. <beans xmlns="http://www.springframework.org/schema/beans"
  3.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  4.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  5. <bean  scope="prototype">
  6.        <property name="sid" value="1001"></property>
  7.        <property name="sname" value="张三"></property>
  8.        <property name="gender" value="男"></property>
  9. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  10.     <bean id="student" ></bean>
  11. </beans>...<?xml version="1.0" encoding="UTF-8"?>
  12. <beans xmlns="http://www.springframework.org/schema/beans"
  13.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  14.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  15. <bean  scope="prototype">
  16.        <property name="sid" value="1001"></property>
  17.        <property name="sname" value="张三"></property>
  18.        <property name="gender" value="男"></property>
  19. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  20.     <bean id="student" ></bean>
  21. </beans>...<?xml version="1.0" encoding="UTF-8"?>
  22. <beans xmlns="http://www.springframework.org/schema/beans"
  23.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  24.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  25. <bean  scope="prototype">
  26.        <property name="sid" value="1001"></property>
  27.        <property name="sname" value="张三"></property>
  28.        <property name="gender" value="男"></property>
  29. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  30.     <bean id="student" ></bean>
  31. </beans>private List list;<?xml version="1.0" encoding="UTF-8"?>
  32. <beans xmlns="http://www.springframework.org/schema/beans"
  33.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  34.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  35. <bean  scope="prototype">
  36.        <property name="sid" value="1001"></property>
  37.        <property name="sname" value="张三"></property>
  38.        <property name="gender" value="男"></property>
  39. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  40.     <bean id="student" ></bean>
  41. </beans>private Set set;<?xml version="1.0" encoding="UTF-8"?>
  42. <beans xmlns="http://www.springframework.org/schema/beans"
  43.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  44.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  45. <bean  scope="prototype">
  46.        <property name="sid" value="1001"></property>
  47.        <property name="sname" value="张三"></property>
  48.        <property name="gender" value="男"></property>
  49. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  50.     <bean id="student" ></bean>
  51. </beans>private Map map;<?xml version="1.0" encoding="UTF-8"?>
  52. <beans xmlns="http://www.springframework.org/schema/beans"
  53.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  54.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  55. <bean  scope="prototype">
  56.        <property name="sid" value="1001"></property>
  57.        <property name="sname" value="张三"></property>
  58.        <property name="gender" value="男"></property>
  59. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  60.     <bean id="student" ></bean>
  61. </beans>public List getList() {<?xml version="1.0" encoding="UTF-8"?>
  62. <beans xmlns="http://www.springframework.org/schema/beans"
  63.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  64.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  65. <bean  scope="prototype">
  66.        <property name="sid" value="1001"></property>
  67.        <property name="sname" value="张三"></property>
  68.        <property name="gender" value="男"></property>
  69. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  70.     <bean id="student" ></bean>
  71. </beans><?xml version="1.0" encoding="UTF-8"?>
  72. <beans xmlns="http://www.springframework.org/schema/beans"
  73.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  74.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  75. <bean  scope="prototype">
  76.        <property name="sid" value="1001"></property>
  77.        <property name="sname" value="张三"></property>
  78.        <property name="gender" value="男"></property>
  79. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  80.     <bean id="student" ></bean>
  81. </beans>return list;<?xml version="1.0" encoding="UTF-8"?>
  82. <beans xmlns="http://www.springframework.org/schema/beans"
  83.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  84.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  85. <bean  scope="prototype">
  86.        <property name="sid" value="1001"></property>
  87.        <property name="sname" value="张三"></property>
  88.        <property name="gender" value="男"></property>
  89. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  90.     <bean id="student" ></bean>
  91. </beans>}<?xml version="1.0" encoding="UTF-8"?>
  92. <beans xmlns="http://www.springframework.org/schema/beans"
  93.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  94.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  95. <bean  scope="prototype">
  96.        <property name="sid" value="1001"></property>
  97.        <property name="sname" value="张三"></property>
  98.        <property name="gender" value="男"></property>
  99. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  100.     <bean id="student" ></bean>
  101. </beans>public void setList(List list) {<?xml version="1.0" encoding="UTF-8"?>
  102. <beans xmlns="http://www.springframework.org/schema/beans"
  103.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  104.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  105. <bean  scope="prototype">
  106.        <property name="sid" value="1001"></property>
  107.        <property name="sname" value="张三"></property>
  108.        <property name="gender" value="男"></property>
  109. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  110.     <bean id="student" ></bean>
  111. </beans><?xml version="1.0" encoding="UTF-8"?>
  112. <beans xmlns="http://www.springframework.org/schema/beans"
  113.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  114.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  115. <bean  scope="prototype">
  116.        <property name="sid" value="1001"></property>
  117.        <property name="sname" value="张三"></property>
  118.        <property name="gender" value="男"></property>
  119. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  120.     <bean id="student" ></bean>
  121. </beans>this.list = list;<?xml version="1.0" encoding="UTF-8"?>
  122. <beans xmlns="http://www.springframework.org/schema/beans"
  123.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  124.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  125. <bean  scope="prototype">
  126.        <property name="sid" value="1001"></property>
  127.        <property name="sname" value="张三"></property>
  128.        <property name="gender" value="男"></property>
  129. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  130.     <bean id="student" ></bean>
  131. </beans>}<?xml version="1.0" encoding="UTF-8"?>
  132. <beans xmlns="http://www.springframework.org/schema/beans"
  133.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  134.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  135. <bean  scope="prototype">
  136.        <property name="sid" value="1001"></property>
  137.        <property name="sname" value="张三"></property>
  138.        <property name="gender" value="男"></property>
  139. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  140.     <bean id="student" ></bean>
  141. </beans>public Set getSet() {<?xml version="1.0" encoding="UTF-8"?>
  142. <beans xmlns="http://www.springframework.org/schema/beans"
  143.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  144.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  145. <bean  scope="prototype">
  146.        <property name="sid" value="1001"></property>
  147.        <property name="sname" value="张三"></property>
  148.        <property name="gender" value="男"></property>
  149. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  150.     <bean id="student" ></bean>
  151. </beans><?xml version="1.0" encoding="UTF-8"?>
  152. <beans xmlns="http://www.springframework.org/schema/beans"
  153.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  154.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  155. <bean  scope="prototype">
  156.        <property name="sid" value="1001"></property>
  157.        <property name="sname" value="张三"></property>
  158.        <property name="gender" value="男"></property>
  159. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  160.     <bean id="student" ></bean>
  161. </beans>return set;<?xml version="1.0" encoding="UTF-8"?>
  162. <beans xmlns="http://www.springframework.org/schema/beans"
  163.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  164.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  165. <bean  scope="prototype">
  166.        <property name="sid" value="1001"></property>
  167.        <property name="sname" value="张三"></property>
  168.        <property name="gender" value="男"></property>
  169. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  170.     <bean id="student" ></bean>
  171. </beans>}<?xml version="1.0" encoding="UTF-8"?>
  172. <beans xmlns="http://www.springframework.org/schema/beans"
  173.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  174.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  175. <bean  scope="prototype">
  176.        <property name="sid" value="1001"></property>
  177.        <property name="sname" value="张三"></property>
  178.        <property name="gender" value="男"></property>
  179. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  180.     <bean id="student" ></bean>
  181. </beans>public void setSet(Set set) {<?xml version="1.0" encoding="UTF-8"?>
  182. <beans xmlns="http://www.springframework.org/schema/beans"
  183.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  184.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  185. <bean  scope="prototype">
  186.        <property name="sid" value="1001"></property>
  187.        <property name="sname" value="张三"></property>
  188.        <property name="gender" value="男"></property>
  189. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  190.     <bean id="student" ></bean>
  191. </beans><?xml version="1.0" encoding="UTF-8"?>
  192. <beans xmlns="http://www.springframework.org/schema/beans"
  193.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  194.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  195. <bean  scope="prototype">
  196.        <property name="sid" value="1001"></property>
  197.        <property name="sname" value="张三"></property>
  198.        <property name="gender" value="男"></property>
  199. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  200.     <bean id="student" ></bean>
  201. </beans>this.set = set;<?xml version="1.0" encoding="UTF-8"?>
  202. <beans xmlns="http://www.springframework.org/schema/beans"
  203.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  204.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  205. <bean  scope="prototype">
  206.        <property name="sid" value="1001"></property>
  207.        <property name="sname" value="张三"></property>
  208.        <property name="gender" value="男"></property>
  209. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  210.     <bean id="student" ></bean>
  211. </beans>}<?xml version="1.0" encoding="UTF-8"?>
  212. <beans xmlns="http://www.springframework.org/schema/beans"
  213.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  214.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  215. <bean  scope="prototype">
  216.        <property name="sid" value="1001"></property>
  217.        <property name="sname" value="张三"></property>
  218.        <property name="gender" value="男"></property>
  219. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  220.     <bean id="student" ></bean>
  221. </beans>public Map getMap() {<?xml version="1.0" encoding="UTF-8"?>
  222. <beans xmlns="http://www.springframework.org/schema/beans"
  223.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  224.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  225. <bean  scope="prototype">
  226.        <property name="sid" value="1001"></property>
  227.        <property name="sname" value="张三"></property>
  228.        <property name="gender" value="男"></property>
  229. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  230.     <bean id="student" ></bean>
  231. </beans><?xml version="1.0" encoding="UTF-8"?>
  232. <beans xmlns="http://www.springframework.org/schema/beans"
  233.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  234.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  235. <bean  scope="prototype">
  236.        <property name="sid" value="1001"></property>
  237.        <property name="sname" value="张三"></property>
  238.        <property name="gender" value="男"></property>
  239. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  240.     <bean id="student" ></bean>
  241. </beans>return map;<?xml version="1.0" encoding="UTF-8"?>
  242. <beans xmlns="http://www.springframework.org/schema/beans"
  243.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  244.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  245. <bean  scope="prototype">
  246.        <property name="sid" value="1001"></property>
  247.        <property name="sname" value="张三"></property>
  248.        <property name="gender" value="男"></property>
  249. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  250.     <bean id="student" ></bean>
  251. </beans>}<?xml version="1.0" encoding="UTF-8"?>
  252. <beans xmlns="http://www.springframework.org/schema/beans"
  253.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  254.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  255. <bean  scope="prototype">
  256.        <property name="sid" value="1001"></property>
  257.        <property name="sname" value="张三"></property>
  258.        <property name="gender" value="男"></property>
  259. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  260.     <bean id="student" ></bean>
  261. </beans>public void setMap(Map map) {<?xml version="1.0" encoding="UTF-8"?>
  262. <beans xmlns="http://www.springframework.org/schema/beans"
  263.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  264.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  265. <bean  scope="prototype">
  266.        <property name="sid" value="1001"></property>
  267.        <property name="sname" value="张三"></property>
  268.        <property name="gender" value="男"></property>
  269. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  270.     <bean id="student" ></bean>
  271. </beans><?xml version="1.0" encoding="UTF-8"?>
  272. <beans xmlns="http://www.springframework.org/schema/beans"
  273.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  274.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  275. <bean  scope="prototype">
  276.        <property name="sid" value="1001"></property>
  277.        <property name="sname" value="张三"></property>
  278.        <property name="gender" value="男"></property>
  279. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  280.     <bean id="student" ></bean>
  281. </beans>this.map = map;<?xml version="1.0" encoding="UTF-8"?>
  282. <beans xmlns="http://www.springframework.org/schema/beans"
  283.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  284.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  285. <bean  scope="prototype">
  286.        <property name="sid" value="1001"></property>
  287.        <property name="sname" value="张三"></property>
  288.        <property name="gender" value="男"></property>
  289. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  290.     <bean id="student" ></bean>
  291. </beans>}        ...        ...}       
复制代码
  1. <bean ></bean>       
  2. <bean  id="myLogger"></bean>
  3. <aop:aspectj-autoproxy></aop:aspectj-autoproxy>        <bean ></bean>       
  4. <bean  id="myLogger"></bean>
  5. <aop:aspectj-autoproxy></aop:aspectj-autoproxy>        <bean ></bean>       
  6. <bean  id="myLogger"></bean>
  7. <aop:aspectj-autoproxy></aop:aspectj-autoproxy>        <bean ></bean>       
  8. <bean  id="myLogger"></bean>
  9. <aop:aspectj-autoproxy></aop:aspectj-autoproxy>        <bean ></bean>       
  10. <bean  id="myLogger"></bean>
  11. <aop:aspectj-autoproxy></aop:aspectj-autoproxy>        <bean ></bean>       
  12. <bean  id="myLogger"></bean>
  13. <aop:aspectj-autoproxy></aop:aspectj-autoproxy>        <bean ></bean>       
  14. <bean  id="myLogger"></bean>
  15. <aop:aspectj-autoproxy></aop:aspectj-autoproxy>                111<bean ></bean>       
  16. <bean  id="myLogger"></bean>
  17. <aop:aspectj-autoproxy></aop:aspectj-autoproxy>        <bean ></bean>       
  18. <bean  id="myLogger"></bean>
  19. <aop:aspectj-autoproxy></aop:aspectj-autoproxy>        222<bean ></bean>       
  20. <bean  id="myLogger"></bean>
  21. <aop:aspectj-autoproxy></aop:aspectj-autoproxy>        <bean ></bean>       
  22. <bean  id="myLogger"></bean>
  23. <aop:aspectj-autoproxy></aop:aspectj-autoproxy>        333<bean ></bean>       
  24. <bean  id="myLogger"></bean>
  25. <aop:aspectj-autoproxy></aop:aspectj-autoproxy>        <bean ></bean>       
  26. <bean  id="myLogger"></bean>
  27. <aop:aspectj-autoproxy></aop:aspectj-autoproxy>        <bean ></bean>       
  28. <bean  id="myLogger"></bean>
  29. <aop:aspectj-autoproxy></aop:aspectj-autoproxy>        <bean ></bean>       
  30. <bean  id="myLogger"></bean>
  31. <aop:aspectj-autoproxy></aop:aspectj-autoproxy>        <bean ></bean>       
  32. <bean  id="myLogger"></bean>
  33. <aop:aspectj-autoproxy></aop:aspectj-autoproxy>        <bean ></bean>       
  34. <bean  id="myLogger"></bean>
  35. <aop:aspectj-autoproxy></aop:aspectj-autoproxy>        <bean ></bean>       
  36. <bean  id="myLogger"></bean>
  37. <aop:aspectj-autoproxy></aop:aspectj-autoproxy>        444<bean ></bean>       
  38. <bean  id="myLogger"></bean>
  39. <aop:aspectj-autoproxy></aop:aspectj-autoproxy>        <bean ></bean>       
  40. <bean  id="myLogger"></bean>
  41. <aop:aspectj-autoproxy></aop:aspectj-autoproxy>        555<bean ></bean>       
  42. <bean  id="myLogger"></bean>
  43. <aop:aspectj-autoproxy></aop:aspectj-autoproxy>        <bean ></bean>       
  44. <bean  id="myLogger"></bean>
  45. <aop:aspectj-autoproxy></aop:aspectj-autoproxy>        666        <bean >
  46. <bean ></bean>       
  47. <bean  id="myLogger"></bean>
  48. <aop:aspectj-autoproxy></aop:aspectj-autoproxy>        <property name="sid" value="1001"></property>
  49. <bean ></bean>       
  50. <bean  id="myLogger"></bean>
  51. <aop:aspectj-autoproxy></aop:aspectj-autoproxy>        <property name="sname" value="张三"></property>
  52. <bean ></bean>       
  53. <bean  id="myLogger"></bean>
  54. <aop:aspectj-autoproxy></aop:aspectj-autoproxy>        <property name="gender" value="男"></property>
  55. <bean ></bean>       
  56. <bean  id="myLogger"></bean>
  57. <aop:aspectj-autoproxy></aop:aspectj-autoproxy>        <property name="clazz" ref="clazz"></property>
  58.         </bean>
  59.         <bean  id="clazz">
  60. <bean ></bean>       
  61. <bean  id="myLogger"></bean>
  62. <aop:aspectj-autoproxy></aop:aspectj-autoproxy>        <property name="cid" value="1001"></property>
  63. <bean ></bean>       
  64. <bean  id="myLogger"></bean>
  65. <aop:aspectj-autoproxy></aop:aspectj-autoproxy>        <property name="cname" value="DT117"></property>
  66.         </bean><bean ></bean>       
  67. <bean  id="myLogger"></bean>
  68. <aop:aspectj-autoproxy></aop:aspectj-autoproxy>        <bean ></bean>       
  69. <bean  id="myLogger"></bean>
  70. <aop:aspectj-autoproxy></aop:aspectj-autoproxy>        <bean ></bean>       
  71. <bean  id="myLogger"></bean>
  72. <aop:aspectj-autoproxy></aop:aspectj-autoproxy>        <bean ></bean>       
  73. <bean  id="myLogger"></bean>
  74. <aop:aspectj-autoproxy></aop:aspectj-autoproxy>        <bean ></bean>       
  75. <bean  id="myLogger"></bean>
  76. <aop:aspectj-autoproxy></aop:aspectj-autoproxy>        <bean ></bean>       
  77. <bean  id="myLogger"></bean>
  78. <aop:aspectj-autoproxy></aop:aspectj-autoproxy>       
复制代码
基于字段的注入

​<bean ></bean>       
<bean  id="myLogger"></bean>


<aop:aspectj-autoproxy></aop:aspectj-autoproxy>        直接在需要注入的属性上添加注解实现;
  1. @Autowired
  2. private Clazz clazz;
复制代码
​<bean ></bean>       
<bean  id="myLogger"></bean>


<aop:aspectj-autoproxy></aop:aspectj-autoproxy>         @Autowired: 在IoC容器中根据范例查找, 然后注入到指定的属性中;
​<bean ></bean>       
<bean  id="myLogger"></bean>


<aop:aspectj-autoproxy></aop:aspectj-autoproxy>         @Resource:  该注解并非Spring注解, 而是java中的注解,作用和 @Autowired雷同, 是在根据名称进行注入;

3 Aop

​<bean ></bean>       
<bean  id="myLogger"></bean>


<aop:aspectj-autoproxy></aop:aspectj-autoproxy>        Spring AOP(Aspect-Oriented Programming,面向切面编程)是Spring框架的一个紧张特性,它允许将与业务逻辑无关的横切关注点(如日志记录、安全检查、事务管理等)从应用程序代码中分离出来。这有助于提高代码的模块化程度,使得应用程序更加易于维护和扩展。
​<bean ></bean>       
<bean  id="myLogger"></bean>


<aop:aspectj-autoproxy></aop:aspectj-autoproxy>        在Spring AOP中,紧张涉及以下几个焦点概念:

  • 切面(Aspect):封装了横切关注点的模块化代码,通常包含一个或多个通知(Advice)以及切入点(Pointcut)的定义。
  • 通知(Advice):切面在特定连接点执行的操作。根据执行机遇不同,通知可以分为前置通知(Before)、后置通知(After)、返回通知(After-returning)、异常通知(After-throwing)和围绕通知(Around)。
  • 切入点(Pointcut):描述了通知应该织入的一系列连接点。切入点通过类和方法签名的模式匹配定义,比方匹配特定包下所有类的所有方法。
  • 连接点(Join point):程序执行过程中可以插入切面操作的点,比方方法调用、构造函数调用、字段赋值等。Spring AOP仅支持方法执行连接点。
  • 引入(Introduction):允许为现有类添加新方法或属性的一种方式。
  • 织入(Weaving):将切面与目标对象组合在一起,创建代理对象的过程。织入可以在编译时、类加载时或运行时完成。Spring AOP默认使用运行时织入。

1)使用配置文件实现:

​<bean ></bean>       
<bean  id="myLogger"></bean>


<aop:aspectj-autoproxy></aop:aspectj-autoproxy>        导入jar;
​<bean ></bean>       
<bean  id="myLogger"></bean>


<aop:aspectj-autoproxy></aop:aspectj-autoproxy>       

​<bean ></bean>       
<bean  id="myLogger"></bean>


<aop:aspectj-autoproxy></aop:aspectj-autoproxy>        创建业务类接口:
  1. public interface GoodsService {<?xml version="1.0" encoding="UTF-8"?>
  2. <beans xmlns="http://www.springframework.org/schema/beans"
  3.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  4.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  5. <bean  scope="prototype">
  6.        <property name="sid" value="1001"></property>
  7.        <property name="sname" value="张三"></property>
  8.        <property name="gender" value="男"></property>
  9. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  10.     <bean id="student" ></bean>
  11. </beans>void sayHello(String name);}
复制代码
​<bean ></bean>       
<bean  id="myLogger"></bean>


<aop:aspectj-autoproxy></aop:aspectj-autoproxy>        实现接口:
  1. public class GoodsServiceImpl implements GoodsService {<?xml version="1.0" encoding="UTF-8"?>
  2. <beans xmlns="http://www.springframework.org/schema/beans"
  3.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  4.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  5. <bean  scope="prototype">
  6.        <property name="sid" value="1001"></property>
  7.        <property name="sname" value="张三"></property>
  8.        <property name="gender" value="男"></property>
  9. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  10.     <bean id="student" ></bean>
  11. </beans>@Override<?xml version="1.0" encoding="UTF-8"?>
  12. <beans xmlns="http://www.springframework.org/schema/beans"
  13.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  14.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  15. <bean  scope="prototype">
  16.        <property name="sid" value="1001"></property>
  17.        <property name="sname" value="张三"></property>
  18.        <property name="gender" value="男"></property>
  19. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  20.     <bean id="student" ></bean>
  21. </beans>public void sayHello(String name) {<?xml version="1.0" encoding="UTF-8"?>
  22. <beans xmlns="http://www.springframework.org/schema/beans"
  23.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  24.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  25. <bean  scope="prototype">
  26.        <property name="sid" value="1001"></property>
  27.        <property name="sname" value="张三"></property>
  28.        <property name="gender" value="男"></property>
  29. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  30.     <bean id="student" ></bean>
  31. </beans><?xml version="1.0" encoding="UTF-8"?>
  32. <beans xmlns="http://www.springframework.org/schema/beans"
  33.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  34.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  35. <bean  scope="prototype">
  36.        <property name="sid" value="1001"></property>
  37.        <property name="sname" value="张三"></property>
  38.        <property name="gender" value="男"></property>
  39. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  40.     <bean id="student" ></bean>
  41. </beans>System.out.println("Hello, " + name);<?xml version="1.0" encoding="UTF-8"?>
  42. <beans xmlns="http://www.springframework.org/schema/beans"
  43.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  44.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  45. <bean  scope="prototype">
  46.        <property name="sid" value="1001"></property>
  47.        <property name="sname" value="张三"></property>
  48.        <property name="gender" value="男"></property>
  49. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  50.     <bean id="student" ></bean>
  51. </beans>}}
复制代码
​<bean ></bean>       
<bean  id="myLogger"></bean>


<aop:aspectj-autoproxy></aop:aspectj-autoproxy>        创建增强处理的类和方法:
  1. public class myLogger {<?xml version="1.0" encoding="UTF-8"?>
  2. <beans xmlns="http://www.springframework.org/schema/beans"
  3.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  4.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  5. <bean  scope="prototype">
  6.        <property name="sid" value="1001"></property>
  7.        <property name="sname" value="张三"></property>
  8.        <property name="gender" value="男"></property>
  9. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  10.     <bean id="student" ></bean>
  11. </beans>//JoinPoint  可以获取到业务方法的相关的信息<?xml version="1.0" encoding="UTF-8"?>
  12. <beans xmlns="http://www.springframework.org/schema/beans"
  13.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  14.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  15. <bean  scope="prototype">
  16.        <property name="sid" value="1001"></property>
  17.        <property name="sname" value="张三"></property>
  18.        <property name="gender" value="男"></property>
  19. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  20.     <bean id="student" ></bean>
  21. </beans>//前置通知<?xml version="1.0" encoding="UTF-8"?>
  22. <beans xmlns="http://www.springframework.org/schema/beans"
  23.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  24.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  25. <bean  scope="prototype">
  26.        <property name="sid" value="1001"></property>
  27.        <property name="sname" value="张三"></property>
  28.        <property name="gender" value="男"></property>
  29. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  30.     <bean id="student" ></bean>
  31. </beans>public void beforeLogging(JoinPoint point){<?xml version="1.0" encoding="UTF-8"?>
  32. <beans xmlns="http://www.springframework.org/schema/beans"
  33.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  34.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  35. <bean  scope="prototype">
  36.        <property name="sid" value="1001"></property>
  37.        <property name="sname" value="张三"></property>
  38.        <property name="gender" value="男"></property>
  39. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  40.     <bean id="student" ></bean>
  41. </beans><?xml version="1.0" encoding="UTF-8"?>
  42. <beans xmlns="http://www.springframework.org/schema/beans"
  43.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  44.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  45. <bean  scope="prototype">
  46.        <property name="sid" value="1001"></property>
  47.        <property name="sname" value="张三"></property>
  48.        <property name="gender" value="男"></property>
  49. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  50.     <bean id="student" ></bean>
  51. </beans>System.out.println("------------------------------进入前置通知---------------------");<?xml version="1.0" encoding="UTF-8"?>
  52. <beans xmlns="http://www.springframework.org/schema/beans"
  53.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  54.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  55. <bean  scope="prototype">
  56.        <property name="sid" value="1001"></property>
  57.        <property name="sname" value="张三"></property>
  58.        <property name="gender" value="男"></property>
  59. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  60.     <bean id="student" ></bean>
  61. </beans><?xml version="1.0" encoding="UTF-8"?>
  62. <beans xmlns="http://www.springframework.org/schema/beans"
  63.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  64.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  65. <bean  scope="prototype">
  66.        <property name="sid" value="1001"></property>
  67.        <property name="sname" value="张三"></property>
  68.        <property name="gender" value="男"></property>
  69. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  70.     <bean id="student" ></bean>
  71. </beans>System.out.println("---------------------进入了类:"+point.getTarget().getClass().getName());<?xml version="1.0" encoding="UTF-8"?>
  72. <beans xmlns="http://www.springframework.org/schema/beans"
  73.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  74.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  75. <bean  scope="prototype">
  76.        <property name="sid" value="1001"></property>
  77.        <property name="sname" value="张三"></property>
  78.        <property name="gender" value="男"></property>
  79. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  80.     <bean id="student" ></bean>
  81. </beans><?xml version="1.0" encoding="UTF-8"?>
  82. <beans xmlns="http://www.springframework.org/schema/beans"
  83.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  84.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  85. <bean  scope="prototype">
  86.        <property name="sid" value="1001"></property>
  87.        <property name="sname" value="张三"></property>
  88.        <property name="gender" value="男"></property>
  89. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  90.     <bean id="student" ></bean>
  91. </beans>System.out.println("---------------------进入了方法:"+point.getSignature().getName());<?xml version="1.0" encoding="UTF-8"?>
  92. <beans xmlns="http://www.springframework.org/schema/beans"
  93.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  94.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  95. <bean  scope="prototype">
  96.        <property name="sid" value="1001"></property>
  97.        <property name="sname" value="张三"></property>
  98.        <property name="gender" value="男"></property>
  99. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  100.     <bean id="student" ></bean>
  101. </beans><?xml version="1.0" encoding="UTF-8"?>
  102. <beans xmlns="http://www.springframework.org/schema/beans"
  103.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  104.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  105. <bean  scope="prototype">
  106.        <property name="sid" value="1001"></property>
  107.        <property name="sname" value="张三"></property>
  108.        <property name="gender" value="男"></property>
  109. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  110.     <bean id="student" ></bean>
  111. </beans>System.out.println("---------------------传入了参数:"+point.getArgs()[0]);<?xml version="1.0" encoding="UTF-8"?>
  112. <beans xmlns="http://www.springframework.org/schema/beans"
  113.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  114.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  115. <bean  scope="prototype">
  116.        <property name="sid" value="1001"></property>
  117.        <property name="sname" value="张三"></property>
  118.        <property name="gender" value="男"></property>
  119. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  120.     <bean id="student" ></bean>
  121. </beans><?xml version="1.0" encoding="UTF-8"?>
  122. <beans xmlns="http://www.springframework.org/schema/beans"
  123.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  124.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  125. <bean  scope="prototype">
  126.        <property name="sid" value="1001"></property>
  127.        <property name="sname" value="张三"></property>
  128.        <property name="gender" value="男"></property>
  129. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  130.     <bean id="student" ></bean>
  131. </beans>System.out.println(".------------------------------脱离前置通知---------------------");<?xml version="1.0" encoding="UTF-8"?>
  132. <beans xmlns="http://www.springframework.org/schema/beans"
  133.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  134.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  135. <bean  scope="prototype">
  136.        <property name="sid" value="1001"></property>
  137.        <property name="sname" value="张三"></property>
  138.        <property name="gender" value="男"></property>
  139. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  140.     <bean id="student" ></bean>
  141. </beans>}        //后置通知<?xml version="1.0" encoding="UTF-8"?>
  142. <beans xmlns="http://www.springframework.org/schema/beans"
  143.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  144.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  145. <bean  scope="prototype">
  146.        <property name="sid" value="1001"></property>
  147.        <property name="sname" value="张三"></property>
  148.        <property name="gender" value="男"></property>
  149. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  150.     <bean id="student" ></bean>
  151. </beans>public void afterLogging(JoinPoint point,Object result){<?xml version="1.0" encoding="UTF-8"?>
  152. <beans xmlns="http://www.springframework.org/schema/beans"
  153.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  154.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  155. <bean  scope="prototype">
  156.        <property name="sid" value="1001"></property>
  157.        <property name="sname" value="张三"></property>
  158.        <property name="gender" value="男"></property>
  159. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  160.     <bean id="student" ></bean>
  161. </beans><?xml version="1.0" encoding="UTF-8"?>
  162. <beans xmlns="http://www.springframework.org/schema/beans"
  163.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  164.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  165. <bean  scope="prototype">
  166.        <property name="sid" value="1001"></property>
  167.        <property name="sname" value="张三"></property>
  168.        <property name="gender" value="男"></property>
  169. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  170.     <bean id="student" ></bean>
  171. </beans>System.out.println("------------------------------进入后置通知---------------------");<?xml version="1.0" encoding="UTF-8"?>
  172. <beans xmlns="http://www.springframework.org/schema/beans"
  173.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  174.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  175. <bean  scope="prototype">
  176.        <property name="sid" value="1001"></property>
  177.        <property name="sname" value="张三"></property>
  178.        <property name="gender" value="男"></property>
  179. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  180.     <bean id="student" ></bean>
  181. </beans><?xml version="1.0" encoding="UTF-8"?>
  182. <beans xmlns="http://www.springframework.org/schema/beans"
  183.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  184.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  185. <bean  scope="prototype">
  186.        <property name="sid" value="1001"></property>
  187.        <property name="sname" value="张三"></property>
  188.        <property name="gender" value="男"></property>
  189. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  190.     <bean id="student" ></bean>
  191. </beans>System.out.println("---------------------进入了类:"+point.getTarget().getClass().getName());<?xml version="1.0" encoding="UTF-8"?>
  192. <beans xmlns="http://www.springframework.org/schema/beans"
  193.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  194.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  195. <bean  scope="prototype">
  196.        <property name="sid" value="1001"></property>
  197.        <property name="sname" value="张三"></property>
  198.        <property name="gender" value="男"></property>
  199. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  200.     <bean id="student" ></bean>
  201. </beans><?xml version="1.0" encoding="UTF-8"?>
  202. <beans xmlns="http://www.springframework.org/schema/beans"
  203.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  204.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  205. <bean  scope="prototype">
  206.        <property name="sid" value="1001"></property>
  207.        <property name="sname" value="张三"></property>
  208.        <property name="gender" value="男"></property>
  209. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  210.     <bean id="student" ></bean>
  211. </beans>System.out.println("---------------------进入了方法:"+point.getSignature().getName());<?xml version="1.0" encoding="UTF-8"?>
  212. <beans xmlns="http://www.springframework.org/schema/beans"
  213.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  214.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  215. <bean  scope="prototype">
  216.        <property name="sid" value="1001"></property>
  217.        <property name="sname" value="张三"></property>
  218.        <property name="gender" value="男"></property>
  219. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  220.     <bean id="student" ></bean>
  221. </beans><?xml version="1.0" encoding="UTF-8"?>
  222. <beans xmlns="http://www.springframework.org/schema/beans"
  223.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  224.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  225. <bean  scope="prototype">
  226.        <property name="sid" value="1001"></property>
  227.        <property name="sname" value="张三"></property>
  228.        <property name="gender" value="男"></property>
  229. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  230.     <bean id="student" ></bean>
  231. </beans>System.out.println("---------------------传入了参数:"+point.getArgs()[0]);<?xml version="1.0" encoding="UTF-8"?>
  232. <beans xmlns="http://www.springframework.org/schema/beans"
  233.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  234.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  235. <bean  scope="prototype">
  236.        <property name="sid" value="1001"></property>
  237.        <property name="sname" value="张三"></property>
  238.        <property name="gender" value="男"></property>
  239. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  240.     <bean id="student" ></bean>
  241. </beans><?xml version="1.0" encoding="UTF-8"?>
  242. <beans xmlns="http://www.springframework.org/schema/beans"
  243.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  244.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  245. <bean  scope="prototype">
  246.        <property name="sid" value="1001"></property>
  247.        <property name="sname" value="张三"></property>
  248.        <property name="gender" value="男"></property>
  249. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  250.     <bean id="student" ></bean>
  251. </beans>System.out.println("---------------------返回值:"+result);<?xml version="1.0" encoding="UTF-8"?>
  252. <beans xmlns="http://www.springframework.org/schema/beans"
  253.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  254.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  255. <bean  scope="prototype">
  256.        <property name="sid" value="1001"></property>
  257.        <property name="sname" value="张三"></property>
  258.        <property name="gender" value="男"></property>
  259. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  260.     <bean id="student" ></bean>
  261. </beans><?xml version="1.0" encoding="UTF-8"?>
  262. <beans xmlns="http://www.springframework.org/schema/beans"
  263.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  264.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  265. <bean  scope="prototype">
  266.        <property name="sid" value="1001"></property>
  267.        <property name="sname" value="张三"></property>
  268.        <property name="gender" value="男"></property>
  269. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  270.     <bean id="student" ></bean>
  271. </beans>System.out.println(".------------------------------脱离后置通知---------------------");<?xml version="1.0" encoding="UTF-8"?>
  272. <beans xmlns="http://www.springframework.org/schema/beans"
  273.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  274.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  275. <bean  scope="prototype">
  276.        <property name="sid" value="1001"></property>
  277.        <property name="sname" value="张三"></property>
  278.        <property name="gender" value="男"></property>
  279. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  280.     <bean id="student" ></bean>
  281. </beans>}<?xml version="1.0" encoding="UTF-8"?>
  282. <beans xmlns="http://www.springframework.org/schema/beans"
  283.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  284.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  285. <bean  scope="prototype">
  286.        <property name="sid" value="1001"></property>
  287.        <property name="sname" value="张三"></property>
  288.        <property name="gender" value="男"></property>
  289. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  290.     <bean id="student" ></bean>
  291. </beans>//围绕通知<?xml version="1.0" encoding="UTF-8"?>
  292. <beans xmlns="http://www.springframework.org/schema/beans"
  293.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  294.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  295. <bean  scope="prototype">
  296.        <property name="sid" value="1001"></property>
  297.        <property name="sname" value="张三"></property>
  298.        <property name="gender" value="男"></property>
  299. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  300.     <bean id="student" ></bean>
  301. </beans>public Object aroundLogging(ProceedingJoinPoint point) throws Throwable {<?xml version="1.0" encoding="UTF-8"?>
  302. <beans xmlns="http://www.springframework.org/schema/beans"
  303.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  304.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  305. <bean  scope="prototype">
  306.        <property name="sid" value="1001"></property>
  307.        <property name="sname" value="张三"></property>
  308.        <property name="gender" value="男"></property>
  309. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  310.     <bean id="student" ></bean>
  311. </beans><?xml version="1.0" encoding="UTF-8"?>
  312. <beans xmlns="http://www.springframework.org/schema/beans"
  313.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  314.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  315. <bean  scope="prototype">
  316.        <property name="sid" value="1001"></property>
  317.        <property name="sname" value="张三"></property>
  318.        <property name="gender" value="男"></property>
  319. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  320.     <bean id="student" ></bean>
  321. </beans>System.out.println("------------------------------进入围绕通知---------------------");<?xml version="1.0" encoding="UTF-8"?>
  322. <beans xmlns="http://www.springframework.org/schema/beans"
  323.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  324.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  325. <bean  scope="prototype">
  326.        <property name="sid" value="1001"></property>
  327.        <property name="sname" value="张三"></property>
  328.        <property name="gender" value="男"></property>
  329. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  330.     <bean id="student" ></bean>
  331. </beans><?xml version="1.0" encoding="UTF-8"?>
  332. <beans xmlns="http://www.springframework.org/schema/beans"
  333.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  334.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  335. <bean  scope="prototype">
  336.        <property name="sid" value="1001"></property>
  337.        <property name="sname" value="张三"></property>
  338.        <property name="gender" value="男"></property>
  339. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  340.     <bean id="student" ></bean>
  341. </beans>System.out.println("---------------------进入了类:"+point.getTarget().getClass().getName());<?xml version="1.0" encoding="UTF-8"?>
  342. <beans xmlns="http://www.springframework.org/schema/beans"
  343.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  344.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  345. <bean  scope="prototype">
  346.        <property name="sid" value="1001"></property>
  347.        <property name="sname" value="张三"></property>
  348.        <property name="gender" value="男"></property>
  349. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  350.     <bean id="student" ></bean>
  351. </beans><?xml version="1.0" encoding="UTF-8"?>
  352. <beans xmlns="http://www.springframework.org/schema/beans"
  353.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  354.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  355. <bean  scope="prototype">
  356.        <property name="sid" value="1001"></property>
  357.        <property name="sname" value="张三"></property>
  358.        <property name="gender" value="男"></property>
  359. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  360.     <bean id="student" ></bean>
  361. </beans>System.out.println("---------------------进入了方法:"+point.getSignature().getName());<?xml version="1.0" encoding="UTF-8"?>
  362. <beans xmlns="http://www.springframework.org/schema/beans"
  363.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  364.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  365. <bean  scope="prototype">
  366.        <property name="sid" value="1001"></property>
  367.        <property name="sname" value="张三"></property>
  368.        <property name="gender" value="男"></property>
  369. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  370.     <bean id="student" ></bean>
  371. </beans><?xml version="1.0" encoding="UTF-8"?>
  372. <beans xmlns="http://www.springframework.org/schema/beans"
  373.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  374.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  375. <bean  scope="prototype">
  376.        <property name="sid" value="1001"></property>
  377.        <property name="sname" value="张三"></property>
  378.        <property name="gender" value="男"></property>
  379. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  380.     <bean id="student" ></bean>
  381. </beans>System.out.println("---------------------传入了参数:"+point.getArgs()[0]);<?xml version="1.0" encoding="UTF-8"?>
  382. <beans xmlns="http://www.springframework.org/schema/beans"
  383.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  384.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  385. <bean  scope="prototype">
  386.        <property name="sid" value="1001"></property>
  387.        <property name="sname" value="张三"></property>
  388.        <property name="gender" value="男"></property>
  389. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  390.     <bean id="student" ></bean>
  391. </beans><?xml version="1.0" encoding="UTF-8"?>
  392. <beans xmlns="http://www.springframework.org/schema/beans"
  393.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  394.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  395. <bean  scope="prototype">
  396.        <property name="sid" value="1001"></property>
  397.        <property name="sname" value="张三"></property>
  398.        <property name="gender" value="男"></property>
  399. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  400.     <bean id="student" ></bean>
  401. </beans>//手动执行业务方法  并且接收返回值<?xml version="1.0" encoding="UTF-8"?>
  402. <beans xmlns="http://www.springframework.org/schema/beans"
  403.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  404.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  405. <bean  scope="prototype">
  406.        <property name="sid" value="1001"></property>
  407.        <property name="sname" value="张三"></property>
  408.        <property name="gender" value="男"></property>
  409. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  410.     <bean id="student" ></bean>
  411. </beans><?xml version="1.0" encoding="UTF-8"?>
  412. <beans xmlns="http://www.springframework.org/schema/beans"
  413.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  414.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  415. <bean  scope="prototype">
  416.        <property name="sid" value="1001"></property>
  417.        <property name="sname" value="张三"></property>
  418.        <property name="gender" value="男"></property>
  419. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  420.     <bean id="student" ></bean>
  421. </beans>Object result = point.proceed();<?xml version="1.0" encoding="UTF-8"?>
  422. <beans xmlns="http://www.springframework.org/schema/beans"
  423.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  424.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  425. <bean  scope="prototype">
  426.        <property name="sid" value="1001"></property>
  427.        <property name="sname" value="张三"></property>
  428.        <property name="gender" value="男"></property>
  429. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  430.     <bean id="student" ></bean>
  431. </beans><?xml version="1.0" encoding="UTF-8"?>
  432. <beans xmlns="http://www.springframework.org/schema/beans"
  433.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  434.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  435. <bean  scope="prototype">
  436.        <property name="sid" value="1001"></property>
  437.        <property name="sname" value="张三"></property>
  438.        <property name="gender" value="男"></property>
  439. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  440.     <bean id="student" ></bean>
  441. </beans>System.out.println("---------------------返回值:"+result);<?xml version="1.0" encoding="UTF-8"?>
  442. <beans xmlns="http://www.springframework.org/schema/beans"
  443.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  444.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  445. <bean  scope="prototype">
  446.        <property name="sid" value="1001"></property>
  447.        <property name="sname" value="张三"></property>
  448.        <property name="gender" value="男"></property>
  449. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  450.     <bean id="student" ></bean>
  451. </beans><?xml version="1.0" encoding="UTF-8"?>
  452. <beans xmlns="http://www.springframework.org/schema/beans"
  453.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  454.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  455. <bean  scope="prototype">
  456.        <property name="sid" value="1001"></property>
  457.        <property name="sname" value="张三"></property>
  458.        <property name="gender" value="男"></property>
  459. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  460.     <bean id="student" ></bean>
  461. </beans>System.out.println(".------------------------------脱离围绕通知---------------------");<?xml version="1.0" encoding="UTF-8"?>
  462. <beans xmlns="http://www.springframework.org/schema/beans"
  463.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  464.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  465. <bean  scope="prototype">
  466.        <property name="sid" value="1001"></property>
  467.        <property name="sname" value="张三"></property>
  468.        <property name="gender" value="男"></property>
  469. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  470.     <bean id="student" ></bean>
  471. </beans><?xml version="1.0" encoding="UTF-8"?>
  472. <beans xmlns="http://www.springframework.org/schema/beans"
  473.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  474.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  475. <bean  scope="prototype">
  476.        <property name="sid" value="1001"></property>
  477.        <property name="sname" value="张三"></property>
  478.        <property name="gender" value="男"></property>
  479. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  480.     <bean id="student" ></bean>
  481. </beans>return result;<?xml version="1.0" encoding="UTF-8"?>
  482. <beans xmlns="http://www.springframework.org/schema/beans"
  483.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  484.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  485. <bean  scope="prototype">
  486.        <property name="sid" value="1001"></property>
  487.        <property name="sname" value="张三"></property>
  488.        <property name="gender" value="男"></property>
  489. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  490.     <bean id="student" ></bean>
  491. </beans>}<?xml version="1.0" encoding="UTF-8"?>
  492. <beans xmlns="http://www.springframework.org/schema/beans"
  493.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  494.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  495. <bean  scope="prototype">
  496.        <property name="sid" value="1001"></property>
  497.        <property name="sname" value="张三"></property>
  498.        <property name="gender" value="男"></property>
  499. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  500.     <bean id="student" ></bean>
  501. </beans>  //异常通知<?xml version="1.0" encoding="UTF-8"?>
  502. <beans xmlns="http://www.springframework.org/schema/beans"
  503.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  504.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  505. <bean  scope="prototype">
  506.        <property name="sid" value="1001"></property>
  507.        <property name="sname" value="张三"></property>
  508.        <property name="gender" value="男"></property>
  509. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  510.     <bean id="student" ></bean>
  511. </beans>public void execptionLogging(JoinPoint point,Exception e){<?xml version="1.0" encoding="UTF-8"?>
  512. <beans xmlns="http://www.springframework.org/schema/beans"
  513.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  514.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  515. <bean  scope="prototype">
  516.        <property name="sid" value="1001"></property>
  517.        <property name="sname" value="张三"></property>
  518.        <property name="gender" value="男"></property>
  519. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  520.     <bean id="student" ></bean>
  521. </beans><?xml version="1.0" encoding="UTF-8"?>
  522. <beans xmlns="http://www.springframework.org/schema/beans"
  523.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  524.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  525. <bean  scope="prototype">
  526.        <property name="sid" value="1001"></property>
  527.        <property name="sname" value="张三"></property>
  528.        <property name="gender" value="男"></property>
  529. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  530.     <bean id="student" ></bean>
  531. </beans>System.out.println("------------------------------进入异常通知---------------------");<?xml version="1.0" encoding="UTF-8"?>
  532. <beans xmlns="http://www.springframework.org/schema/beans"
  533.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  534.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  535. <bean  scope="prototype">
  536.        <property name="sid" value="1001"></property>
  537.        <property name="sname" value="张三"></property>
  538.        <property name="gender" value="男"></property>
  539. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  540.     <bean id="student" ></bean>
  541. </beans><?xml version="1.0" encoding="UTF-8"?>
  542. <beans xmlns="http://www.springframework.org/schema/beans"
  543.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  544.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  545. <bean  scope="prototype">
  546.        <property name="sid" value="1001"></property>
  547.        <property name="sname" value="张三"></property>
  548.        <property name="gender" value="男"></property>
  549. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  550.     <bean id="student" ></bean>
  551. </beans>System.out.println("---------------------进入了类:"+point.getTarget().getClass().getName());<?xml version="1.0" encoding="UTF-8"?>
  552. <beans xmlns="http://www.springframework.org/schema/beans"
  553.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  554.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  555. <bean  scope="prototype">
  556.        <property name="sid" value="1001"></property>
  557.        <property name="sname" value="张三"></property>
  558.        <property name="gender" value="男"></property>
  559. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  560.     <bean id="student" ></bean>
  561. </beans><?xml version="1.0" encoding="UTF-8"?>
  562. <beans xmlns="http://www.springframework.org/schema/beans"
  563.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  564.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  565. <bean  scope="prototype">
  566.        <property name="sid" value="1001"></property>
  567.        <property name="sname" value="张三"></property>
  568.        <property name="gender" value="男"></property>
  569. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  570.     <bean id="student" ></bean>
  571. </beans>System.out.println("---------------------进入了方法:"+point.getSignature().getName());<?xml version="1.0" encoding="UTF-8"?>
  572. <beans xmlns="http://www.springframework.org/schema/beans"
  573.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  574.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  575. <bean  scope="prototype">
  576.        <property name="sid" value="1001"></property>
  577.        <property name="sname" value="张三"></property>
  578.        <property name="gender" value="男"></property>
  579. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  580.     <bean id="student" ></bean>
  581. </beans><?xml version="1.0" encoding="UTF-8"?>
  582. <beans xmlns="http://www.springframework.org/schema/beans"
  583.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  584.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  585. <bean  scope="prototype">
  586.        <property name="sid" value="1001"></property>
  587.        <property name="sname" value="张三"></property>
  588.        <property name="gender" value="男"></property>
  589. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  590.     <bean id="student" ></bean>
  591. </beans>System.out.println("---------------------传入了参数:"+point.getArgs()[0]);<?xml version="1.0" encoding="UTF-8"?>
  592. <beans xmlns="http://www.springframework.org/schema/beans"
  593.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  594.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  595. <bean  scope="prototype">
  596.        <property name="sid" value="1001"></property>
  597.        <property name="sname" value="张三"></property>
  598.        <property name="gender" value="男"></property>
  599. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  600.     <bean id="student" ></bean>
  601. </beans><?xml version="1.0" encoding="UTF-8"?>
  602. <beans xmlns="http://www.springframework.org/schema/beans"
  603.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  604.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  605. <bean  scope="prototype">
  606.        <property name="sid" value="1001"></property>
  607.        <property name="sname" value="张三"></property>
  608.        <property name="gender" value="男"></property>
  609. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  610.     <bean id="student" ></bean>
  611. </beans>System.out.println("---------------------发生了异常:"+e.getMessage());<?xml version="1.0" encoding="UTF-8"?>
  612. <beans xmlns="http://www.springframework.org/schema/beans"
  613.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  614.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  615. <bean  scope="prototype">
  616.        <property name="sid" value="1001"></property>
  617.        <property name="sname" value="张三"></property>
  618.        <property name="gender" value="男"></property>
  619. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  620.     <bean id="student" ></bean>
  621. </beans><?xml version="1.0" encoding="UTF-8"?>
  622. <beans xmlns="http://www.springframework.org/schema/beans"
  623.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  624.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  625. <bean  scope="prototype">
  626.        <property name="sid" value="1001"></property>
  627.        <property name="sname" value="张三"></property>
  628.        <property name="gender" value="男"></property>
  629. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  630.     <bean id="student" ></bean>
  631. </beans>System.out.println(".------------------------------脱离异常通知---------------------");<?xml version="1.0" encoding="UTF-8"?>
  632. <beans xmlns="http://www.springframework.org/schema/beans"
  633.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  634.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  635. <bean  scope="prototype">
  636.        <property name="sid" value="1001"></property>
  637.        <property name="sname" value="张三"></property>
  638.        <property name="gender" value="男"></property>
  639. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  640.     <bean id="student" ></bean>
  641. </beans>}        //最终通知<?xml version="1.0" encoding="UTF-8"?>
  642. <beans xmlns="http://www.springframework.org/schema/beans"
  643.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  644.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  645. <bean  scope="prototype">
  646.        <property name="sid" value="1001"></property>
  647.        <property name="sname" value="张三"></property>
  648.        <property name="gender" value="男"></property>
  649. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  650.     <bean id="student" ></bean>
  651. </beans>public void finallyLogging(JoinPoint point){<?xml version="1.0" encoding="UTF-8"?>
  652. <beans xmlns="http://www.springframework.org/schema/beans"
  653.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  654.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  655. <bean  scope="prototype">
  656.        <property name="sid" value="1001"></property>
  657.        <property name="sname" value="张三"></property>
  658.        <property name="gender" value="男"></property>
  659. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  660.     <bean id="student" ></bean>
  661. </beans><?xml version="1.0" encoding="UTF-8"?>
  662. <beans xmlns="http://www.springframework.org/schema/beans"
  663.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  664.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  665. <bean  scope="prototype">
  666.        <property name="sid" value="1001"></property>
  667.        <property name="sname" value="张三"></property>
  668.        <property name="gender" value="男"></property>
  669. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  670.     <bean id="student" ></bean>
  671. </beans>System.out.println("------------------------------进入最终通知---------------------");<?xml version="1.0" encoding="UTF-8"?>
  672. <beans xmlns="http://www.springframework.org/schema/beans"
  673.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  674.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  675. <bean  scope="prototype">
  676.        <property name="sid" value="1001"></property>
  677.        <property name="sname" value="张三"></property>
  678.        <property name="gender" value="男"></property>
  679. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  680.     <bean id="student" ></bean>
  681. </beans><?xml version="1.0" encoding="UTF-8"?>
  682. <beans xmlns="http://www.springframework.org/schema/beans"
  683.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  684.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  685. <bean  scope="prototype">
  686.        <property name="sid" value="1001"></property>
  687.        <property name="sname" value="张三"></property>
  688.        <property name="gender" value="男"></property>
  689. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  690.     <bean id="student" ></bean>
  691. </beans>System.out.println("---------------------进入了类:"+point.getTarget().getClass().getName());<?xml version="1.0" encoding="UTF-8"?>
  692. <beans xmlns="http://www.springframework.org/schema/beans"
  693.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  694.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  695. <bean  scope="prototype">
  696.        <property name="sid" value="1001"></property>
  697.        <property name="sname" value="张三"></property>
  698.        <property name="gender" value="男"></property>
  699. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  700.     <bean id="student" ></bean>
  701. </beans><?xml version="1.0" encoding="UTF-8"?>
  702. <beans xmlns="http://www.springframework.org/schema/beans"
  703.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  704.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  705. <bean  scope="prototype">
  706.        <property name="sid" value="1001"></property>
  707.        <property name="sname" value="张三"></property>
  708.        <property name="gender" value="男"></property>
  709. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  710.     <bean id="student" ></bean>
  711. </beans>System.out.println("---------------------进入了方法:"+point.getSignature().getName());<?xml version="1.0" encoding="UTF-8"?>
  712. <beans xmlns="http://www.springframework.org/schema/beans"
  713.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  714.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  715. <bean  scope="prototype">
  716.        <property name="sid" value="1001"></property>
  717.        <property name="sname" value="张三"></property>
  718.        <property name="gender" value="男"></property>
  719. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  720.     <bean id="student" ></bean>
  721. </beans><?xml version="1.0" encoding="UTF-8"?>
  722. <beans xmlns="http://www.springframework.org/schema/beans"
  723.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  724.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  725. <bean  scope="prototype">
  726.        <property name="sid" value="1001"></property>
  727.        <property name="sname" value="张三"></property>
  728.        <property name="gender" value="男"></property>
  729. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  730.     <bean id="student" ></bean>
  731. </beans>System.out.println("---------------------传入了参数:"+point.getArgs()[0]);<?xml version="1.0" encoding="UTF-8"?>
  732. <beans xmlns="http://www.springframework.org/schema/beans"
  733.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  734.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  735. <bean  scope="prototype">
  736.        <property name="sid" value="1001"></property>
  737.        <property name="sname" value="张三"></property>
  738.        <property name="gender" value="男"></property>
  739. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  740.     <bean id="student" ></bean>
  741. </beans><?xml version="1.0" encoding="UTF-8"?>
  742. <beans xmlns="http://www.springframework.org/schema/beans"
  743.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  744.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  745. <bean  scope="prototype">
  746.        <property name="sid" value="1001"></property>
  747.        <property name="sname" value="张三"></property>
  748.        <property name="gender" value="男"></property>
  749. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  750.     <bean id="student" ></bean>
  751. </beans>System.out.println(".------------------------------脱离最终通知---------------------");<?xml version="1.0" encoding="UTF-8"?>
  752. <beans xmlns="http://www.springframework.org/schema/beans"
  753.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  754.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  755. <bean  scope="prototype">
  756.        <property name="sid" value="1001"></property>
  757.        <property name="sname" value="张三"></property>
  758.        <property name="gender" value="男"></property>
  759. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  760.     <bean id="student" ></bean>
  761. </beans>}}<?xml version="1.0" encoding="UTF-8"?>
  762. <beans xmlns="http://www.springframework.org/schema/beans"
  763.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  764.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  765. <bean  scope="prototype">
  766.        <property name="sid" value="1001"></property>
  767.        <property name="sname" value="张三"></property>
  768.        <property name="gender" value="男"></property>
  769. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  770.     <bean id="student" ></bean>
  771. </beans>
复制代码
  1. <bean ></bean>       
  2. <bean  id="myLogger"></bean>
  3. <aop:aspectj-autoproxy></aop:aspectj-autoproxy>                <?xml version="1.0" encoding="UTF-8"?>
  4. <beans xmlns="http://www.springframework.org/schema/beans"
  5.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  6.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  7. <bean  scope="prototype">
  8.        <property name="sid" value="1001"></property>
  9.        <property name="sname" value="张三"></property>
  10.        <property name="gender" value="男"></property>
  11. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  12.     <bean id="student" ></bean>
  13. </beans><?xml version="1.0" encoding="UTF-8"?>
  14. <beans xmlns="http://www.springframework.org/schema/beans"
  15.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  16.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  17. <bean  scope="prototype">
  18.        <property name="sid" value="1001"></property>
  19.        <property name="sname" value="张三"></property>
  20.        <property name="gender" value="男"></property>
  21. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  22.     <bean id="student" ></bean>
  23. </beans>        <?xml version="1.0" encoding="UTF-8"?>
  24. <beans xmlns="http://www.springframework.org/schema/beans"
  25.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  26.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  27. <bean  scope="prototype">
  28.        <property name="sid" value="1001"></property>
  29.        <property name="sname" value="张三"></property>
  30.        <property name="gender" value="男"></property>
  31. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  32.     <bean id="student" ></bean>
  33. </beans>        <bean >
  34. <bean ></bean>       
  35. <bean  id="myLogger"></bean>
  36. <aop:aspectj-autoproxy></aop:aspectj-autoproxy>        <property name="sid" value="1001"></property>
  37. <bean ></bean>       
  38. <bean  id="myLogger"></bean>
  39. <aop:aspectj-autoproxy></aop:aspectj-autoproxy>        <property name="sname" value="张三"></property>
  40. <bean ></bean>       
  41. <bean  id="myLogger"></bean>
  42. <aop:aspectj-autoproxy></aop:aspectj-autoproxy>        <property name="gender" value="男"></property>
  43. <bean ></bean>       
  44. <bean  id="myLogger"></bean>
  45. <aop:aspectj-autoproxy></aop:aspectj-autoproxy>        <property name="clazz" ref="clazz"></property>
  46.         </bean>
  47.         <bean  id="clazz">
  48. <bean ></bean>       
  49. <bean  id="myLogger"></bean>
  50. <aop:aspectj-autoproxy></aop:aspectj-autoproxy>        <property name="cid" value="1001"></property>
  51. <bean ></bean>       
  52. <bean  id="myLogger"></bean>
  53. <aop:aspectj-autoproxy></aop:aspectj-autoproxy>        <property name="cname" value="DT117"></property>
  54.         </bean><bean ></bean>       
  55. <bean  id="myLogger"></bean>
  56. <aop:aspectj-autoproxy></aop:aspectj-autoproxy>        <bean ></bean>       
  57. <bean  id="myLogger"></bean>
  58. <aop:aspectj-autoproxy></aop:aspectj-autoproxy>        <bean ></bean>       
  59. <bean  id="myLogger"></bean>
  60. <aop:aspectj-autoproxy></aop:aspectj-autoproxy>          
复制代码
2)使用注解实现:

​        1) 给创建增强处理的类和方法加上指定的注解:
​<bean ></bean>       
<bean  id="myLogger"></bean>


<aop:aspectj-autoproxy></aop:aspectj-autoproxy>                @Aspect:  用在增长处理类上,声明该类为aop的一个切面类;
​<bean ></bean>       
<bean  id="myLogger"></bean>


<aop:aspectj-autoproxy></aop:aspectj-autoproxy>                @Pointcut("execution(* cn.guotu.service..(..))"), 用在方法上, 指定一个切入点
​<bean ></bean>       
<bean  id="myLogger"></bean>


<aop:aspectj-autoproxy></aop:aspectj-autoproxy>        <?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
<bean  scope="prototype">
       <property name="sid" value="1001"></property>
       <property name="sname" value="张三"></property>
       <property name="gender" value="男"></property>
</bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">

    <bean id="student" ></bean>

</beans>@Before(), 用在方法上, 代表该方法是一个前置增强方法
​<bean ></bean>       
<bean  id="myLogger"></bean>


<aop:aspectj-autoproxy></aop:aspectj-autoproxy>                @Around(), 用在方法上, 代表该方法是一个围绕增强方法
​<bean ></bean>       
<bean  id="myLogger"></bean>


<aop:aspectj-autoproxy></aop:aspectj-autoproxy>                @AfterReturning(), 用在方法上, 代表该方法是一个后置增强方法
​<bean ></bean>       
<bean  id="myLogger"></bean>


<aop:aspectj-autoproxy></aop:aspectj-autoproxy>                @AfterThrowing(), 用在方法上, 代表该方法是一个异常增强方法
​<bean ></bean>       
<bean  id="myLogger"></bean>


<aop:aspectj-autoproxy></aop:aspectj-autoproxy>                @After(), 用在方法上, 代表该方法是一个异常增强方法
  1. @Aspectpublic class MyLoggerAspacj {<?xml version="1.0" encoding="UTF-8"?>
  2. <beans xmlns="http://www.springframework.org/schema/beans"
  3.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  4.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  5. <bean  scope="prototype">
  6.        <property name="sid" value="1001"></property>
  7.        <property name="sname" value="张三"></property>
  8.        <property name="gender" value="男"></property>
  9. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  10.     <bean id="student" ></bean>
  11. </beans>//切入点<?xml version="1.0" encoding="UTF-8"?>
  12. <beans xmlns="http://www.springframework.org/schema/beans"
  13.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  14.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  15. <bean  scope="prototype">
  16.        <property name="sid" value="1001"></property>
  17.        <property name="sname" value="张三"></property>
  18.        <property name="gender" value="男"></property>
  19. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  20.     <bean id="student" ></bean>
  21. </beans>@Pointcut("execution(* cn.guotu.service.*.*(..))")<?xml version="1.0" encoding="UTF-8"?>
  22. <beans xmlns="http://www.springframework.org/schema/beans"
  23.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  24.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  25. <bean  scope="prototype">
  26.        <property name="sid" value="1001"></property>
  27.        <property name="sname" value="张三"></property>
  28.        <property name="gender" value="男"></property>
  29. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  30.     <bean id="student" ></bean>
  31. </beans>public void pt(){<?xml version="1.0" encoding="UTF-8"?>
  32. <beans xmlns="http://www.springframework.org/schema/beans"
  33.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  34.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  35. <bean  scope="prototype">
  36.        <property name="sid" value="1001"></property>
  37.        <property name="sname" value="张三"></property>
  38.        <property name="gender" value="男"></property>
  39. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  40.     <bean id="student" ></bean>
  41. </beans>}<?xml version="1.0" encoding="UTF-8"?>
  42. <beans xmlns="http://www.springframework.org/schema/beans"
  43.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  44.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  45. <bean  scope="prototype">
  46.        <property name="sid" value="1001"></property>
  47.        <property name="sname" value="张三"></property>
  48.        <property name="gender" value="男"></property>
  49. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  50.     <bean id="student" ></bean>
  51. </beans>@Before("pt()")<?xml version="1.0" encoding="UTF-8"?>
  52. <beans xmlns="http://www.springframework.org/schema/beans"
  53.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  54.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  55. <bean  scope="prototype">
  56.        <property name="sid" value="1001"></property>
  57.        <property name="sname" value="张三"></property>
  58.        <property name="gender" value="男"></property>
  59. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  60.     <bean id="student" ></bean>
  61. </beans>public void beforeLogging(JoinPoint point){<?xml version="1.0" encoding="UTF-8"?>
  62. <beans xmlns="http://www.springframework.org/schema/beans"
  63.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  64.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  65. <bean  scope="prototype">
  66.        <property name="sid" value="1001"></property>
  67.        <property name="sname" value="张三"></property>
  68.        <property name="gender" value="男"></property>
  69. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  70.     <bean id="student" ></bean>
  71. </beans><?xml version="1.0" encoding="UTF-8"?>
  72. <beans xmlns="http://www.springframework.org/schema/beans"
  73.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  74.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  75. <bean  scope="prototype">
  76.        <property name="sid" value="1001"></property>
  77.        <property name="sname" value="张三"></property>
  78.        <property name="gender" value="男"></property>
  79. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  80.     <bean id="student" ></bean>
  81. </beans>System.out.println("------------------------------进入前置增强---------------------");<?xml version="1.0" encoding="UTF-8"?>
  82. <beans xmlns="http://www.springframework.org/schema/beans"
  83.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  84.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  85. <bean  scope="prototype">
  86.        <property name="sid" value="1001"></property>
  87.        <property name="sname" value="张三"></property>
  88.        <property name="gender" value="男"></property>
  89. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  90.     <bean id="student" ></bean>
  91. </beans><?xml version="1.0" encoding="UTF-8"?>
  92. <beans xmlns="http://www.springframework.org/schema/beans"
  93.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  94.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  95. <bean  scope="prototype">
  96.        <property name="sid" value="1001"></property>
  97.        <property name="sname" value="张三"></property>
  98.        <property name="gender" value="男"></property>
  99. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  100.     <bean id="student" ></bean>
  101. </beans>System.out.println("---------------------进入了类:"+point.getTarget().getClass().getName());<?xml version="1.0" encoding="UTF-8"?>
  102. <beans xmlns="http://www.springframework.org/schema/beans"
  103.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  104.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  105. <bean  scope="prototype">
  106.        <property name="sid" value="1001"></property>
  107.        <property name="sname" value="张三"></property>
  108.        <property name="gender" value="男"></property>
  109. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  110.     <bean id="student" ></bean>
  111. </beans><?xml version="1.0" encoding="UTF-8"?>
  112. <beans xmlns="http://www.springframework.org/schema/beans"
  113.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  114.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  115. <bean  scope="prototype">
  116.        <property name="sid" value="1001"></property>
  117.        <property name="sname" value="张三"></property>
  118.        <property name="gender" value="男"></property>
  119. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  120.     <bean id="student" ></bean>
  121. </beans>System.out.println("---------------------进入了方法:"+point.getSignature().getName());<?xml version="1.0" encoding="UTF-8"?>
  122. <beans xmlns="http://www.springframework.org/schema/beans"
  123.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  124.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  125. <bean  scope="prototype">
  126.        <property name="sid" value="1001"></property>
  127.        <property name="sname" value="张三"></property>
  128.        <property name="gender" value="男"></property>
  129. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  130.     <bean id="student" ></bean>
  131. </beans><?xml version="1.0" encoding="UTF-8"?>
  132. <beans xmlns="http://www.springframework.org/schema/beans"
  133.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  134.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  135. <bean  scope="prototype">
  136.        <property name="sid" value="1001"></property>
  137.        <property name="sname" value="张三"></property>
  138.        <property name="gender" value="男"></property>
  139. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  140.     <bean id="student" ></bean>
  141. </beans>System.out.println("---------------------传入了参数:"+point.getArgs()[0]);<?xml version="1.0" encoding="UTF-8"?>
  142. <beans xmlns="http://www.springframework.org/schema/beans"
  143.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  144.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  145. <bean  scope="prototype">
  146.        <property name="sid" value="1001"></property>
  147.        <property name="sname" value="张三"></property>
  148.        <property name="gender" value="男"></property>
  149. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  150.     <bean id="student" ></bean>
  151. </beans><?xml version="1.0" encoding="UTF-8"?>
  152. <beans xmlns="http://www.springframework.org/schema/beans"
  153.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  154.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  155. <bean  scope="prototype">
  156.        <property name="sid" value="1001"></property>
  157.        <property name="sname" value="张三"></property>
  158.        <property name="gender" value="男"></property>
  159. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  160.     <bean id="student" ></bean>
  161. </beans>System.out.println(".------------------------------脱离前置增强---------------------");<?xml version="1.0" encoding="UTF-8"?>
  162. <beans xmlns="http://www.springframework.org/schema/beans"
  163.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  164.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  165. <bean  scope="prototype">
  166.        <property name="sid" value="1001"></property>
  167.        <property name="sname" value="张三"></property>
  168.        <property name="gender" value="男"></property>
  169. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  170.     <bean id="student" ></bean>
  171. </beans>}<?xml version="1.0" encoding="UTF-8"?>
  172. <beans xmlns="http://www.springframework.org/schema/beans"
  173.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  174.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  175. <bean  scope="prototype">
  176.        <property name="sid" value="1001"></property>
  177.        <property name="sname" value="张三"></property>
  178.        <property name="gender" value="男"></property>
  179. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  180.     <bean id="student" ></bean>
  181. </beans>//围绕增强<?xml version="1.0" encoding="UTF-8"?>
  182. <beans xmlns="http://www.springframework.org/schema/beans"
  183.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  184.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  185. <bean  scope="prototype">
  186.        <property name="sid" value="1001"></property>
  187.        <property name="sname" value="张三"></property>
  188.        <property name="gender" value="男"></property>
  189. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  190.     <bean id="student" ></bean>
  191. </beans>@Around("pt()")<?xml version="1.0" encoding="UTF-8"?>
  192. <beans xmlns="http://www.springframework.org/schema/beans"
  193.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  194.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  195. <bean  scope="prototype">
  196.        <property name="sid" value="1001"></property>
  197.        <property name="sname" value="张三"></property>
  198.        <property name="gender" value="男"></property>
  199. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  200.     <bean id="student" ></bean>
  201. </beans>public Object aroundLogging(ProceedingJoinPoint point) throws Throwable {<?xml version="1.0" encoding="UTF-8"?>
  202. <beans xmlns="http://www.springframework.org/schema/beans"
  203.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  204.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  205. <bean  scope="prototype">
  206.        <property name="sid" value="1001"></property>
  207.        <property name="sname" value="张三"></property>
  208.        <property name="gender" value="男"></property>
  209. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  210.     <bean id="student" ></bean>
  211. </beans><?xml version="1.0" encoding="UTF-8"?>
  212. <beans xmlns="http://www.springframework.org/schema/beans"
  213.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  214.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  215. <bean  scope="prototype">
  216.        <property name="sid" value="1001"></property>
  217.        <property name="sname" value="张三"></property>
  218.        <property name="gender" value="男"></property>
  219. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  220.     <bean id="student" ></bean>
  221. </beans>System.out.println("------------------------------进入围绕增强---------------------");<?xml version="1.0" encoding="UTF-8"?>
  222. <beans xmlns="http://www.springframework.org/schema/beans"
  223.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  224.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  225. <bean  scope="prototype">
  226.        <property name="sid" value="1001"></property>
  227.        <property name="sname" value="张三"></property>
  228.        <property name="gender" value="男"></property>
  229. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  230.     <bean id="student" ></bean>
  231. </beans><?xml version="1.0" encoding="UTF-8"?>
  232. <beans xmlns="http://www.springframework.org/schema/beans"
  233.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  234.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  235. <bean  scope="prototype">
  236.        <property name="sid" value="1001"></property>
  237.        <property name="sname" value="张三"></property>
  238.        <property name="gender" value="男"></property>
  239. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  240.     <bean id="student" ></bean>
  241. </beans>System.out.println("---------------------进入了类:"+point.getTarget().getClass().getName());<?xml version="1.0" encoding="UTF-8"?>
  242. <beans xmlns="http://www.springframework.org/schema/beans"
  243.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  244.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  245. <bean  scope="prototype">
  246.        <property name="sid" value="1001"></property>
  247.        <property name="sname" value="张三"></property>
  248.        <property name="gender" value="男"></property>
  249. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  250.     <bean id="student" ></bean>
  251. </beans><?xml version="1.0" encoding="UTF-8"?>
  252. <beans xmlns="http://www.springframework.org/schema/beans"
  253.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  254.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  255. <bean  scope="prototype">
  256.        <property name="sid" value="1001"></property>
  257.        <property name="sname" value="张三"></property>
  258.        <property name="gender" value="男"></property>
  259. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  260.     <bean id="student" ></bean>
  261. </beans>System.out.println("---------------------进入了方法:"+point.getSignature().getName());<?xml version="1.0" encoding="UTF-8"?>
  262. <beans xmlns="http://www.springframework.org/schema/beans"
  263.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  264.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  265. <bean  scope="prototype">
  266.        <property name="sid" value="1001"></property>
  267.        <property name="sname" value="张三"></property>
  268.        <property name="gender" value="男"></property>
  269. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  270.     <bean id="student" ></bean>
  271. </beans><?xml version="1.0" encoding="UTF-8"?>
  272. <beans xmlns="http://www.springframework.org/schema/beans"
  273.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  274.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  275. <bean  scope="prototype">
  276.        <property name="sid" value="1001"></property>
  277.        <property name="sname" value="张三"></property>
  278.        <property name="gender" value="男"></property>
  279. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  280.     <bean id="student" ></bean>
  281. </beans>System.out.println("---------------------传入了参数:"+point.getArgs()[0]);<?xml version="1.0" encoding="UTF-8"?>
  282. <beans xmlns="http://www.springframework.org/schema/beans"
  283.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  284.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  285. <bean  scope="prototype">
  286.        <property name="sid" value="1001"></property>
  287.        <property name="sname" value="张三"></property>
  288.        <property name="gender" value="男"></property>
  289. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  290.     <bean id="student" ></bean>
  291. </beans><?xml version="1.0" encoding="UTF-8"?>
  292. <beans xmlns="http://www.springframework.org/schema/beans"
  293.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  294.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  295. <bean  scope="prototype">
  296.        <property name="sid" value="1001"></property>
  297.        <property name="sname" value="张三"></property>
  298.        <property name="gender" value="男"></property>
  299. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  300.     <bean id="student" ></bean>
  301. </beans>//手动执行业务方法  并且接收返回值<?xml version="1.0" encoding="UTF-8"?>
  302. <beans xmlns="http://www.springframework.org/schema/beans"
  303.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  304.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  305. <bean  scope="prototype">
  306.        <property name="sid" value="1001"></property>
  307.        <property name="sname" value="张三"></property>
  308.        <property name="gender" value="男"></property>
  309. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  310.     <bean id="student" ></bean>
  311. </beans><?xml version="1.0" encoding="UTF-8"?>
  312. <beans xmlns="http://www.springframework.org/schema/beans"
  313.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  314.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  315. <bean  scope="prototype">
  316.        <property name="sid" value="1001"></property>
  317.        <property name="sname" value="张三"></property>
  318.        <property name="gender" value="男"></property>
  319. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  320.     <bean id="student" ></bean>
  321. </beans>Object result = point.proceed();<?xml version="1.0" encoding="UTF-8"?>
  322. <beans xmlns="http://www.springframework.org/schema/beans"
  323.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  324.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  325. <bean  scope="prototype">
  326.        <property name="sid" value="1001"></property>
  327.        <property name="sname" value="张三"></property>
  328.        <property name="gender" value="男"></property>
  329. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  330.     <bean id="student" ></bean>
  331. </beans><?xml version="1.0" encoding="UTF-8"?>
  332. <beans xmlns="http://www.springframework.org/schema/beans"
  333.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  334.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  335. <bean  scope="prototype">
  336.        <property name="sid" value="1001"></property>
  337.        <property name="sname" value="张三"></property>
  338.        <property name="gender" value="男"></property>
  339. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  340.     <bean id="student" ></bean>
  341. </beans>System.out.println("---------------------返回值:"+result);<?xml version="1.0" encoding="UTF-8"?>
  342. <beans xmlns="http://www.springframework.org/schema/beans"
  343.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  344.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  345. <bean  scope="prototype">
  346.        <property name="sid" value="1001"></property>
  347.        <property name="sname" value="张三"></property>
  348.        <property name="gender" value="男"></property>
  349. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  350.     <bean id="student" ></bean>
  351. </beans><?xml version="1.0" encoding="UTF-8"?>
  352. <beans xmlns="http://www.springframework.org/schema/beans"
  353.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  354.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  355. <bean  scope="prototype">
  356.        <property name="sid" value="1001"></property>
  357.        <property name="sname" value="张三"></property>
  358.        <property name="gender" value="男"></property>
  359. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  360.     <bean id="student" ></bean>
  361. </beans>System.out.println(".------------------------------脱离围绕增强---------------------");<?xml version="1.0" encoding="UTF-8"?>
  362. <beans xmlns="http://www.springframework.org/schema/beans"
  363.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  364.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  365. <bean  scope="prototype">
  366.        <property name="sid" value="1001"></property>
  367.        <property name="sname" value="张三"></property>
  368.        <property name="gender" value="男"></property>
  369. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  370.     <bean id="student" ></bean>
  371. </beans><?xml version="1.0" encoding="UTF-8"?>
  372. <beans xmlns="http://www.springframework.org/schema/beans"
  373.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  374.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  375. <bean  scope="prototype">
  376.        <property name="sid" value="1001"></property>
  377.        <property name="sname" value="张三"></property>
  378.        <property name="gender" value="男"></property>
  379. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  380.     <bean id="student" ></bean>
  381. </beans>return result;<?xml version="1.0" encoding="UTF-8"?>
  382. <beans xmlns="http://www.springframework.org/schema/beans"
  383.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  384.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  385. <bean  scope="prototype">
  386.        <property name="sid" value="1001"></property>
  387.        <property name="sname" value="张三"></property>
  388.        <property name="gender" value="男"></property>
  389. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  390.     <bean id="student" ></bean>
  391. </beans>}<?xml version="1.0" encoding="UTF-8"?>
  392. <beans xmlns="http://www.springframework.org/schema/beans"
  393.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  394.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  395. <bean  scope="prototype">
  396.        <property name="sid" value="1001"></property>
  397.        <property name="sname" value="张三"></property>
  398.        <property name="gender" value="男"></property>
  399. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  400.     <bean id="student" ></bean>
  401. </beans>@AfterReturning(pointcut = "pt()",returning="result")<?xml version="1.0" encoding="UTF-8"?>
  402. <beans xmlns="http://www.springframework.org/schema/beans"
  403.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  404.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  405. <bean  scope="prototype">
  406.        <property name="sid" value="1001"></property>
  407.        <property name="sname" value="张三"></property>
  408.        <property name="gender" value="男"></property>
  409. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  410.     <bean id="student" ></bean>
  411. </beans>public void afterLogging(JoinPoint point,Object result){<?xml version="1.0" encoding="UTF-8"?>
  412. <beans xmlns="http://www.springframework.org/schema/beans"
  413.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  414.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  415. <bean  scope="prototype">
  416.        <property name="sid" value="1001"></property>
  417.        <property name="sname" value="张三"></property>
  418.        <property name="gender" value="男"></property>
  419. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  420.     <bean id="student" ></bean>
  421. </beans><?xml version="1.0" encoding="UTF-8"?>
  422. <beans xmlns="http://www.springframework.org/schema/beans"
  423.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  424.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  425. <bean  scope="prototype">
  426.        <property name="sid" value="1001"></property>
  427.        <property name="sname" value="张三"></property>
  428.        <property name="gender" value="男"></property>
  429. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  430.     <bean id="student" ></bean>
  431. </beans>System.out.println("------------------------------进入后置增强---------------------");<?xml version="1.0" encoding="UTF-8"?>
  432. <beans xmlns="http://www.springframework.org/schema/beans"
  433.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  434.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  435. <bean  scope="prototype">
  436.        <property name="sid" value="1001"></property>
  437.        <property name="sname" value="张三"></property>
  438.        <property name="gender" value="男"></property>
  439. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  440.     <bean id="student" ></bean>
  441. </beans><?xml version="1.0" encoding="UTF-8"?>
  442. <beans xmlns="http://www.springframework.org/schema/beans"
  443.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  444.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  445. <bean  scope="prototype">
  446.        <property name="sid" value="1001"></property>
  447.        <property name="sname" value="张三"></property>
  448.        <property name="gender" value="男"></property>
  449. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  450.     <bean id="student" ></bean>
  451. </beans>System.out.println("---------------------进入了类:"+point.getTarget().getClass().getName());<?xml version="1.0" encoding="UTF-8"?>
  452. <beans xmlns="http://www.springframework.org/schema/beans"
  453.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  454.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  455. <bean  scope="prototype">
  456.        <property name="sid" value="1001"></property>
  457.        <property name="sname" value="张三"></property>
  458.        <property name="gender" value="男"></property>
  459. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  460.     <bean id="student" ></bean>
  461. </beans><?xml version="1.0" encoding="UTF-8"?>
  462. <beans xmlns="http://www.springframework.org/schema/beans"
  463.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  464.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  465. <bean  scope="prototype">
  466.        <property name="sid" value="1001"></property>
  467.        <property name="sname" value="张三"></property>
  468.        <property name="gender" value="男"></property>
  469. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  470.     <bean id="student" ></bean>
  471. </beans>System.out.println("---------------------进入了方法:"+point.getSignature().getName());<?xml version="1.0" encoding="UTF-8"?>
  472. <beans xmlns="http://www.springframework.org/schema/beans"
  473.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  474.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  475. <bean  scope="prototype">
  476.        <property name="sid" value="1001"></property>
  477.        <property name="sname" value="张三"></property>
  478.        <property name="gender" value="男"></property>
  479. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  480.     <bean id="student" ></bean>
  481. </beans><?xml version="1.0" encoding="UTF-8"?>
  482. <beans xmlns="http://www.springframework.org/schema/beans"
  483.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  484.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  485. <bean  scope="prototype">
  486.        <property name="sid" value="1001"></property>
  487.        <property name="sname" value="张三"></property>
  488.        <property name="gender" value="男"></property>
  489. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  490.     <bean id="student" ></bean>
  491. </beans>System.out.println("---------------------传入了参数:"+point.getArgs()[0]);<?xml version="1.0" encoding="UTF-8"?>
  492. <beans xmlns="http://www.springframework.org/schema/beans"
  493.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  494.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  495. <bean  scope="prototype">
  496.        <property name="sid" value="1001"></property>
  497.        <property name="sname" value="张三"></property>
  498.        <property name="gender" value="男"></property>
  499. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  500.     <bean id="student" ></bean>
  501. </beans><?xml version="1.0" encoding="UTF-8"?>
  502. <beans xmlns="http://www.springframework.org/schema/beans"
  503.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  504.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  505. <bean  scope="prototype">
  506.        <property name="sid" value="1001"></property>
  507.        <property name="sname" value="张三"></property>
  508.        <property name="gender" value="男"></property>
  509. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  510.     <bean id="student" ></bean>
  511. </beans>System.out.println("---------------------返回值:"+result);<?xml version="1.0" encoding="UTF-8"?>
  512. <beans xmlns="http://www.springframework.org/schema/beans"
  513.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  514.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  515. <bean  scope="prototype">
  516.        <property name="sid" value="1001"></property>
  517.        <property name="sname" value="张三"></property>
  518.        <property name="gender" value="男"></property>
  519. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  520.     <bean id="student" ></bean>
  521. </beans><?xml version="1.0" encoding="UTF-8"?>
  522. <beans xmlns="http://www.springframework.org/schema/beans"
  523.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  524.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  525. <bean  scope="prototype">
  526.        <property name="sid" value="1001"></property>
  527.        <property name="sname" value="张三"></property>
  528.        <property name="gender" value="男"></property>
  529. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  530.     <bean id="student" ></bean>
  531. </beans>System.out.println(".------------------------------脱离后置增强---------------------");<?xml version="1.0" encoding="UTF-8"?>
  532. <beans xmlns="http://www.springframework.org/schema/beans"
  533.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  534.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  535. <bean  scope="prototype">
  536.        <property name="sid" value="1001"></property>
  537.        <property name="sname" value="张三"></property>
  538.        <property name="gender" value="男"></property>
  539. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  540.     <bean id="student" ></bean>
  541. </beans>}<?xml version="1.0" encoding="UTF-8"?>
  542. <beans xmlns="http://www.springframework.org/schema/beans"
  543.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  544.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  545. <bean  scope="prototype">
  546.        <property name="sid" value="1001"></property>
  547.        <property name="sname" value="张三"></property>
  548.        <property name="gender" value="男"></property>
  549. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  550.     <bean id="student" ></bean>
  551. </beans>//异常增强<?xml version="1.0" encoding="UTF-8"?>
  552. <beans xmlns="http://www.springframework.org/schema/beans"
  553.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  554.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  555. <bean  scope="prototype">
  556.        <property name="sid" value="1001"></property>
  557.        <property name="sname" value="张三"></property>
  558.        <property name="gender" value="男"></property>
  559. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  560.     <bean id="student" ></bean>
  561. </beans>@AfterThrowing(pointcut = "pt()",throwing = "e")<?xml version="1.0" encoding="UTF-8"?>
  562. <beans xmlns="http://www.springframework.org/schema/beans"
  563.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  564.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  565. <bean  scope="prototype">
  566.        <property name="sid" value="1001"></property>
  567.        <property name="sname" value="张三"></property>
  568.        <property name="gender" value="男"></property>
  569. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  570.     <bean id="student" ></bean>
  571. </beans>public void execptionLogging(JoinPoint point,Exception e){<?xml version="1.0" encoding="UTF-8"?>
  572. <beans xmlns="http://www.springframework.org/schema/beans"
  573.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  574.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  575. <bean  scope="prototype">
  576.        <property name="sid" value="1001"></property>
  577.        <property name="sname" value="张三"></property>
  578.        <property name="gender" value="男"></property>
  579. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  580.     <bean id="student" ></bean>
  581. </beans><?xml version="1.0" encoding="UTF-8"?>
  582. <beans xmlns="http://www.springframework.org/schema/beans"
  583.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  584.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  585. <bean  scope="prototype">
  586.        <property name="sid" value="1001"></property>
  587.        <property name="sname" value="张三"></property>
  588.        <property name="gender" value="男"></property>
  589. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  590.     <bean id="student" ></bean>
  591. </beans>System.out.println("------------------------------进入异常增强---------------------");<?xml version="1.0" encoding="UTF-8"?>
  592. <beans xmlns="http://www.springframework.org/schema/beans"
  593.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  594.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  595. <bean  scope="prototype">
  596.        <property name="sid" value="1001"></property>
  597.        <property name="sname" value="张三"></property>
  598.        <property name="gender" value="男"></property>
  599. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  600.     <bean id="student" ></bean>
  601. </beans><?xml version="1.0" encoding="UTF-8"?>
  602. <beans xmlns="http://www.springframework.org/schema/beans"
  603.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  604.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  605. <bean  scope="prototype">
  606.        <property name="sid" value="1001"></property>
  607.        <property name="sname" value="张三"></property>
  608.        <property name="gender" value="男"></property>
  609. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  610.     <bean id="student" ></bean>
  611. </beans>System.out.println("---------------------进入了类:"+point.getTarget().getClass().getName());<?xml version="1.0" encoding="UTF-8"?>
  612. <beans xmlns="http://www.springframework.org/schema/beans"
  613.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  614.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  615. <bean  scope="prototype">
  616.        <property name="sid" value="1001"></property>
  617.        <property name="sname" value="张三"></property>
  618.        <property name="gender" value="男"></property>
  619. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  620.     <bean id="student" ></bean>
  621. </beans><?xml version="1.0" encoding="UTF-8"?>
  622. <beans xmlns="http://www.springframework.org/schema/beans"
  623.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  624.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  625. <bean  scope="prototype">
  626.        <property name="sid" value="1001"></property>
  627.        <property name="sname" value="张三"></property>
  628.        <property name="gender" value="男"></property>
  629. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  630.     <bean id="student" ></bean>
  631. </beans>System.out.println("---------------------进入了方法:"+point.getSignature().getName());<?xml version="1.0" encoding="UTF-8"?>
  632. <beans xmlns="http://www.springframework.org/schema/beans"
  633.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  634.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  635. <bean  scope="prototype">
  636.        <property name="sid" value="1001"></property>
  637.        <property name="sname" value="张三"></property>
  638.        <property name="gender" value="男"></property>
  639. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  640.     <bean id="student" ></bean>
  641. </beans><?xml version="1.0" encoding="UTF-8"?>
  642. <beans xmlns="http://www.springframework.org/schema/beans"
  643.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  644.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  645. <bean  scope="prototype">
  646.        <property name="sid" value="1001"></property>
  647.        <property name="sname" value="张三"></property>
  648.        <property name="gender" value="男"></property>
  649. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  650.     <bean id="student" ></bean>
  651. </beans>System.out.println("---------------------传入了参数:"+point.getArgs()[0]);<?xml version="1.0" encoding="UTF-8"?>
  652. <beans xmlns="http://www.springframework.org/schema/beans"
  653.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  654.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  655. <bean  scope="prototype">
  656.        <property name="sid" value="1001"></property>
  657.        <property name="sname" value="张三"></property>
  658.        <property name="gender" value="男"></property>
  659. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  660.     <bean id="student" ></bean>
  661. </beans><?xml version="1.0" encoding="UTF-8"?>
  662. <beans xmlns="http://www.springframework.org/schema/beans"
  663.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  664.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  665. <bean  scope="prototype">
  666.        <property name="sid" value="1001"></property>
  667.        <property name="sname" value="张三"></property>
  668.        <property name="gender" value="男"></property>
  669. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  670.     <bean id="student" ></bean>
  671. </beans>System.out.println("---------------------发生了异常:"+e.getMessage());<?xml version="1.0" encoding="UTF-8"?>
  672. <beans xmlns="http://www.springframework.org/schema/beans"
  673.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  674.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  675. <bean  scope="prototype">
  676.        <property name="sid" value="1001"></property>
  677.        <property name="sname" value="张三"></property>
  678.        <property name="gender" value="男"></property>
  679. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  680.     <bean id="student" ></bean>
  681. </beans><?xml version="1.0" encoding="UTF-8"?>
  682. <beans xmlns="http://www.springframework.org/schema/beans"
  683.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  684.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  685. <bean  scope="prototype">
  686.        <property name="sid" value="1001"></property>
  687.        <property name="sname" value="张三"></property>
  688.        <property name="gender" value="男"></property>
  689. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  690.     <bean id="student" ></bean>
  691. </beans>System.out.println(".------------------------------脱离异常增强---------------------");<?xml version="1.0" encoding="UTF-8"?>
  692. <beans xmlns="http://www.springframework.org/schema/beans"
  693.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  694.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  695. <bean  scope="prototype">
  696.        <property name="sid" value="1001"></property>
  697.        <property name="sname" value="张三"></property>
  698.        <property name="gender" value="男"></property>
  699. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  700.     <bean id="student" ></bean>
  701. </beans>}<?xml version="1.0" encoding="UTF-8"?>
  702. <beans xmlns="http://www.springframework.org/schema/beans"
  703.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  704.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  705. <bean  scope="prototype">
  706.        <property name="sid" value="1001"></property>
  707.        <property name="sname" value="张三"></property>
  708.        <property name="gender" value="男"></property>
  709. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  710.     <bean id="student" ></bean>
  711. </beans>@After("pt()")<?xml version="1.0" encoding="UTF-8"?>
  712. <beans xmlns="http://www.springframework.org/schema/beans"
  713.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  714.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  715. <bean  scope="prototype">
  716.        <property name="sid" value="1001"></property>
  717.        <property name="sname" value="张三"></property>
  718.        <property name="gender" value="男"></property>
  719. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  720.     <bean id="student" ></bean>
  721. </beans>public void finallyLogging(JoinPoint point){<?xml version="1.0" encoding="UTF-8"?>
  722. <beans xmlns="http://www.springframework.org/schema/beans"
  723.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  724.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  725. <bean  scope="prototype">
  726.        <property name="sid" value="1001"></property>
  727.        <property name="sname" value="张三"></property>
  728.        <property name="gender" value="男"></property>
  729. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  730.     <bean id="student" ></bean>
  731. </beans><?xml version="1.0" encoding="UTF-8"?>
  732. <beans xmlns="http://www.springframework.org/schema/beans"
  733.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  734.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  735. <bean  scope="prototype">
  736.        <property name="sid" value="1001"></property>
  737.        <property name="sname" value="张三"></property>
  738.        <property name="gender" value="男"></property>
  739. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  740.     <bean id="student" ></bean>
  741. </beans>System.out.println("------------------------------进入最终增强---------------------");<?xml version="1.0" encoding="UTF-8"?>
  742. <beans xmlns="http://www.springframework.org/schema/beans"
  743.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  744.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  745. <bean  scope="prototype">
  746.        <property name="sid" value="1001"></property>
  747.        <property name="sname" value="张三"></property>
  748.        <property name="gender" value="男"></property>
  749. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  750.     <bean id="student" ></bean>
  751. </beans><?xml version="1.0" encoding="UTF-8"?>
  752. <beans xmlns="http://www.springframework.org/schema/beans"
  753.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  754.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  755. <bean  scope="prototype">
  756.        <property name="sid" value="1001"></property>
  757.        <property name="sname" value="张三"></property>
  758.        <property name="gender" value="男"></property>
  759. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  760.     <bean id="student" ></bean>
  761. </beans>System.out.println("---------------------进入了类:"+point.getTarget().getClass().getName());<?xml version="1.0" encoding="UTF-8"?>
  762. <beans xmlns="http://www.springframework.org/schema/beans"
  763.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  764.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  765. <bean  scope="prototype">
  766.        <property name="sid" value="1001"></property>
  767.        <property name="sname" value="张三"></property>
  768.        <property name="gender" value="男"></property>
  769. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  770.     <bean id="student" ></bean>
  771. </beans><?xml version="1.0" encoding="UTF-8"?>
  772. <beans xmlns="http://www.springframework.org/schema/beans"
  773.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  774.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  775. <bean  scope="prototype">
  776.        <property name="sid" value="1001"></property>
  777.        <property name="sname" value="张三"></property>
  778.        <property name="gender" value="男"></property>
  779. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  780.     <bean id="student" ></bean>
  781. </beans>System.out.println("---------------------进入了方法:"+point.getSignature().getName());<?xml version="1.0" encoding="UTF-8"?>
  782. <beans xmlns="http://www.springframework.org/schema/beans"
  783.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  784.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  785. <bean  scope="prototype">
  786.        <property name="sid" value="1001"></property>
  787.        <property name="sname" value="张三"></property>
  788.        <property name="gender" value="男"></property>
  789. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  790.     <bean id="student" ></bean>
  791. </beans><?xml version="1.0" encoding="UTF-8"?>
  792. <beans xmlns="http://www.springframework.org/schema/beans"
  793.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  794.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  795. <bean  scope="prototype">
  796.        <property name="sid" value="1001"></property>
  797.        <property name="sname" value="张三"></property>
  798.        <property name="gender" value="男"></property>
  799. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  800.     <bean id="student" ></bean>
  801. </beans>System.out.println("---------------------传入了参数:"+point.getArgs()[0]);<?xml version="1.0" encoding="UTF-8"?>
  802. <beans xmlns="http://www.springframework.org/schema/beans"
  803.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  804.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  805. <bean  scope="prototype">
  806.        <property name="sid" value="1001"></property>
  807.        <property name="sname" value="张三"></property>
  808.        <property name="gender" value="男"></property>
  809. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  810.     <bean id="student" ></bean>
  811. </beans><?xml version="1.0" encoding="UTF-8"?>
  812. <beans xmlns="http://www.springframework.org/schema/beans"
  813.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  814.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  815. <bean  scope="prototype">
  816.        <property name="sid" value="1001"></property>
  817.        <property name="sname" value="张三"></property>
  818.        <property name="gender" value="男"></property>
  819. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  820.     <bean id="student" ></bean>
  821. </beans>System.out.println(".------------------------------脱离最终增强---------------------");<?xml version="1.0" encoding="UTF-8"?>
  822. <beans xmlns="http://www.springframework.org/schema/beans"
  823.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  824.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  825. <bean  scope="prototype">
  826.        <property name="sid" value="1001"></property>
  827.        <property name="sname" value="张三"></property>
  828.        <property name="gender" value="男"></property>
  829. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  830.     <bean id="student" ></bean>
  831. </beans>}}
复制代码
  1. <bean ></bean>       
  2. <bean  id="myLogger"></bean>
  3. <aop:aspectj-autoproxy></aop:aspectj-autoproxy>       
复制代码
3 spring整合mybatis

​        1)添加jar

​        2) 创建配置文件:
  1. datasources.properties
  2. url=jdbc:mysql://127.0.0.1:3306/goods?serverTimezone=Asia/Shanghai
  3. driver=com.mysql.cj.jdbc.Driver
  4. user=root
  5. password=root
复制代码
  1. mybatis-config.xml<?xml version="1.0" encoding="UTF-8"?>
  2. <beans xmlns="http://www.springframework.org/schema/beans"
  3.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  4.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  5. <bean  scope="prototype">
  6.        <property name="sid" value="1001"></property>
  7.        <property name="sname" value="张三"></property>
  8.        <property name="gender" value="男"></property>
  9. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  10.     <bean id="student" ></bean>
  11. </beans><?xml version="1.0" encoding="UTF-8"?>
  12. <beans xmlns="http://www.springframework.org/schema/beans"
  13.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  14.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  15. <bean  scope="prototype">
  16.        <property name="sid" value="1001"></property>
  17.        <property name="sname" value="张三"></property>
  18.        <property name="gender" value="男"></property>
  19. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  20.     <bean id="student" ></bean>
  21. </beans><?xml version="1.0" encoding="UTF-8"?>
  22. <beans xmlns="http://www.springframework.org/schema/beans"
  23.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  24.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  25. <bean  scope="prototype">
  26.        <property name="sid" value="1001"></property>
  27.        <property name="sname" value="张三"></property>
  28.        <property name="gender" value="男"></property>
  29. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  30.     <bean id="student" ></bean>
  31. </beans><?xml version="1.0" encoding="UTF-8"?>
  32. <beans xmlns="http://www.springframework.org/schema/beans"
  33.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  34.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  35. <bean  scope="prototype">
  36.        <property name="sid" value="1001"></property>
  37.        <property name="sname" value="张三"></property>
  38.        <property name="gender" value="男"></property>
  39. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  40.     <bean id="student" ></bean>
  41. </beans><bean ></bean>       
  42. <bean  id="myLogger"></bean>
  43. <aop:aspectj-autoproxy></aop:aspectj-autoproxy>               
复制代码
  1. spring-dao.xml<?xml version="1.0" encoding="UTF-8"?>
  2. <beans xmlns="http://www.springframework.org/schema/beans"
  3.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  4.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  5. <bean  scope="prototype">
  6.        <property name="sid" value="1001"></property>
  7.        <property name="sname" value="张三"></property>
  8.        <property name="gender" value="男"></property>
  9. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  10.     <bean id="student" ></bean>
  11. </beans><?xml version="1.0" encoding="UTF-8"?>
  12. <beans xmlns="http://www.springframework.org/schema/beans"
  13.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  14.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  15. <bean  scope="prototype">
  16.        <property name="sid" value="1001"></property>
  17.        <property name="sname" value="张三"></property>
  18.        <property name="gender" value="男"></property>
  19. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  20.     <bean id="student" ></bean>
  21. </beans><?xml version="1.0" encoding="UTF-8"?>
  22. <beans xmlns="http://www.springframework.org/schema/beans"
  23.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  24.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  25. <bean  scope="prototype">
  26.        <property name="sid" value="1001"></property>
  27.        <property name="sname" value="张三"></property>
  28.        <property name="gender" value="男"></property>
  29. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  30.     <bean id="student" ></bean>
  31. </beans><?xml version="1.0" encoding="UTF-8"?>
  32. <beans xmlns="http://www.springframework.org/schema/beans"
  33.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  34.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  35. <bean  scope="prototype">
  36.        <property name="sid" value="1001"></property>
  37.        <property name="sname" value="张三"></property>
  38.        <property name="gender" value="男"></property>
  39. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  40.     <bean id="student" ></bean>
  41. </beans><?xml version="1.0" encoding="UTF-8"?>
  42. <beans xmlns="http://www.springframework.org/schema/beans"
  43.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  44.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  45. <bean  scope="prototype">
  46.        <property name="sid" value="1001"></property>
  47.        <property name="sname" value="张三"></property>
  48.        <property name="gender" value="男"></property>
  49. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  50.     <bean id="student" ></bean>
  51. </beans><?xml version="1.0" encoding="UTF-8"?>
  52. <beans xmlns="http://www.springframework.org/schema/beans"
  53.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  54.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  55. <bean  scope="prototype">
  56.        <property name="sid" value="1001"></property>
  57.        <property name="sname" value="张三"></property>
  58.        <property name="gender" value="男"></property>
  59. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  60.     <bean id="student" ></bean>
  61. </beans><?xml version="1.0" encoding="UTF-8"?>
  62. <beans xmlns="http://www.springframework.org/schema/beans"
  63.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  64.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  65. <bean  scope="prototype">
  66.        <property name="sid" value="1001"></property>
  67.        <property name="sname" value="张三"></property>
  68.        <property name="gender" value="男"></property>
  69. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  70.     <bean id="student" ></bean>
  71. </beans><?xml version="1.0" encoding="UTF-8"?>
  72. <beans xmlns="http://www.springframework.org/schema/beans"
  73.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  74.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  75. <bean  scope="prototype">
  76.        <property name="sid" value="1001"></property>
  77.        <property name="sname" value="张三"></property>
  78.        <property name="gender" value="男"></property>
  79. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  80.     <bean id="student" ></bean>
  81. </beans><?xml version="1.0" encoding="UTF-8"?>
  82. <beans xmlns="http://www.springframework.org/schema/beans"
  83.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  84.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  85. <bean  scope="prototype">
  86.        <property name="sid" value="1001"></property>
  87.        <property name="sname" value="张三"></property>
  88.        <property name="gender" value="男"></property>
  89. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  90.     <bean id="student" ></bean>
  91. </beans><?xml version="1.0" encoding="UTF-8"?>
  92. <beans xmlns="http://www.springframework.org/schema/beans"
  93.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  94.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  95. <bean  scope="prototype">
  96.        <property name="sid" value="1001"></property>
  97.        <property name="sname" value="张三"></property>
  98.        <property name="gender" value="男"></property>
  99. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  100.     <bean id="student" ></bean>
  101. </beans><?xml version="1.0" encoding="UTF-8"?>
  102. <beans xmlns="http://www.springframework.org/schema/beans"
  103.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  104.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  105. <bean  scope="prototype">
  106.        <property name="sid" value="1001"></property>
  107.        <property name="sname" value="张三"></property>
  108.        <property name="gender" value="男"></property>
  109. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  110.     <bean id="student" ></bean>
  111. </beans><?xml version="1.0" encoding="UTF-8"?>
  112. <beans xmlns="http://www.springframework.org/schema/beans"
  113.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  114.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  115. <bean  scope="prototype">
  116.        <property name="sid" value="1001"></property>
  117.        <property name="sname" value="张三"></property>
  118.        <property name="gender" value="男"></property>
  119. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  120.     <bean id="student" ></bean>
  121. </beans><?xml version="1.0" encoding="UTF-8"?>
  122. <beans xmlns="http://www.springframework.org/schema/beans"
  123.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  124.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  125. <bean  scope="prototype">
  126.        <property name="sid" value="1001"></property>
  127.        <property name="sname" value="张三"></property>
  128.        <property name="gender" value="男"></property>
  129. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  130.     <bean id="student" ></bean>
  131. </beans><?xml version="1.0" encoding="UTF-8"?>
  132. <beans xmlns="http://www.springframework.org/schema/beans"
  133.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  134.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  135. <bean  scope="prototype">
  136.        <property name="sid" value="1001"></property>
  137.        <property name="sname" value="张三"></property>
  138.        <property name="gender" value="男"></property>
  139. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  140.     <bean id="student" ></bean>
  141. </beans><?xml version="1.0" encoding="UTF-8"?>
  142. <beans xmlns="http://www.springframework.org/schema/beans"
  143.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  144.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  145. <bean  scope="prototype">
  146.        <property name="sid" value="1001"></property>
  147.        <property name="sname" value="张三"></property>
  148.        <property name="gender" value="男"></property>
  149. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  150.     <bean id="student" ></bean>
  151. </beans><?xml version="1.0" encoding="UTF-8"?>
  152. <beans xmlns="http://www.springframework.org/schema/beans"
  153.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  154.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  155. <bean  scope="prototype">
  156.        <property name="sid" value="1001"></property>
  157.        <property name="sname" value="张三"></property>
  158.        <property name="gender" value="男"></property>
  159. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  160.     <bean id="student" ></bean>
  161. </beans><?xml version="1.0" encoding="UTF-8"?>
  162. <beans xmlns="http://www.springframework.org/schema/beans"
  163.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  164.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  165. <bean  scope="prototype">
  166.        <property name="sid" value="1001"></property>
  167.        <property name="sname" value="张三"></property>
  168.        <property name="gender" value="男"></property>
  169. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  170.     <bean id="student" ></bean>
  171. </beans><?xml version="1.0" encoding="UTF-8"?>
  172. <beans xmlns="http://www.springframework.org/schema/beans"
  173.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  174.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  175. <bean  scope="prototype">
  176.        <property name="sid" value="1001"></property>
  177.        <property name="sname" value="张三"></property>
  178.        <property name="gender" value="男"></property>
  179. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  180.     <bean id="student" ></bean>
  181. </beans><?xml version="1.0" encoding="UTF-8"?>
  182. <beans xmlns="http://www.springframework.org/schema/beans"
  183.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  184.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  185. <bean  scope="prototype">
  186.        <property name="sid" value="1001"></property>
  187.        <property name="sname" value="张三"></property>
  188.        <property name="gender" value="男"></property>
  189. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  190.     <bean id="student" ></bean>
  191. </beans><?xml version="1.0" encoding="UTF-8"?>
  192. <beans xmlns="http://www.springframework.org/schema/beans"
  193.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  194.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  195. <bean  scope="prototype">
  196.        <property name="sid" value="1001"></property>
  197.        <property name="sname" value="张三"></property>
  198.        <property name="gender" value="男"></property>
  199. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  200.     <bean id="student" ></bean>
  201. </beans><?xml version="1.0" encoding="UTF-8"?>
  202. <beans xmlns="http://www.springframework.org/schema/beans"
  203.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  204.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  205. <bean  scope="prototype">
  206.        <property name="sid" value="1001"></property>
  207.        <property name="sname" value="张三"></property>
  208.        <property name="gender" value="男"></property>
  209. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  210.     <bean id="student" ></bean>
  211. </beans><?xml version="1.0" encoding="UTF-8"?>
  212. <beans xmlns="http://www.springframework.org/schema/beans"
  213.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  214.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  215. <bean  scope="prototype">
  216.        <property name="sid" value="1001"></property>
  217.        <property name="sname" value="张三"></property>
  218.        <property name="gender" value="男"></property>
  219. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  220.     <bean id="student" ></bean>
  221. </beans><?xml version="1.0" encoding="UTF-8"?>
  222. <beans xmlns="http://www.springframework.org/schema/beans"
  223.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  224.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  225. <bean  scope="prototype">
  226.        <property name="sid" value="1001"></property>
  227.        <property name="sname" value="张三"></property>
  228.        <property name="gender" value="男"></property>
  229. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  230.     <bean id="student" ></bean>
  231. </beans><?xml version="1.0" encoding="UTF-8"?>
  232. <beans xmlns="http://www.springframework.org/schema/beans"
  233.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  234.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  235. <bean  scope="prototype">
  236.        <property name="sid" value="1001"></property>
  237.        <property name="sname" value="张三"></property>
  238.        <property name="gender" value="男"></property>
  239. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  240.     <bean id="student" ></bean>
  241. </beans><?xml version="1.0" encoding="UTF-8"?>
  242. <beans xmlns="http://www.springframework.org/schema/beans"
  243.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  244.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  245. <bean  scope="prototype">
  246.        <property name="sid" value="1001"></property>
  247.        <property name="sname" value="张三"></property>
  248.        <property name="gender" value="男"></property>
  249. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  250.     <bean id="student" ></bean>
  251. </beans>
复制代码
  1. spting-service.xml<?xml version="1.0" encoding="UTF-8"?>
  2. <beans xmlns="http://www.springframework.org/schema/beans"
  3.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  4.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  5. <bean  scope="prototype">
  6.        <property name="sid" value="1001"></property>
  7.        <property name="sname" value="张三"></property>
  8.        <property name="gender" value="男"></property>
  9. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  10.     <bean id="student" ></bean>
  11. </beans><?xml version="1.0" encoding="UTF-8"?>
  12. <beans xmlns="http://www.springframework.org/schema/beans"
  13.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  14.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  15. <bean  scope="prototype">
  16.        <property name="sid" value="1001"></property>
  17.        <property name="sname" value="张三"></property>
  18.        <property name="gender" value="男"></property>
  19. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  20.     <bean id="student" ></bean>
  21. </beans>
复制代码
实体类: Goods.java(略)
Mapper接口: GoodsMapper.java(略)
服务层: GoodsService.java(略)
4 spring事务管理

1)基于配置文件的事务

当在service的业务方法中, 对数据库有1个以上的操作时, 如果方法内任何一个地方出现异常, 那么对数据的所有操作都需要回滚, 要么全部都执行成功, 要么都执行后失败!
  1. spring-dao.xml<?xml version="1.0" encoding="UTF-8"?>
  2. <beans xmlns="http://www.springframework.org/schema/beans"
  3.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  4.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  5. <bean  scope="prototype">
  6.        <property name="sid" value="1001"></property>
  7.        <property name="sname" value="张三"></property>
  8.        <property name="gender" value="男"></property>
  9. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  10.     <bean id="student" ></bean>
  11. </beans><?xml version="1.0" encoding="UTF-8"?>
  12. <beans xmlns="http://www.springframework.org/schema/beans"
  13.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  14.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  15. <bean  scope="prototype">
  16.        <property name="sid" value="1001"></property>
  17.        <property name="sname" value="张三"></property>
  18.        <property name="gender" value="男"></property>
  19. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  20.     <bean id="student" ></bean>
  21. </beans><?xml version="1.0" encoding="UTF-8"?>
  22. <beans xmlns="http://www.springframework.org/schema/beans"
  23.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  24.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  25. <bean  scope="prototype">
  26.        <property name="sid" value="1001"></property>
  27.        <property name="sname" value="张三"></property>
  28.        <property name="gender" value="男"></property>
  29. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  30.     <bean id="student" ></bean>
  31. </beans><?xml version="1.0" encoding="UTF-8"?>
  32. <beans xmlns="http://www.springframework.org/schema/beans"
  33.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  34.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  35. <bean  scope="prototype">
  36.        <property name="sid" value="1001"></property>
  37.        <property name="sname" value="张三"></property>
  38.        <property name="gender" value="男"></property>
  39. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  40.     <bean id="student" ></bean>
  41. </beans><?xml version="1.0" encoding="UTF-8"?>
  42. <beans xmlns="http://www.springframework.org/schema/beans"
  43.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  44.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  45. <bean  scope="prototype">
  46.        <property name="sid" value="1001"></property>
  47.        <property name="sname" value="张三"></property>
  48.        <property name="gender" value="男"></property>
  49. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  50.     <bean id="student" ></bean>
  51. </beans><?xml version="1.0" encoding="UTF-8"?>
  52. <beans xmlns="http://www.springframework.org/schema/beans"
  53.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  54.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  55. <bean  scope="prototype">
  56.        <property name="sid" value="1001"></property>
  57.        <property name="sname" value="张三"></property>
  58.        <property name="gender" value="男"></property>
  59. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  60.     <bean id="student" ></bean>
  61. </beans><?xml version="1.0" encoding="UTF-8"?>
  62. <beans xmlns="http://www.springframework.org/schema/beans"
  63.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  64.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  65. <bean  scope="prototype">
  66.        <property name="sid" value="1001"></property>
  67.        <property name="sname" value="张三"></property>
  68.        <property name="gender" value="男"></property>
  69. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  70.     <bean id="student" ></bean>
  71. </beans><?xml version="1.0" encoding="UTF-8"?>
  72. <beans xmlns="http://www.springframework.org/schema/beans"
  73.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  74.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  75. <bean  scope="prototype">
  76.        <property name="sid" value="1001"></property>
  77.        <property name="sname" value="张三"></property>
  78.        <property name="gender" value="男"></property>
  79. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  80.     <bean id="student" ></bean>
  81. </beans><?xml version="1.0" encoding="UTF-8"?>
  82. <beans xmlns="http://www.springframework.org/schema/beans"
  83.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  84.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  85. <bean  scope="prototype">
  86.        <property name="sid" value="1001"></property>
  87.        <property name="sname" value="张三"></property>
  88.        <property name="gender" value="男"></property>
  89. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  90.     <bean id="student" ></bean>
  91. </beans><?xml version="1.0" encoding="UTF-8"?>
  92. <beans xmlns="http://www.springframework.org/schema/beans"
  93.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  94.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  95. <bean  scope="prototype">
  96.        <property name="sid" value="1001"></property>
  97.        <property name="sname" value="张三"></property>
  98.        <property name="gender" value="男"></property>
  99. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  100.     <bean id="student" ></bean>
  101. </beans><?xml version="1.0" encoding="UTF-8"?>
  102. <beans xmlns="http://www.springframework.org/schema/beans"
  103.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  104.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  105. <bean  scope="prototype">
  106.        <property name="sid" value="1001"></property>
  107.        <property name="sname" value="张三"></property>
  108.        <property name="gender" value="男"></property>
  109. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  110.     <bean id="student" ></bean>
  111. </beans><?xml version="1.0" encoding="UTF-8"?>
  112. <beans xmlns="http://www.springframework.org/schema/beans"
  113.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  114.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  115. <bean  scope="prototype">
  116.        <property name="sid" value="1001"></property>
  117.        <property name="sname" value="张三"></property>
  118.        <property name="gender" value="男"></property>
  119. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  120.     <bean id="student" ></bean>
  121. </beans><?xml version="1.0" encoding="UTF-8"?>
  122. <beans xmlns="http://www.springframework.org/schema/beans"
  123.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  124.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  125. <bean  scope="prototype">
  126.        <property name="sid" value="1001"></property>
  127.        <property name="sname" value="张三"></property>
  128.        <property name="gender" value="男"></property>
  129. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  130.     <bean id="student" ></bean>
  131. </beans><?xml version="1.0" encoding="UTF-8"?>
  132. <beans xmlns="http://www.springframework.org/schema/beans"
  133.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  134.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  135. <bean  scope="prototype">
  136.        <property name="sid" value="1001"></property>
  137.        <property name="sname" value="张三"></property>
  138.        <property name="gender" value="男"></property>
  139. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  140.     <bean id="student" ></bean>
  141. </beans><?xml version="1.0" encoding="UTF-8"?>
  142. <beans xmlns="http://www.springframework.org/schema/beans"
  143.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  144.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  145. <bean  scope="prototype">
  146.        <property name="sid" value="1001"></property>
  147.        <property name="sname" value="张三"></property>
  148.        <property name="gender" value="男"></property>
  149. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  150.     <bean id="student" ></bean>
  151. </beans><?xml version="1.0" encoding="UTF-8"?>
  152. <beans xmlns="http://www.springframework.org/schema/beans"
  153.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  154.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  155. <bean  scope="prototype">
  156.        <property name="sid" value="1001"></property>
  157.        <property name="sname" value="张三"></property>
  158.        <property name="gender" value="男"></property>
  159. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  160.     <bean id="student" ></bean>
  161. </beans><?xml version="1.0" encoding="UTF-8"?>
  162. <beans xmlns="http://www.springframework.org/schema/beans"
  163.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  164.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  165. <bean  scope="prototype">
  166.        <property name="sid" value="1001"></property>
  167.        <property name="sname" value="张三"></property>
  168.        <property name="gender" value="男"></property>
  169. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  170.     <bean id="student" ></bean>
  171. </beans><?xml version="1.0" encoding="UTF-8"?>
  172. <beans xmlns="http://www.springframework.org/schema/beans"
  173.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  174.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  175. <bean  scope="prototype">
  176.        <property name="sid" value="1001"></property>
  177.        <property name="sname" value="张三"></property>
  178.        <property name="gender" value="男"></property>
  179. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  180.     <bean id="student" ></bean>
  181. </beans><?xml version="1.0" encoding="UTF-8"?>
  182. <beans xmlns="http://www.springframework.org/schema/beans"
  183.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  184.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  185. <bean  scope="prototype">
  186.        <property name="sid" value="1001"></property>
  187.        <property name="sname" value="张三"></property>
  188.        <property name="gender" value="男"></property>
  189. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  190.     <bean id="student" ></bean>
  191. </beans><?xml version="1.0" encoding="UTF-8"?>
  192. <beans xmlns="http://www.springframework.org/schema/beans"
  193.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  194.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  195. <bean  scope="prototype">
  196.        <property name="sid" value="1001"></property>
  197.        <property name="sname" value="张三"></property>
  198.        <property name="gender" value="男"></property>
  199. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  200.     <bean id="student" ></bean>
  201. </beans><?xml version="1.0" encoding="UTF-8"?>
  202. <beans xmlns="http://www.springframework.org/schema/beans"
  203.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  204.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  205. <bean  scope="prototype">
  206.        <property name="sid" value="1001"></property>
  207.        <property name="sname" value="张三"></property>
  208.        <property name="gender" value="男"></property>
  209. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  210.     <bean id="student" ></bean>
  211. </beans><?xml version="1.0" encoding="UTF-8"?>
  212. <beans xmlns="http://www.springframework.org/schema/beans"
  213.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  214.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  215. <bean  scope="prototype">
  216.        <property name="sid" value="1001"></property>
  217.        <property name="sname" value="张三"></property>
  218.        <property name="gender" value="男"></property>
  219. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  220.     <bean id="student" ></bean>
  221. </beans><?xml version="1.0" encoding="UTF-8"?>
  222. <beans xmlns="http://www.springframework.org/schema/beans"
  223.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  224.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  225. <bean  scope="prototype">
  226.        <property name="sid" value="1001"></property>
  227.        <property name="sname" value="张三"></property>
  228.        <property name="gender" value="男"></property>
  229. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  230.     <bean id="student" ></bean>
  231. </beans><?xml version="1.0" encoding="UTF-8"?>
  232. <beans xmlns="http://www.springframework.org/schema/beans"
  233.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  234.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  235. <bean  scope="prototype">
  236.        <property name="sid" value="1001"></property>
  237.        <property name="sname" value="张三"></property>
  238.        <property name="gender" value="男"></property>
  239. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  240.     <bean id="student" ></bean>
  241. </beans><?xml version="1.0" encoding="UTF-8"?>
  242. <beans xmlns="http://www.springframework.org/schema/beans"
  243.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  244.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  245. <bean  scope="prototype">
  246.        <property name="sid" value="1001"></property>
  247.        <property name="sname" value="张三"></property>
  248.        <property name="gender" value="男"></property>
  249. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  250.     <bean id="student" ></bean>
  251. </beans><?xml version="1.0" encoding="UTF-8"?>
  252. <beans xmlns="http://www.springframework.org/schema/beans"
  253.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  254.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  255. <bean  scope="prototype">
  256.        <property name="sid" value="1001"></property>
  257.        <property name="sname" value="张三"></property>
  258.        <property name="gender" value="男"></property>
  259. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  260.     <bean id="student" ></bean>
  261. </beans><?xml version="1.0" encoding="UTF-8"?>
  262. <beans xmlns="http://www.springframework.org/schema/beans"
  263.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  264.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  265. <bean  scope="prototype">
  266.        <property name="sid" value="1001"></property>
  267.        <property name="sname" value="张三"></property>
  268.        <property name="gender" value="男"></property>
  269. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  270.     <bean id="student" ></bean>
  271. </beans><?xml version="1.0" encoding="UTF-8"?>
  272. <beans xmlns="http://www.springframework.org/schema/beans"
  273.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  274.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  275. <bean  scope="prototype">
  276.        <property name="sid" value="1001"></property>
  277.        <property name="sname" value="张三"></property>
  278.        <property name="gender" value="男"></property>
  279. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  280.     <bean id="student" ></bean>
  281. </beans><?xml version="1.0" encoding="UTF-8"?>
  282. <beans xmlns="http://www.springframework.org/schema/beans"
  283.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  284.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  285. <bean  scope="prototype">
  286.        <property name="sid" value="1001"></property>
  287.        <property name="sname" value="张三"></property>
  288.        <property name="gender" value="男"></property>
  289. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  290.     <bean id="student" ></bean>
  291. </beans><?xml version="1.0" encoding="UTF-8"?>
  292. <beans xmlns="http://www.springframework.org/schema/beans"
  293.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  294.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  295. <bean  scope="prototype">
  296.        <property name="sid" value="1001"></property>
  297.        <property name="sname" value="张三"></property>
  298.        <property name="gender" value="男"></property>
  299. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  300.     <bean id="student" ></bean>
  301. </beans><?xml version="1.0" encoding="UTF-8"?>
  302. <beans xmlns="http://www.springframework.org/schema/beans"
  303.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  304.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  305. <bean  scope="prototype">
  306.        <property name="sid" value="1001"></property>
  307.        <property name="sname" value="张三"></property>
  308.        <property name="gender" value="男"></property>
  309. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  310.     <bean id="student" ></bean>
  311. </beans><?xml version="1.0" encoding="UTF-8"?>
  312. <beans xmlns="http://www.springframework.org/schema/beans"
  313.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  314.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  315. <bean  scope="prototype">
  316.        <property name="sid" value="1001"></property>
  317.        <property name="sname" value="张三"></property>
  318.        <property name="gender" value="男"></property>
  319. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  320.     <bean id="student" ></bean>
  321. </beans><?xml version="1.0" encoding="UTF-8"?>
  322. <beans xmlns="http://www.springframework.org/schema/beans"
  323.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  324.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  325. <bean  scope="prototype">
  326.        <property name="sid" value="1001"></property>
  327.        <property name="sname" value="张三"></property>
  328.        <property name="gender" value="男"></property>
  329. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  330.     <bean id="student" ></bean>
  331. </beans><?xml version="1.0" encoding="UTF-8"?>
  332. <beans xmlns="http://www.springframework.org/schema/beans"
  333.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  334.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  335. <bean  scope="prototype">
  336.        <property name="sid" value="1001"></property>
  337.        <property name="sname" value="张三"></property>
  338.        <property name="gender" value="男"></property>
  339. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  340.     <bean id="student" ></bean>
  341. </beans><?xml version="1.0" encoding="UTF-8"?>
  342. <beans xmlns="http://www.springframework.org/schema/beans"
  343.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  344.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  345. <bean  scope="prototype">
  346.        <property name="sid" value="1001"></property>
  347.        <property name="sname" value="张三"></property>
  348.        <property name="gender" value="男"></property>
  349. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  350.     <bean id="student" ></bean>
  351. </beans><?xml version="1.0" encoding="UTF-8"?>
  352. <beans xmlns="http://www.springframework.org/schema/beans"
  353.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  354.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  355. <bean  scope="prototype">
  356.        <property name="sid" value="1001"></property>
  357.        <property name="sname" value="张三"></property>
  358.        <property name="gender" value="男"></property>
  359. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  360.     <bean id="student" ></bean>
  361. </beans><?xml version="1.0" encoding="UTF-8"?>
  362. <beans xmlns="http://www.springframework.org/schema/beans"
  363.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  364.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  365. <bean  scope="prototype">
  366.        <property name="sid" value="1001"></property>
  367.        <property name="sname" value="张三"></property>
  368.        <property name="gender" value="男"></property>
  369. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  370.     <bean id="student" ></bean>
  371. </beans><?xml version="1.0" encoding="UTF-8"?>
  372. <beans xmlns="http://www.springframework.org/schema/beans"
  373.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  374.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  375. <bean  scope="prototype">
  376.        <property name="sid" value="1001"></property>
  377.        <property name="sname" value="张三"></property>
  378.        <property name="gender" value="男"></property>
  379. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  380.     <bean id="student" ></bean>
  381. </beans>
复制代码
  1. GoodsService.java<?xml version="1.0" encoding="UTF-8"?>
  2. <beans xmlns="http://www.springframework.org/schema/beans"
  3.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  4.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  5. <bean  scope="prototype">
  6.        <property name="sid" value="1001"></property>
  7.        <property name="sname" value="张三"></property>
  8.        <property name="gender" value="男"></property>
  9. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  10.     <bean id="student" ></bean>
  11. </beans><?xml version="1.0" encoding="UTF-8"?>
  12. <beans xmlns="http://www.springframework.org/schema/beans"
  13.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  14.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  15. <bean  scope="prototype">
  16.        <property name="sid" value="1001"></property>
  17.        <property name="sname" value="张三"></property>
  18.        <property name="gender" value="男"></property>
  19. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  20.     <bean id="student" ></bean>
  21. </beans>public void insert(){<?xml version="1.0" encoding="UTF-8"?>
  22. <beans xmlns="http://www.springframework.org/schema/beans"
  23.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  24.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  25. <bean  scope="prototype">
  26.        <property name="sid" value="1001"></property>
  27.        <property name="sname" value="张三"></property>
  28.        <property name="gender" value="男"></property>
  29. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  30.     <bean id="student" ></bean>
  31. </beans><?xml version="1.0" encoding="UTF-8"?>
  32. <beans xmlns="http://www.springframework.org/schema/beans"
  33.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  34.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  35. <bean  scope="prototype">
  36.        <property name="sid" value="1001"></property>
  37.        <property name="sname" value="张三"></property>
  38.        <property name="gender" value="男"></property>
  39. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  40.     <bean id="student" ></bean>
  41. </beans>Goods goods = new Goods();<?xml version="1.0" encoding="UTF-8"?>
  42. <beans xmlns="http://www.springframework.org/schema/beans"
  43.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  44.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  45. <bean  scope="prototype">
  46.        <property name="sid" value="1001"></property>
  47.        <property name="sname" value="张三"></property>
  48.        <property name="gender" value="男"></property>
  49. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  50.     <bean id="student" ></bean>
  51. </beans><?xml version="1.0" encoding="UTF-8"?>
  52. <beans xmlns="http://www.springframework.org/schema/beans"
  53.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  54.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  55. <bean  scope="prototype">
  56.        <property name="sid" value="1001"></property>
  57.        <property name="sname" value="张三"></property>
  58.        <property name="gender" value="男"></property>
  59. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  60.     <bean id="student" ></bean>
  61. </beans>goods.setGname("国土1");<?xml version="1.0" encoding="UTF-8"?>
  62. <beans xmlns="http://www.springframework.org/schema/beans"
  63.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  64.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  65. <bean  scope="prototype">
  66.        <property name="sid" value="1001"></property>
  67.        <property name="sname" value="张三"></property>
  68.        <property name="gender" value="男"></property>
  69. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  70.     <bean id="student" ></bean>
  71. </beans><?xml version="1.0" encoding="UTF-8"?>
  72. <beans xmlns="http://www.springframework.org/schema/beans"
  73.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  74.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  75. <bean  scope="prototype">
  76.        <property name="sid" value="1001"></property>
  77.        <property name="sname" value="张三"></property>
  78.        <property name="gender" value="男"></property>
  79. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  80.     <bean id="student" ></bean>
  81. </beans>goods.setGcount(100);<?xml version="1.0" encoding="UTF-8"?>
  82. <beans xmlns="http://www.springframework.org/schema/beans"
  83.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  84.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  85. <bean  scope="prototype">
  86.        <property name="sid" value="1001"></property>
  87.        <property name="sname" value="张三"></property>
  88.        <property name="gender" value="男"></property>
  89. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  90.     <bean id="student" ></bean>
  91. </beans><?xml version="1.0" encoding="UTF-8"?>
  92. <beans xmlns="http://www.springframework.org/schema/beans"
  93.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  94.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  95. <bean  scope="prototype">
  96.        <property name="sid" value="1001"></property>
  97.        <property name="sname" value="张三"></property>
  98.        <property name="gender" value="男"></property>
  99. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  100.     <bean id="student" ></bean>
  101. </beans>goods.setGprice(5.6);<?xml version="1.0" encoding="UTF-8"?>
  102. <beans xmlns="http://www.springframework.org/schema/beans"
  103.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  104.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  105. <bean  scope="prototype">
  106.        <property name="sid" value="1001"></property>
  107.        <property name="sname" value="张三"></property>
  108.        <property name="gender" value="男"></property>
  109. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  110.     <bean id="student" ></bean>
  111. </beans><?xml version="1.0" encoding="UTF-8"?>
  112. <beans xmlns="http://www.springframework.org/schema/beans"
  113.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  114.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  115. <bean  scope="prototype">
  116.        <property name="sid" value="1001"></property>
  117.        <property name="sname" value="张三"></property>
  118.        <property name="gender" value="男"></property>
  119. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  120.     <bean id="student" ></bean>
  121. </beans>goods.setCreateTime(new Date());<?xml version="1.0" encoding="UTF-8"?>
  122. <beans xmlns="http://www.springframework.org/schema/beans"
  123.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  124.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  125. <bean  scope="prototype">
  126.        <property name="sid" value="1001"></property>
  127.        <property name="sname" value="张三"></property>
  128.        <property name="gender" value="男"></property>
  129. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  130.     <bean id="student" ></bean>
  131. </beans><?xml version="1.0" encoding="UTF-8"?>
  132. <beans xmlns="http://www.springframework.org/schema/beans"
  133.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  134.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  135. <bean  scope="prototype">
  136.        <property name="sid" value="1001"></property>
  137.        <property name="sname" value="张三"></property>
  138.        <property name="gender" value="男"></property>
  139. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  140.     <bean id="student" ></bean>
  141. </beans>goods.setTid(1);<?xml version="1.0" encoding="UTF-8"?>
  142. <beans xmlns="http://www.springframework.org/schema/beans"
  143.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  144.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  145. <bean  scope="prototype">
  146.        <property name="sid" value="1001"></property>
  147.        <property name="sname" value="张三"></property>
  148.        <property name="gender" value="男"></property>
  149. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  150.     <bean id="student" ></bean>
  151. </beans><?xml version="1.0" encoding="UTF-8"?>
  152. <beans xmlns="http://www.springframework.org/schema/beans"
  153.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  154.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  155. <bean  scope="prototype">
  156.        <property name="sid" value="1001"></property>
  157.        <property name="sname" value="张三"></property>
  158.        <property name="gender" value="男"></property>
  159. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  160.     <bean id="student" ></bean>
  161. </beans>int i =  goodsMapper.insert(goods);<?xml version="1.0" encoding="UTF-8"?>
  162. <beans xmlns="http://www.springframework.org/schema/beans"
  163.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  164.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  165. <bean  scope="prototype">
  166.        <property name="sid" value="1001"></property>
  167.        <property name="sname" value="张三"></property>
  168.        <property name="gender" value="男"></property>
  169. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  170.     <bean id="student" ></bean>
  171. </beans><?xml version="1.0" encoding="UTF-8"?>
  172. <beans xmlns="http://www.springframework.org/schema/beans"
  173.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  174.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  175. <bean  scope="prototype">
  176.        <property name="sid" value="1001"></property>
  177.        <property name="sname" value="张三"></property>
  178.        <property name="gender" value="男"></property>
  179. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  180.     <bean id="student" ></bean>
  181. </beans>int a = 10/0;<?xml version="1.0" encoding="UTF-8"?>
  182. <beans xmlns="http://www.springframework.org/schema/beans"
  183.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  184.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  185. <bean  scope="prototype">
  186.        <property name="sid" value="1001"></property>
  187.        <property name="sname" value="张三"></property>
  188.        <property name="gender" value="男"></property>
  189. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  190.     <bean id="student" ></bean>
  191. </beans><?xml version="1.0" encoding="UTF-8"?>
  192. <beans xmlns="http://www.springframework.org/schema/beans"
  193.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  194.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  195. <bean  scope="prototype">
  196.        <property name="sid" value="1001"></property>
  197.        <property name="sname" value="张三"></property>
  198.        <property name="gender" value="男"></property>
  199. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  200.     <bean id="student" ></bean>
  201. </beans>Goods goods1 = new Goods();<?xml version="1.0" encoding="UTF-8"?>
  202. <beans xmlns="http://www.springframework.org/schema/beans"
  203.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  204.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  205. <bean  scope="prototype">
  206.        <property name="sid" value="1001"></property>
  207.        <property name="sname" value="张三"></property>
  208.        <property name="gender" value="男"></property>
  209. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  210.     <bean id="student" ></bean>
  211. </beans><?xml version="1.0" encoding="UTF-8"?>
  212. <beans xmlns="http://www.springframework.org/schema/beans"
  213.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  214.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  215. <bean  scope="prototype">
  216.        <property name="sid" value="1001"></property>
  217.        <property name="sname" value="张三"></property>
  218.        <property name="gender" value="男"></property>
  219. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  220.     <bean id="student" ></bean>
  221. </beans>goods1.setGname("国土2");<?xml version="1.0" encoding="UTF-8"?>
  222. <beans xmlns="http://www.springframework.org/schema/beans"
  223.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  224.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  225. <bean  scope="prototype">
  226.        <property name="sid" value="1001"></property>
  227.        <property name="sname" value="张三"></property>
  228.        <property name="gender" value="男"></property>
  229. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  230.     <bean id="student" ></bean>
  231. </beans><?xml version="1.0" encoding="UTF-8"?>
  232. <beans xmlns="http://www.springframework.org/schema/beans"
  233.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  234.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  235. <bean  scope="prototype">
  236.        <property name="sid" value="1001"></property>
  237.        <property name="sname" value="张三"></property>
  238.        <property name="gender" value="男"></property>
  239. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  240.     <bean id="student" ></bean>
  241. </beans>goods1.setGcount(100);<?xml version="1.0" encoding="UTF-8"?>
  242. <beans xmlns="http://www.springframework.org/schema/beans"
  243.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  244.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  245. <bean  scope="prototype">
  246.        <property name="sid" value="1001"></property>
  247.        <property name="sname" value="张三"></property>
  248.        <property name="gender" value="男"></property>
  249. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  250.     <bean id="student" ></bean>
  251. </beans><?xml version="1.0" encoding="UTF-8"?>
  252. <beans xmlns="http://www.springframework.org/schema/beans"
  253.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  254.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  255. <bean  scope="prototype">
  256.        <property name="sid" value="1001"></property>
  257.        <property name="sname" value="张三"></property>
  258.        <property name="gender" value="男"></property>
  259. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  260.     <bean id="student" ></bean>
  261. </beans>goods1.setGprice(5.6);<?xml version="1.0" encoding="UTF-8"?>
  262. <beans xmlns="http://www.springframework.org/schema/beans"
  263.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  264.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  265. <bean  scope="prototype">
  266.        <property name="sid" value="1001"></property>
  267.        <property name="sname" value="张三"></property>
  268.        <property name="gender" value="男"></property>
  269. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  270.     <bean id="student" ></bean>
  271. </beans><?xml version="1.0" encoding="UTF-8"?>
  272. <beans xmlns="http://www.springframework.org/schema/beans"
  273.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  274.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  275. <bean  scope="prototype">
  276.        <property name="sid" value="1001"></property>
  277.        <property name="sname" value="张三"></property>
  278.        <property name="gender" value="男"></property>
  279. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  280.     <bean id="student" ></bean>
  281. </beans>goods1.setCreateTime(new Date());<?xml version="1.0" encoding="UTF-8"?>
  282. <beans xmlns="http://www.springframework.org/schema/beans"
  283.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  284.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  285. <bean  scope="prototype">
  286.        <property name="sid" value="1001"></property>
  287.        <property name="sname" value="张三"></property>
  288.        <property name="gender" value="男"></property>
  289. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  290.     <bean id="student" ></bean>
  291. </beans><?xml version="1.0" encoding="UTF-8"?>
  292. <beans xmlns="http://www.springframework.org/schema/beans"
  293.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  294.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  295. <bean  scope="prototype">
  296.        <property name="sid" value="1001"></property>
  297.        <property name="sname" value="张三"></property>
  298.        <property name="gender" value="男"></property>
  299. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  300.     <bean id="student" ></bean>
  301. </beans>goods1.setTid(1);<?xml version="1.0" encoding="UTF-8"?>
  302. <beans xmlns="http://www.springframework.org/schema/beans"
  303.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  304.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  305. <bean  scope="prototype">
  306.        <property name="sid" value="1001"></property>
  307.        <property name="sname" value="张三"></property>
  308.        <property name="gender" value="男"></property>
  309. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  310.     <bean id="student" ></bean>
  311. </beans><?xml version="1.0" encoding="UTF-8"?>
  312. <beans xmlns="http://www.springframework.org/schema/beans"
  313.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  314.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  315. <bean  scope="prototype">
  316.        <property name="sid" value="1001"></property>
  317.        <property name="sname" value="张三"></property>
  318.        <property name="gender" value="男"></property>
  319. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  320.     <bean id="student" ></bean>
  321. </beans>int i1 =  goodsMapper.insert(goods1);<?xml version="1.0" encoding="UTF-8"?>
  322. <beans xmlns="http://www.springframework.org/schema/beans"
  323.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  324.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  325. <bean  scope="prototype">
  326.        <property name="sid" value="1001"></property>
  327.        <property name="sname" value="张三"></property>
  328.        <property name="gender" value="男"></property>
  329. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  330.     <bean id="student" ></bean>
  331. </beans><?xml version="1.0" encoding="UTF-8"?>
  332. <beans xmlns="http://www.springframework.org/schema/beans"
  333.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  334.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  335. <bean  scope="prototype">
  336.        <property name="sid" value="1001"></property>
  337.        <property name="sname" value="张三"></property>
  338.        <property name="gender" value="男"></property>
  339. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  340.     <bean id="student" ></bean>
  341. </beans>System.out.println(i1); }
复制代码
2)基于注解实现事务
  1. spring-dao.xml<?xml version="1.0" encoding="UTF-8"?>
  2. <beans xmlns="http://www.springframework.org/schema/beans"
  3.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  4.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  5. <bean  scope="prototype">
  6.        <property name="sid" value="1001"></property>
  7.        <property name="sname" value="张三"></property>
  8.        <property name="gender" value="男"></property>
  9. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  10.     <bean id="student" ></bean>
  11. </beans><?xml version="1.0" encoding="UTF-8"?>
  12. <beans xmlns="http://www.springframework.org/schema/beans"
  13.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  14.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  15. <bean  scope="prototype">
  16.        <property name="sid" value="1001"></property>
  17.        <property name="sname" value="张三"></property>
  18.        <property name="gender" value="男"></property>
  19. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  20.     <bean id="student" ></bean>
  21. </beans><?xml version="1.0" encoding="UTF-8"?>
  22. <beans xmlns="http://www.springframework.org/schema/beans"
  23.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  24.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  25. <bean  scope="prototype">
  26.        <property name="sid" value="1001"></property>
  27.        <property name="sname" value="张三"></property>
  28.        <property name="gender" value="男"></property>
  29. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  30.     <bean id="student" ></bean>
  31. </beans><?xml version="1.0" encoding="UTF-8"?>
  32. <beans xmlns="http://www.springframework.org/schema/beans"
  33.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  34.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  35. <bean  scope="prototype">
  36.        <property name="sid" value="1001"></property>
  37.        <property name="sname" value="张三"></property>
  38.        <property name="gender" value="男"></property>
  39. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  40.     <bean id="student" ></bean>
  41. </beans><?xml version="1.0" encoding="UTF-8"?>
  42. <beans xmlns="http://www.springframework.org/schema/beans"
  43.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  44.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  45. <bean  scope="prototype">
  46.        <property name="sid" value="1001"></property>
  47.        <property name="sname" value="张三"></property>
  48.        <property name="gender" value="男"></property>
  49. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  50.     <bean id="student" ></bean>
  51. </beans><?xml version="1.0" encoding="UTF-8"?>
  52. <beans xmlns="http://www.springframework.org/schema/beans"
  53.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  54.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  55. <bean  scope="prototype">
  56.        <property name="sid" value="1001"></property>
  57.        <property name="sname" value="张三"></property>
  58.        <property name="gender" value="男"></property>
  59. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  60.     <bean id="student" ></bean>
  61. </beans><?xml version="1.0" encoding="UTF-8"?>
  62. <beans xmlns="http://www.springframework.org/schema/beans"
  63.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  64.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  65. <bean  scope="prototype">
  66.        <property name="sid" value="1001"></property>
  67.        <property name="sname" value="张三"></property>
  68.        <property name="gender" value="男"></property>
  69. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  70.     <bean id="student" ></bean>
  71. </beans>          <?xml version="1.0" encoding="UTF-8"?>
  72. <beans xmlns="http://www.springframework.org/schema/beans"
  73.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  74.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  75. <bean  scope="prototype">
  76.        <property name="sid" value="1001"></property>
  77.        <property name="sname" value="张三"></property>
  78.        <property name="gender" value="男"></property>
  79. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  80.     <bean id="student" ></bean>
  81. </beans><?xml version="1.0" encoding="UTF-8"?>
  82. <beans xmlns="http://www.springframework.org/schema/beans"
  83.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  84.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  85. <bean  scope="prototype">
  86.        <property name="sid" value="1001"></property>
  87.        <property name="sname" value="张三"></property>
  88.        <property name="gender" value="男"></property>
  89. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  90.     <bean id="student" ></bean>
  91. </beans><?xml version="1.0" encoding="UTF-8"?>
  92. <beans xmlns="http://www.springframework.org/schema/beans"
  93.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  94.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  95. <bean  scope="prototype">
  96.        <property name="sid" value="1001"></property>
  97.        <property name="sname" value="张三"></property>
  98.        <property name="gender" value="男"></property>
  99. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  100.     <bean id="student" ></bean>
  101. </beans>
复制代码
  1. GoodsService.java@Transactional(propagation = Propagation.REQUIRED,isolation = Isolation.SERIALIZABLE)public void insert(){<?xml version="1.0" encoding="UTF-8"?>
  2. <beans xmlns="http://www.springframework.org/schema/beans"
  3.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  4.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  5. <bean  scope="prototype">
  6.        <property name="sid" value="1001"></property>
  7.        <property name="sname" value="张三"></property>
  8.        <property name="gender" value="男"></property>
  9. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  10.     <bean id="student" ></bean>
  11. </beans>Goods goods = new Goods();<?xml version="1.0" encoding="UTF-8"?>
  12. <beans xmlns="http://www.springframework.org/schema/beans"
  13.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  14.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  15. <bean  scope="prototype">
  16.        <property name="sid" value="1001"></property>
  17.        <property name="sname" value="张三"></property>
  18.        <property name="gender" value="男"></property>
  19. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  20.     <bean id="student" ></bean>
  21. </beans>goods.setGname("国土1");<?xml version="1.0" encoding="UTF-8"?>
  22. <beans xmlns="http://www.springframework.org/schema/beans"
  23.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  24.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  25. <bean  scope="prototype">
  26.        <property name="sid" value="1001"></property>
  27.        <property name="sname" value="张三"></property>
  28.        <property name="gender" value="男"></property>
  29. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  30.     <bean id="student" ></bean>
  31. </beans>goods.setGcount(100);<?xml version="1.0" encoding="UTF-8"?>
  32. <beans xmlns="http://www.springframework.org/schema/beans"
  33.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  34.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  35. <bean  scope="prototype">
  36.        <property name="sid" value="1001"></property>
  37.        <property name="sname" value="张三"></property>
  38.        <property name="gender" value="男"></property>
  39. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  40.     <bean id="student" ></bean>
  41. </beans>goods.setGprice(5.6);<?xml version="1.0" encoding="UTF-8"?>
  42. <beans xmlns="http://www.springframework.org/schema/beans"
  43.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  44.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  45. <bean  scope="prototype">
  46.        <property name="sid" value="1001"></property>
  47.        <property name="sname" value="张三"></property>
  48.        <property name="gender" value="男"></property>
  49. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  50.     <bean id="student" ></bean>
  51. </beans>goods.setCreateTime(new Date());<?xml version="1.0" encoding="UTF-8"?>
  52. <beans xmlns="http://www.springframework.org/schema/beans"
  53.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  54.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  55. <bean  scope="prototype">
  56.        <property name="sid" value="1001"></property>
  57.        <property name="sname" value="张三"></property>
  58.        <property name="gender" value="男"></property>
  59. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  60.     <bean id="student" ></bean>
  61. </beans>goods.setTid(1);<?xml version="1.0" encoding="UTF-8"?>
  62. <beans xmlns="http://www.springframework.org/schema/beans"
  63.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  64.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  65. <bean  scope="prototype">
  66.        <property name="sid" value="1001"></property>
  67.        <property name="sname" value="张三"></property>
  68.        <property name="gender" value="男"></property>
  69. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  70.     <bean id="student" ></bean>
  71. </beans>int i =  goodsMapper.insert(goods);<?xml version="1.0" encoding="UTF-8"?>
  72. <beans xmlns="http://www.springframework.org/schema/beans"
  73.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  74.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  75. <bean  scope="prototype">
  76.        <property name="sid" value="1001"></property>
  77.        <property name="sname" value="张三"></property>
  78.        <property name="gender" value="男"></property>
  79. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  80.     <bean id="student" ></bean>
  81. </beans>int a = 10/0;<?xml version="1.0" encoding="UTF-8"?>
  82. <beans xmlns="http://www.springframework.org/schema/beans"
  83.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  84.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  85. <bean  scope="prototype">
  86.        <property name="sid" value="1001"></property>
  87.        <property name="sname" value="张三"></property>
  88.        <property name="gender" value="男"></property>
  89. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  90.     <bean id="student" ></bean>
  91. </beans>Goods goods1 = new Goods();<?xml version="1.0" encoding="UTF-8"?>
  92. <beans xmlns="http://www.springframework.org/schema/beans"
  93.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  94.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  95. <bean  scope="prototype">
  96.        <property name="sid" value="1001"></property>
  97.        <property name="sname" value="张三"></property>
  98.        <property name="gender" value="男"></property>
  99. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  100.     <bean id="student" ></bean>
  101. </beans>goods1.setGname("国土2");<?xml version="1.0" encoding="UTF-8"?>
  102. <beans xmlns="http://www.springframework.org/schema/beans"
  103.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  104.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  105. <bean  scope="prototype">
  106.        <property name="sid" value="1001"></property>
  107.        <property name="sname" value="张三"></property>
  108.        <property name="gender" value="男"></property>
  109. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  110.     <bean id="student" ></bean>
  111. </beans>goods1.setGcount(100);<?xml version="1.0" encoding="UTF-8"?>
  112. <beans xmlns="http://www.springframework.org/schema/beans"
  113.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  114.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  115. <bean  scope="prototype">
  116.        <property name="sid" value="1001"></property>
  117.        <property name="sname" value="张三"></property>
  118.        <property name="gender" value="男"></property>
  119. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  120.     <bean id="student" ></bean>
  121. </beans>goods1.setGprice(5.6);<?xml version="1.0" encoding="UTF-8"?>
  122. <beans xmlns="http://www.springframework.org/schema/beans"
  123.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  124.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  125. <bean  scope="prototype">
  126.        <property name="sid" value="1001"></property>
  127.        <property name="sname" value="张三"></property>
  128.        <property name="gender" value="男"></property>
  129. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  130.     <bean id="student" ></bean>
  131. </beans>goods1.setCreateTime(new Date());<?xml version="1.0" encoding="UTF-8"?>
  132. <beans xmlns="http://www.springframework.org/schema/beans"
  133.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  134.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  135. <bean  scope="prototype">
  136.        <property name="sid" value="1001"></property>
  137.        <property name="sname" value="张三"></property>
  138.        <property name="gender" value="男"></property>
  139. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  140.     <bean id="student" ></bean>
  141. </beans>goods1.setTid(1);<?xml version="1.0" encoding="UTF-8"?>
  142. <beans xmlns="http://www.springframework.org/schema/beans"
  143.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  144.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  145. <bean  scope="prototype">
  146.        <property name="sid" value="1001"></property>
  147.        <property name="sname" value="张三"></property>
  148.        <property name="gender" value="男"></property>
  149. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  150.     <bean id="student" ></bean>
  151. </beans>int i1 =  goodsMapper.insert(goods1);<?xml version="1.0" encoding="UTF-8"?>
  152. <beans xmlns="http://www.springframework.org/schema/beans"
  153.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  154.        xsi:schemaLocation="http://www.springframework.org/schema/beans
  155. <bean  scope="prototype">
  156.        <property name="sid" value="1001"></property>
  157.        <property name="sname" value="张三"></property>
  158.        <property name="gender" value="男"></property>
  159. </bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">
  160.     <bean id="student" ></bean>
  161. </beans>System.out.println(i1);}
复制代码
3)事务的传播机制

​<bean ></bean>       
<bean  id="myLogger"></bean>


<aop:aspectj-autoproxy></aop:aspectj-autoproxy>        Propagation:
1.REQUIRED
如果当前没有事务,就创建一个新事务,如果当前存在事务,就加入该事务,该设置是最常用的默认设置。

调用methdoA,如果methodB发生异常,触发事务回滚,也会methodA中的也会回滚
2.SUPPORTS
支持当前事务,如果当前存在事务,就加入该事务,如果当前不存在事务,就以非事务执行。
  1. 如果调用methodA,再调用methodB,MehtodB会加入到MethodA的开启的当前事务中。  如果直接调用methodB,当前没有事务,就以非事务执行。  
复制代码
3.MNDATORY
支持当前事务,如果当前存在事务,就加入该事务,如果当前不存在事务,就抛出异常。
  1. 如果调用methodA,再调用methodB,MehtodB会加入到MethodA的开启的当前事务中。  如果直接调用methodB,当前没有事务,就会抛出异常。  
复制代码
4.REQUIRES_NEW
创建新事务,无论当前存不存在事务,都创建新事务。
  1. 调用methodA,会先开启事务1,执行A的something pre的代码。再调用methodB,methdoB会开启一个事务2,再执行自身的代码。最后在执行methodA的something post。如果method发生异常回滚,只是methodB中的代码回滚,不影响methodA中的代码。如果methodA发生异常回滚,只回滚methodA中的代码,不影响methodB中的代码。  
复制代码
5.NOT_SUPPORTED
以非事务方式执行操作,如果当前存在事务,就把当前事务挂起。

调用methodA,再调用methodB,methodA开启的事务会被挂起,即在methodB中不齐作用,相称于没有事务,methodB内部抛出异常不会回滚。methodA内的代码发生异常会回滚。  直接调用methodB,不会开启事务。
6.NEVER
以非事务方式执行操作,如果当前存在事务,则抛出异常。


7.NESTED
如果当前存在事务,则在嵌套事务内执行。如果当前没有事务,则按REQUIRED属性执行。

调用methodA,开启一个事务,执行something pre的代码,设置回滚点savepoint,再调用methodB的代码,如果methodB里抛出异常,此时回滚到之前的saveponint。再然后执行methodA里的something post的代码,末了提交大概回滚事务。  嵌套事务,外层的事务如果回滚,会导致内层的事务也回滚;但是内层的事务如果回滚,仅仅是回滚自己的代码,不影响外层的事务的代码。
4)事务的隔离级别

​        1) 读未提交(脏读)  (不加任何锁)
​<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
<bean  scope="prototype">
       <property name="sid" value="1001"></property>
       <property name="sname" value="张三"></property>
       <property name="gender" value="男"></property>
</bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">

    <bean id="student" ></bean>

</beans>          当一个事务开启后, 修改了数据, 但是未提交事务之前,  另外一个事务来读取数据,  可以读到未提交的数据;
​<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
<bean  scope="prototype">
       <property name="sid" value="1001"></property>
       <property name="sname" value="张三"></property>
       <property name="gender" value="男"></property>
</bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">

    <bean id="student" ></bean>

</beans>由于读的数据是未提交的, 那么万一事务回滚, 数据就读到的是错的;  会产生脏数据;
​        2)读提交(不可重复读)  (写锁(部门行))
​<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
<bean  scope="prototype">
       <property name="sid" value="1001"></property>
       <property name="sname" value="张三"></property>
       <property name="gender" value="男"></property>
</bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">

    <bean id="student" ></bean>

</beans><?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
<bean  scope="prototype">
       <property name="sid" value="1001"></property>
       <property name="sname" value="张三"></property>
       <property name="gender" value="男"></property>
</bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">

    <bean id="student" ></bean>

</beans>  如果是一个读事务(线程),则允许其他事务读写,如果是写事务将会禁止其他事务访问该行数据,该隔离级别避免了脏读,但是可能出现不可重复读。事务A事先读取了数据,事务B紧接着更新了数据,并提交了事务,而事务A再次读取该数据时,数据已经发生了改变
​        3)可重复读(读写锁(部门行))
​<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
<bean  scope="prototype">
       <property name="sid" value="1001"></property>
       <property name="sname" value="张三"></property>
       <property name="gender" value="男"></property>
</bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">

    <bean id="student" ></bean>

</beans><?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
<bean  scope="prototype">
       <property name="sid" value="1001"></property>
       <property name="sname" value="张三"></property>
       <property name="gender" value="男"></property>
</bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">

    <bean id="student" ></bean>

</beans>  可重复读取是指在一个事务内,多次读同一个数据,在这个事务还没竣事时,其他事务不能访问该数据(包括了读写),这样就可以在同一个事务内两次读到的数据是一样的,因此称为是可重复读隔离级别;
​<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
<bean  scope="prototype">
       <property name="sid" value="1001"></property>
       <property name="sname" value="张三"></property>
       <property name="gender" value="男"></property>
</bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">

    <bean id="student" ></bean>

</beans><?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
<bean  scope="prototype">
       <property name="sid" value="1001"></property>
       <property name="sname" value="张三"></property>
       <property name="gender" value="男"></property>
</bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">

    <bean id="student" ></bean>

</beans>  读取数据的事务将会禁止写事务,写事务则禁止任何其他事务(包括了读写),这样避免了不可重复读和脏读,但是偶然可能会出现幻读。
​        4)串行话(读写锁(表))
这是最高的隔离级别,它通过欺压事务排序,使之不可能相互辩论,从而解决幻读问题。简言之,它是在每个读的数据行上加上锁。在这个级别,可能导致大量的超时征象和锁竞争;
事务隔离级别脏读不可重复读幻读读未提交<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
<bean  scope="prototype">
       <property name="sid" value="1001"></property>
       <property name="sname" value="张三"></property>
       <property name="gender" value="男"></property>
</bean>      http://www.springframework.org/schema/beans/spring-beans.xsd">

    <bean id="student" ></bean>

</beans> (read-uncommitted)是是是读提交(read-committed)否是是可重复读(repeatable-read)否否是串行化(serializable)否否否5  其余常用注解


  • @Component:将类标记为Spring管理的Bean。@Service、@Repository和@Controller都是特定范例的@Component注解,分别表现服务层、数据访问层和控制层组件。
  • @Autowired:用于自动装配Bean之间的依赖关系。可以用于构造函数、setter方法或字段上。从Spring 4.3开始,如果只有一个构造函数,可以省略@Autowired。
  • @Qualifier:当有多个相同范例的Bean时,使用@Qualifier指定特定的Bean进行注入。通常与@Autowired一起使用。
  • @Value:用于向Bean的属性注入基本范例或String范例的值,支持SpEL表达式。
  • @Scope:定义Bean的作用域,如singleton(默认)、prototype、request、session和global session。
  • @PostConstruct:标记一个方法作为初始化方法,该方法会在Bean实例化并设置完所有属性后调用。
  • @PreDestroy:标记一个方法作为销毁方法,在容器关闭前调用。
  • @Configuration:将类标记为Spring Java配置类,用于定义和注册Bean。
  • @Bean:用于@Configuration类中的方法上,声明一个Bean。方法返回的对象将由Spring容器管理。
  • @ComponentScan:用于Java配置类上,声明启用组件扫描。可以指定扫描的基础包和过滤条件。

免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

x
回复

使用道具 举报

0 个回复

正序浏览

快速回复

您需要登录后才可以回帖 登录 or 立即注册

本版积分规则

东湖之滨

金牌会员
这个人很懒什么都没写!
快速回复 返回顶部 返回列表