<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國際加速解決方案。 廣告
                # Spring Boot 簡介 > 原文: [https://javatutorial.net/introduction-to-spring-boot](https://javatutorial.net/introduction-to-spring-boot) 在本教程中,您將學習什么是 Spring Boot 以及如何開始使用它。 ![java-featured-image](https://img.kancloud.cn/05/3e/053ee0bb59842d92359246c98f815e0c_780x330.jpg) ## 先決條件 * 您的時間 10-20 分鐘 * 熟悉 [Maven](https://javatutorial.net/how-to-install-maven-on-windows-linux-and-mac) ## 什么是 Spring Boot? Spring Boot 使創建獨立的基于 Spring 的應用程序的過程變得非常簡單。 通過使用基于 Java 的 Spring Boot 框架,您將不需要太多的配置。 如果您總體上熟悉 Spring,那么您就會知道 Spring 中 XML 配置文件的龐大程度和不可管理性。 好吧,多虧了 Spring Boot,您不會遇到這個問題。 使用 Spring Boot 的另一個好處是,它大大減少了開發時間,并提供了一種更簡單的入門方法。 ## 好處 * 易于部署 * 容易拿起 * 節省時間 * 不需要太多配置 * 提供依賴關系管理 * 提供基于注解的 spring 應用程序 既然您知道 Spring Boot 是什么,并且已經熟悉了它的優勢,那么讓我向您展示如何立即開始使用它。 ## 使用 Maven 構建 在您的項目目錄中,創建一個子目錄。 例: ```java mkdir -p src/main/java/demo ``` 這就是您的`pom.xml`文件的外觀: `pom.xml` ```java <?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>org.springframework</groupId> <artifactId>gs-spring-boot</artifactId> <version>0.1.0</version> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.1.6.RELEASE</version> </parent> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> </dependencies> <properties> <java.version>1.8</java.version> </properties> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build> </project> ``` 請注意,我們正在使用 spring boot maven 插件。 簡而言之,它搜索`main()`方法,提供內置的依賴項解析器,該解析器設置版本號與 Spring Boot 依賴項相匹配,最后,它收集類路徑上的所有 jar,然后構建可運行的“uber-jar”,這使得執行起來更加方便。 ## 讓我們構建一個演示 Web 應用程序 讓我們創建一個控制器。 控制器的路徑為: ```java src/main/java/demo/DemoController.java ``` **DemoController.java** ```java package demo; import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RequestMapping; @RestController public class DemoController { @RequestMapping("/") public String handle() { return "Hello World!"; } } ``` 對于此控制器類,我們使用`@RestController`注解,如果您不熟悉該注解,則它基本上可以供 Spring MVC 使用,以能夠處理 Web 請求。 因此,所有到`"/"`路徑的 Web 請求都將由我們的`handle()`方法處理。 將針對此特定路徑(`"/"`)處理 Web 請求的原因是因為我們使用`@RequestMapping`注解將其映射到此 Web 路徑。 現在是時候創建我們的`Application`類了。 ## 讓我們構建一個`DemoApplication`類 讓我們創建我們的`DemoApplication`類。 應用程序類的路徑為: ```java src/main/java/demo/DemoApplication.java ``` `DemoApplication.java` ```java package demo; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication public class Application { // that's the main method public static void main(String[] args) { SpringApplication.run(Application.class, args); } } ``` 感謝`@SpringBootApplication`注解,我們正在初始化 Spring Boot `Application`的入口點。 請注意,我們在此類中有`main`方法。 `@SpringBootApplication`注解包含`@EnableAutoConfiguration`,`@ComponentScan`和`@SpringBootConfiguration`。 使用`@SpringBootApplication`注解時,我們“調用”了所有上述注解。 ## 運行應用程序 要使用 maven 運行應用程序,請執行以下行: ```java mvn package && java -jar target/gs-spring-boot-0.1.0.jar ```
                  <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>

                              哎呀哎呀视频在线观看