Spring实战——获取方法返回值

小咪咪 2021-07-25 00:32 596阅读 0赞

一 配置文件

  1. <?xml version="1.0" encoding="GBK"?>
  2. <beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  3. xmlns="http://www.springframework.org/schema/beans"
  4. xmlns:util="http://www.springframework.org/schema/util"
  5. xsi:schemaLocation="http://www.springframework.org/schema/beans
  6. http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
  7. http://www.springframework.org/schema/util
  8. http://www.springframework.org/schema/util/spring-util-4.0.xsd">
  9. <!-- 下面配置相当于如下Java代码:
  10. JFrame win = new JFrame("我的窗口");
  11. win.setVisible(true); -->
  12. <bean id="win" class="javax.swing.JFrame">
  13. <constructor-arg value="我的窗口" type="java.lang.String"/>
  14. <property name="visible" value="true"/>
  15. </bean>
  16. <!-- 下面配置相当于如下Java代码:
  17. JTextArea jta = JTextArea(7, 40); -->
  18. <bean id="jta" class="javax.swing.JTextArea">
  19. <constructor-arg value="7" type="int"/>
  20. <constructor-arg value="40" type="int"/>
  21. </bean>
  22. <!-- 使用MethodInvokingFactoryBean驱动Spring调用普通方法
  23. 下面配置相当于如下Java代码:
  24. win.add(new JScrollPane(jta)); -->
  25. <bean class=
  26. "org.springframework.beans.factory.config.MethodInvokingFactoryBean">
  27. <property name="targetObject" ref="win"/>
  28. <property name="targetMethod" value="add"/>
  29. <property name="arguments">
  30. <list>
  31. <bean class="javax.swing.JScrollPane">
  32. <constructor-arg ref="jta"/>
  33. </bean>
  34. </list>
  35. </property>
  36. </bean>
  37. <!-- 下面配置相当于如下Java代码:
  38. JPanel jp = new JPanel(); -->
  39. <bean id="jp" class="javax.swing.JPanel"/>
  40. <!-- 使用MethodInvokingFactoryBean驱动Spring调用普通方法
  41. 下面配置相当于如下Java代码:
  42. win.add(jp , BorderLayout.SOUTH); -->
  43. <bean class=
  44. "org.springframework.beans.factory.config.MethodInvokingFactoryBean">
  45. <property name="targetObject" ref="win"/>
  46. <property name="targetMethod" value="add"/>
  47. <property name="arguments">
  48. <list>
  49. <ref bean="jp"/>
  50. <util:constant static-field="java.awt.BorderLayout.SOUTH"/>
  51. </list>
  52. </property>
  53. </bean>
  54. <!-- 下面配置相当于如下Java代码:
  55. JButton jb1 = new JButton("确定"); -->
  56. <bean id="jb1" class="javax.swing.JButton">
  57. <constructor-arg value="确定" type="java.lang.String"/>
  58. </bean>
  59. <!-- 使用MethodInvokingFactoryBean驱动Spring调用普通方法
  60. 下面配置相当于如下Java代码:
  61. jp.add(jb1); -->
  62. <bean class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
  63. <property name="targetObject" ref="jp"/>
  64. <property name="targetMethod" value="add"/>
  65. <property name="arguments">
  66. <list>
  67. <ref bean="jb1"/>
  68. </list>
  69. </property>
  70. </bean>
  71. <!-- 下面配置相当于如下Java代码:
  72. JButton jb2 = new JButton("取消"); -->
  73. <bean id="jb2" class="javax.swing.JButton">
  74. <constructor-arg value="取消" type="java.lang.String"/>
  75. </bean>
  76. <!-- 使用MethodInvokingFactoryBean驱动Spring调用普通方法
  77. 下面配置相当于如下Java代码:
  78. jp.add(jb2); -->
  79. <bean class=
  80. "org.springframework.beans.factory.config.MethodInvokingFactoryBean">
  81. <property name="targetObject" ref="jp"/>
  82. <property name="targetMethod" value="add"/>
  83. <property name="arguments">
  84. <list>
  85. <ref bean="jb2"/>
  86. </list>
  87. </property>
  88. </bean>
  89. <!-- 使用MethodInvokingFactoryBean驱动Spring调用普通方法
  90. 下面配置相当于如下Java代码:
  91. win.pack(); -->
  92. <bean class=
  93. "org.springframework.beans.factory.config.MethodInvokingFactoryBean">
  94. <property name="targetObject" ref="win"/>
  95. <property name="targetMethod" value="pack"/>
  96. </bean>
  97. </beans>

二 测试类

  1. package lee;
  2. import org.springframework.context.*;
  3. import org.springframework.context.support.*;
  4. import org.crazyit.app.service.*;
  5. public class SpringTest
  6. {
  7. public static void main(String[] args)
  8. {
  9. ApplicationContext ctx =
  10. new ClassPathXmlApplicationContext("beans.xml");
  11. }
  12. }

三 测试结果

20190922105615752.png

发表评论

表情:
评论列表 (有 0 条评论,596人围观)

还没有评论,来说两句吧...

相关阅读

    相关 postman获取返回

    在实现接口自动测试的时候,会经常遇到接口参数依赖的问题,例如调取登录接口的时候,需要先获取登录的key值,而每次请求返回的key值又是不一样的,那么这种情况下,要实现接口的自