<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ??一站式輕松地調用各大LLM模型接口,支持GPT4、智譜、豆包、星火、月之暗面及文生圖、文生視頻 廣告
                正如上一節[1.4.1依賴注入](1.4.1依賴注入.md)提到的,你可以通過`<property/>`和`<constructor-arg/>`元素注入成員屬性和構造參數或者直接使用簡單值完成依賴的配置。 [1.4.1.依賴注入](1.4.1.依賴注入.md) ### **簡單值(基本類型、字符串等等)** `<property/>`元素的`value`屬性可以為成員屬性或者構造參數指定一個可讀性高的字符串值,并且Spring的類型轉換服務([3.5.4.ConversionService API](3.5.4.ConversionServiceAPI.md))可以將String類型的數據轉換為屬性或者參數實際需要的類型。 ~~~ <bean id="myDataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"> <!-- 通過調用 setDriverClassName(String) 來設置屬性 --> <property name="driverClassName" value="com.mysql.jdbc.Driver"/> <property name="url" value="jdbc:mysql://localhost:3306/mydb"/> <property name="username" value="root"/> <property name="password" value="masterkaoli"/> </bean> ~~~ 下面的樣例使用了`p-namespace`來簡化XML配置。 ~~~ <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd"> <bean id="myDataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close" p:driverClassName="com.mysql.jdbc.Driver" p:url="jdbc:mysql://localhost:3306/mydb" p:username="root" p:password="masterkaoli"/> </beans> ~~~ 上面的例子顯得更加簡潔,但是單詞拼寫錯誤在運行時才發現而不是編寫代碼時,除非使用[IntelliJ IDEA](http://www.jetbrains.com/idea/) 或者[Spring Tool Suite](https://spring.io/tools/sts) (STS)等支持屬性自動完成的IDE,并且使用這樣的IDE是一種很棒的體驗。 你也可以像這樣配置`java.util.Properties`實例: ~~~ <bean id="mappings" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> <property name="properties"> <value> jdbc.driver.className=com.mysql.jdbc.Driver jdbc.url=jdbc:mysql://localhost:3306/mydb </value> </property> </bean> ~~~ Spring容器通過`PropertyEditor`將`<value/>`元素內的文本轉換為`java.util.Properties`實例。這種方式簡單快捷,所以Spring團隊更喜歡`<value/>`元素而不是`value`屬性。 ##### `<idref/>`元素 此元素是一種通過其他Bean的id值來引用Bean的方式,可以使用在`<constructor-arg/>`或者`<property/>`元素中,并且擁有錯誤校驗的功能。 ~~~ <bean id="theTargetBean" class="..."/> <bean id="theClientBean" class="..."> <property name="targetName"> <idref bean="theTargetBean"/> </property> </bean> ~~~ 上面的配置與下面的配置完全等價(運行時): ~~~ <bean id="theTargetBean" class="..." /> <bean id="client" class="..."> <property name="targetName" value="theTargetBean"/> </bean> ~~~ 第一種形式的配置要優于第二種,因為`<idref/>`元素使得容器會在部署時就驗證引用的Bean是否真實存在。在第二例子中,`targetName`的值不會被驗證,拼寫錯誤只能在`client` Bean被實例化時才出現(很有可能出現嚴重錯誤)。如果`client` Bean是原型模式的,拼寫錯誤和異常結果可能會在容器發布很久之后才被發現。
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看