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

                企業??AI智能體構建引擎,智能編排和調試,一鍵部署,支持知識庫和私有化部署方案 廣告
                # `SpringBootServletInitializer`教程 > 原文: [http://zetcode.com/springboot/springbootservletinitializer/](http://zetcode.com/springboot/springbootservletinitializer/) `SpringBootServletInitializer`教程展示了如何從傳統的 WAR 部署中部署 Spring Boot 應用。 當前的趨勢是從可執行的 JAR 部署 Spring Boot 應用。 (有關如何從 JAR 啟動簡單的 Web 應用的詳細信息,請參見 [Spring Boot 第一個 Web 應用](/articles/springbootwebfirst)。) Spring 是流行的 Java 應用框架。 Spring Boot 致力于以最小的努力創建獨立的,基于生產級別的基于 Spring 的應用。 ## `SpringBootServletInitializer` `SpringBootServletInitializer`是從傳統 WAR 部署運行`SpringApplication`的接口。 它將 Servlet,Filter 和`ServletContextInitializer` Bean 從應用上下文綁定到服務器。 ## SpringBootServletInitializer 示例 該應用創建一個簡單的 Spring Boot RESTful 應用并將其打包到 WAR 中。 ```java pom.xml src ├───main │ ├───java │ │ └───com │ │ └───zetcode │ │ │ Application.java │ │ └───controller │ │ MyController.java │ └───resources └───test └───java ``` 這是項目結構。 `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 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.zetcode</groupId> <artifactId>servletinitializer</artifactId> <version>1.0-SNAPSHOT</version> <packaging>war</packaging> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <maven.compiler.source>11</maven.compiler.source> <maven.compiler.target>11</maven.compiler.target> </properties> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.1.1.RELEASE</version> </parent> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build> </project> ``` 這是 Maven 構建文件。 `spring-boot-starter-web`是使用 Spring MVC 構建 Web(包括 RESTful)應用的入門程序。 該應用打包到一個 WAR 文件中。 `com/zetcode/controller/MyController.java` ```java package com.zetcode.controller; import org.springframework.http.MediaType; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RestController; @RestController public class MyController { @GetMapping(value = "/", produces = MediaType.TEXT_PLAIN_VALUE) public String index() { return "Hello there"; } } ``` 這是 Spring Boot Web 應用的控制器類。 控制器以`@Restontroller`注解修飾。 ```java @GetMapping(value = "/", produces = MediaType.TEXT_PLAIN_VALUE) public String index() { return "Hello there"; } ``` 對主頁的 GET 請求返回一個字符串。 綁定是通過`@GetMapping`完成的。 `com/zetcode/Application.java` ```java package com.zetcode; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; @SpringBootApplication public class Application extends SpringBootServletInitializer { public static void main(String[] args) { SpringApplication.run(Application.class, args); } } ``` `Application`設置 Spring Boot 應用。 它從`SpringBootServletInitializer`擴展而來,可以將其部署為 WAR。 通過將 WAR 部署在 Tomcat 服務器上并將其作為具有嵌入式 Tomcat 的自可執行 Web 歸檔執行,可以運行該應用。 在本教程中,我們創建了第一個可從傳統 WAR 部署的 Spring Boot Web 應用。 您可能也對相關教程感興趣: [Spring Boot 第一個 Web 應用](/articles/springbootwebfirst/), [Spring Web 應用簡介](/articles/springwebfirst/),[獨立的 Spring 應用](/articles/standalonespring/), [FreeMarker 教程[](/java/freemarker/) , [Java 教程](/lang/java/),[游戲簡介](/java/play/), [Spark 簡介](/java/spark/)或[ Strips 簡介](/java/stripes/)。
                  <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>

                              哎呀哎呀视频在线观看