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

                ThinkChat2.0新版上線,更智能更精彩,支持會話、畫圖、視頻、閱讀、搜索等,送10W Token,即刻開啟你的AI之旅 廣告
                # SpringBoot 教程 > 原文: [https://howtodoinjava.com/spring-boot-tutorials/](https://howtodoinjava.com/spring-boot-tutorials/) **Spring Boot** 是一個 Spring 框架模塊,為 Spring 框架提供 RAD(**快速應用程序開發**)功能。 它高度依賴**入門模板**功能,該功能非常強大且可以完美運行。 ![Spring boot modules](https://img.kancloud.cn/96/3e/963e551b4e0db8295d5dfed54381013e_450x338.jpg) Spring boot 模塊 ## 1\. 什么是入門模板? Spring Boot 啟動器是模板,其中包含啟動特定功能所需的所有相關傳遞依賴項的**集合**。 例如,如果要創建 Spring WebMVC 應用程序,則在傳統設置中,您自己會包含所有必需的依賴項。 這就留下了**版本沖突**的機會,這最終會導致更多**運行時異常**。 使用 Spring boot,要創建 MVC 應用程序,只需導入`spring-boot-starter-web`依賴項。 `pom.xml` ```java <!-- Parent pom is mandatory to control versions of child dependencies --> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.1.6.RELEASE</version> <relativePath /> </parent> <!-- Spring web brings all required dependencies to build web application. --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> ``` 在`spring-boot-starter-web`依賴關系之上,內部導入所有給定的依賴關系并將其添加到您的項目中。 請注意,某些依賴關系是直接的,某些依賴關系進一步引用了其他入門模板,這些模板可過渡地下載更多的依賴關系。 另外,請注意**不需要將版本信息提供到子依賴項**中。 相對于父級啟動器的版本,已解決所有版本(在我們的示例中為`2.0.4.RELEASE`)。 `Dependencies brought in by webmvc starter template` ```java <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-json</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-tomcat</artifactId> </dependency> <dependency> <groupId>org.hibernate.validator</groupId> <artifactId>hibernate-validator</artifactId> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-web</artifactId> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-webmvc</artifactId> </dependency> </dependencies> ``` > 閱讀更多: [Spring Boot 入門模板列表](https://github.com/spring-projects/spring-boot/tree/master/spring-boot-project/spring-boot-starters/) ## 2\. Spring Boot 自動配置 通過`@EnableAutoConfiguration`注解啟用自動配置。 Spring Boot 自動配置掃描類路徑,在類路徑中找到庫,然后嘗試為它們猜測最佳配置,最后配置所有此類 bean。 自動配置會嘗試盡可能智能化,并且在您定義更多自己的配置時會自動退出。 > 自動配置始終在注冊用戶定義的 bean 之后應用。 Spring Boot 自動配置邏輯在`spring-boot-autoconfigure.jar`中實現。 Yoy 可以在此處驗證軟件包的[列表](https://docs.spring.io/spring-boot/docs/2.0.4.RELEASE/api/)。 ![Spring boot autoconfiguration packages](https://img.kancloud.cn/52/17/5217322d61db40d6617db343e7a314ba_978x523.jpg) Spring boot 自動配置包 例如,查看 Spring AOP 的自動配置。 它執行以下操作 1. **掃描類路徑**以查看是否存在`EnableAspectJAutoProxy`,`Aspect`,`Advice`和`AnnotatedElement`類。 2. 如果不存在類,則不會為 Spring AOP 進行自動配置。 3. 如果找到了類,則使用 Java config 注解`@EnableAspectJAutoProxy`配置 AOP。 4. 它檢查屬性`spring.aop`的值可以是`true`或`false`。 5. 基于屬性的值,設置`proxyTargetClass`屬性。 `AopAutoConfiguration.java` ```java @Configuration @ConditionalOnClass({ EnableAspectJAutoProxy.class, Aspect.class, Advice.class, AnnotatedElement.class }) @ConditionalOnProperty(prefix = "spring.aop", name = "auto", havingValue = "true", matchIfMissing = true) public class AopAutoConfiguration { @Configuration @EnableAspectJAutoProxy(proxyTargetClass = false) @ConditionalOnProperty(prefix = "spring.aop", name = "proxy-target-class", havingValue = "false", matchIfMissing = false) public static class JdkDynamicAutoProxyConfiguration { } @Configuration @EnableAspectJAutoProxy(proxyTargetClass = true) @ConditionalOnProperty(prefix = "spring.aop", name = "proxy-target-class", havingValue = "true", matchIfMissing = true) public static class CglibAutoProxyConfiguration { } } ``` ## 3\. 嵌入式服務器 SpringBoot 應用程序始終將 **tomcat** 作為**嵌入式服務器**依賴項。 這意味著您可以從命令提示符運行 Spring Boot 應用程序,而無需使用復雜的服務器基礎結構。 您可以根據需要排除 tomcat,并包括任何其他嵌入式服務器。 或者,您可以完全排除服務器環境。 全部基于配置。 例如,以下配置**排除了 tomcat** ,**包括了 Jetty**作為嵌入式服務器。 `pom.xml` ```java <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> <exclusions> <exclusion> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-tomcat</artifactId> </exclusion> </exclusions> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-jetty</artifactId> </dependency> ``` ## 4\. 運行應用程序 要**運行應用程序**,我們需要使用[`@SpringBootApplication`](https://howtodoinjava.com/spring-boot/springbootapplication-auto-configuration/)注解。 在幕后,它們相當于`@Configuration`,`@EnableAutoConfiguration`和`@ComponentScan`。 它可以掃描配置類,文件并將它們加載到 **spring 上下文**中。 在下面的示例中,執行從`main()`方法開始。 它開始加載所有配置文件,對其進行配置,然后根據`/resources`文件夾中`application.properties`文件中的[應用程序屬性](https://docs.spring.io/spring-boot/docs/current/reference/html/common-application-properties.html)運行應用程序。 `MyApplication.java` ```java @SpringBootApplication public class MyApplication { public static void main(String[] args) { SpringApplication.run(Application.class, args); } } ``` `application.properties` ```java ### Server port ######### server.port=8080 ### Context root ######## server.contextPath=/home ``` 要執行該應用程序,可以從 IDE 中運行**`main()`方法**,例如 **eclipse** ,或者可以構建 jar 文件并從命令提示符下執行。 `Console` ```java $ java -jar spring-boot-demo.jar ``` ## 5\. Spring Boot 的優點 * Spring Boot 幫助解決**依賴沖突**。 它標識所需的依賴項并為您導入它們。 * 對于所有依賴項,它都具有**兼容版本**的信息。 它最大程度地減少了運行時**類加載器**問題。 * 它的“預設默認配置”方法可幫助您配置幕后最重要的部分。 僅在需要時才覆蓋它們。 否則,一切都會完美地進行。 它有助于避免**樣板代碼**,注解和 XML 配置。 * 它提供了嵌入式 HTTP 服務器 Tomcat,因此您可以快速進行開發和測試。 * 它與 eclipse 和**智能想法**等 IDE 具有出色的集成。 ## 6\. Spring Boot 配置 1. [Spring Boot 注解](https://howtodoinjava.com/spring-boot2/spring-boot-annotations/) 2. [Spring Boot 登錄指南](https://howtodoinjava.com/spring-boot2/spring-boot-logging-configurations/) 3. [Spring Boot – Spring Boot 入門模板](https://howtodoinjava.com/spring/spring-boot2/spring-boot-starter-templates/) 4. [Spring Boot – 入門級父項依賴項](https://howtodoinjava.com/spring/spring-boot2/spring-boot-starter-parent-dependency/ ) 5. [Spring Boot – 獲取所有已加載的 bean](https://howtodoinjava.com/spring/spring-boot/get-loaded-beans-class-type-information/) 6. [Spring Boot – `@SpringBootApplication`和自動配置](https://howtodoinjava.com/spring/spring-boot2/springbootapplication-auto-configuration/) 7. [Spring Boot – 更改應用程序根目錄](https://howtodoinjava.com/spring/spring-boot/change-application-root-context-path/) 8. [Spring Boot – 配置 Jetty 服務器](https://howtodoinjava.com/spring/spring-boot/configure-jetty-server/) 9. [Spring Boot – Tomcat 默認端口](https://howtodoinjava.com/spring/spring-boot/change-tomcat-server-default-port-8080/) 10. [Spring Boot – WAR 打包示例](https://howtodoinjava.com/spring/spring-boot2/war-packaging-example/) 11. [Spring Boot – 日志和 yml 配置](https://howtodoinjava.com/spring/spring-boot/configure-logging-application-yml/) 12. [Spring Boot – 日志和屬性配置](https://howtodoinjava.com/spring/spring-boot/logging-application-properties/) 13. [Spring Boot – SSL(https)](https://howtodoinjava.com/spring/spring-boot/spring-boot-ssl-https-example/) 14. [Spring Boot – `CommandLineRunner`](https://howtodoinjava.com/spring/spring-boot/command-line-runner-interface-example/) 15. [Spring Boot – 開發人員工具模塊教程](https://howtodoinjava.com/spring/spring-boot2/developer-tools-module-tutorial/) 16. [Spring Boot – 在`@Bean`和`@Compoment`中注入應用程序參數](https://howtodoinjava.com/spring-boot2/application-arguments/) 17. [Spring Boot 嵌入式服務器日志](https://howtodoinjava.com/spring-boot2/embedded-server-logging-config/) 18. [Spring Boot 嵌入式 tomcat 配置](https://howtodoinjava.com/spring-boot2/embedded-tomcat-configuration/) ## 7\. 開發 REST API 和 SOAP Web 服務 1. [Spring Boot – REST API](https://howtodoinjava.com/spring/spring-boot/spring-boot-tutorial-with-hello-world-example/) 2. [Spring Boot – Jersey](https://howtodoinjava.com/spring/spring-boot/spring-boot-jersey-example/) 3. [Spring Boot – Spring HATEOAS 示例](https://howtodoinjava.com/spring/spring-boot2/rest-with-spring-hateoas-example/) 4. [Spring Boot – 請求驗證 REST API](https://howtodoinjava.com/spring/spring-boot2/spring-rest-request-validation/) 5. [Spring Boot – 基于角色的安全性](https://howtodoinjava.com/spring/spring-boot/role-based-security-jaxrs-annotations/) 6. [Spring Boot – SOAP Web 服務](https://howtodoinjava.com/spring/spring-boot/spring-boot-soap-webservice-example/) 7. [Spring Boot – SOAP 客戶端](https://howtodoinjava.com/spring/spring-boot/spring-soap-client-webservicetemplate/) 8. [Spring Boot 2 和 ehcache 3 示例](https://howtodoinjava.com/spring-boot2/ehcache3-config-example/) ## 8\. 其他有用的話題 1. [在啟動時禁用橫幅](https://howtodoinjava.com/spring-boot2/disable-logo-banner/) 2. [Spring Boot – JSP 視圖](https://howtodoinjava.com/spring/spring-boot/spring-boot-jsp-view-example/) 3. [Spring Boot – 自定義`PropertyEditor`](https://howtodoinjava.com/spring/spring-boot/custom-property-editor-example/) 4. [Spring Boot – `@EnableScheduling`](https://howtodoinjava.com/spring/spring-boot/enable-scheduling-scheduled-job-example/) 5. [Spring Boot – `JMSTemplate`](https://howtodoinjava.com/spring/spring-boot/spring-boot-jmstemplate-activemq/) 6. [Spring Boot – RSS / ATOM Feed](https://howtodoinjava.com/spring/spring-boot/spring-boot-rome-rss-and-atom-feed/) 7. [Spring Boot 讀取資源文件夾](https://howtodoinjava.com/spring-boot2/read-file-from-resources/)讀取文件 8. [Spring Boot 面試問題](https://howtodoinjava.com/interview-questions/spring-boot-interview-questions/) 學習愉快!
                  <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>

                              哎呀哎呀视频在线观看