spring中配置bean的init-method_@bean「建议收藏」

spring中配置bean的init-method_@bean「建议收藏」4级1001离散数学例如上面这个文件:配置了3个beanproperty的name属性值,在实体bean中必须有对应的set方法,否则报错,报错如下:Beanproperty'某某属性'is…

大家好,欢迎来到IT知识分享网。

<?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 http://www.springframework.org/schema/beans/spring-beans-3.2.xsd “>
  <bean id=“English_level” class=“com.myspring.second.EnglishLevel”>
      <!– set方法注入 –>
    <property name=“course”>
      <value>4级</value>
    </property>
  </bean>
  <bean id=“Math_level” class=“com.myspring.second.MathCourse”>
    <!– 构造函数注入 –>
    <constructor-arg><value>1001</value></constructor-arg>
    <constructor-arg><value>离散数学</value></constructor-arg>
  </bean>
  <bean id=“student” class=“com.myspring.second.Student”>
    <property name=“eng”>
      <ref bean=“English_level”/>
    </property>
    <property name=“mat”>
      <ref bean=“Math_level”/>
    </property>
  </bean>

</beans>


例如上面这个文件:

  • 配置了3个bean
  • property 的 name 属性值,在实体 bean 中必须有对应的 set 方法,否则报错 ,报错如下:

Bean property ‘某某属性‘ is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?


例如:
<bean id=“student” class=“com.myspring.second.Student”>
    <property name=eng>
      <ref bean=“English_level”/>
    </property>
    <property name=mat>
      <ref bean=“Math_level”/>
    </property>
  </bean>
对于这个bean,在 Student 类中必须存在:
setEng(String string){}
setMat(String string){}
这两个方法;
set 方法写法就不详解了,略~

渣渣就得在 bug中挣扎

来自为知笔记(Wiz)

免责声明:本站所有文章内容,图片,视频等均是来源于用户投稿和互联网及文摘转载整编而成,不代表本站观点,不承担相关法律责任。其著作权各归其原作者或其出版社所有。如发现本站有涉嫌抄袭侵权/违法违规的内容,侵犯到您的权益,请在线联系站长,一经查实,本站将立刻删除。 本文来自网络,若有侵权,请联系删除,如若转载,请注明出处:https://yundeesoft.com/29429.html

(0)
上一篇 2023-09-29 20:00
下一篇 2023-10-10 11:33

相关推荐

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注

关注微信