<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>

                合規國際互聯網加速 OSASE為企業客戶提供高速穩定SD-WAN國際加速解決方案。 廣告
                # 24.外化配置 ### 24.外部化配置 Spring Boot允許將配置外部化(externalize),這樣你就能夠在不同的環境下使用相同的代碼。你可以使用properties文件,YAML文件,環境變量和命令行參數來外部化配置。使用@Value注解,可以直接將屬性值注入到beans中,然后通過Spring的`Environment`抽象或通過`@ConfigurationProperties`[綁定到結構化對象](http://docs.spring.io/spring-boot/docs/1.4.1.RELEASE/reference/htmlsingle/#boot-features-external-config-typesafe-configuration-properties)來訪問。 Spring Boot設計了一個非常特別的`PropertySource`順序,以允許對屬性值進行合理的覆蓋,屬性會以如下的順序進行設值: 1. home目錄下的[devtools全局設置屬性](http://docs.spring.io/spring-boot/docs/1.4.1.RELEASE/reference/htmlsingle/#using-boot-devtools-globalsettings)(`~/.spring-boot-devtools.properties`,如果devtools激活)。 2. 測試用例上的[@TestPropertySource](http://docs.spring.io/spring/docs/4.3.3.RELEASE/javadoc-api/org/springframework/test/context/TestPropertySource.html)注解。 3. 測試用例上的[@SpringBootTest#properties](http://docs.spring.io/spring-boot/docs/1.4.1.RELEASE/api/spring-boot-test/src/main/java/org/springframework/boot/test/context/SpringBootTest.html)注解。 4. 命令行參數 5. 來自`SPRING_APPLICATION_JSON`的屬性(環境變量或系統屬性中內嵌的內聯JSON)。 6. `ServletConfig`初始化參數。 7. `ServletContext`初始化參數。 8. 來自于`java:comp/env`的JNDI屬性。 9. Java系統屬性(System.getProperties())。 10. 操作系統環境變量。 11. RandomValuePropertySource,只包含`random.*`中的屬性。 12. 沒有打進jar包的[Profile-specific應用屬性](http://docs.spring.io/spring-boot/docs/1.4.1.RELEASE/reference/htmlsingle/#boot-features-external-config-profile-specific-properties)(`application-{profile}.properties`和YAML變量)。 13. 打進jar包中的[Profile-specific應用屬性](http://docs.spring.io/spring-boot/docs/1.4.1.RELEASE/reference/htmlsingle/#boot-features-external-config-profile-specific-properties)(`application-{profile}.properties`和YAML變量)。 14. 沒有打進jar包的應用配置(`application.properties`和YAML變量)。 15. 打進jar包中的應用配置(`application.properties`和YAML變量)。 16. `@Configuration`類上的[`@PropertySource`注解](http://docs.spring.io/spring/docs/4.3.3.RELEASE/javadoc-api/org/springframework/context/annotation/PropertySource.html)。 17. 默認屬性(使用`SpringApplication.setDefaultProperties`指定)。 下面是具體的示例,假設你開發一個使用name屬性的`@Component`: ``` import org.springframework.stereotype.* import org.springframework.beans.factory.annotation.* @Component public class MyBean { @Value("${name}") private String name; // ... } ``` 你可以將一個`application.properties`放到應用的classpath下,為`name`提供一個合適的默認屬性值。當在新的環境中運行時,可以在jar包外提供一個`application.properties`覆蓋`name`屬性。對于一次性的測試,你可以使用特定的命令行開關啟動應用(比如,`java -jar app.jar --name="Spring"`)。 **注**`SPRING_APPLICATION_JSON`屬性可以通過命令行的環境變量設置,例如,在一個UNIX shell中可以這樣: ``` $ SPRING_APPLICATION_JSON='{"foo":{"bar":"spam"}}' java -jar myapp.jar ``` 本示例中,如果是Spring `Environment`,你可以以`foo.bar=spam`結尾;如果在一個系統變量中,可以提供作為`spring.application.json`的JSON字符串: ``` $ java -Dspring.application.json='{"foo":"bar"}' -jar myapp.jar ``` 或命令行參數: ``` $ java -jar myapp.jar --spring.application.json='{"foo":"bar"}' ``` 或作為一個JNDI變量`java:comp/env/spring.application.json`。
                  <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>

                              哎呀哎呀视频在线观看