<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、智譜、豆包、星火、月之暗面及文生圖、文生視頻 廣告
                # 第三章 從HellWorld開始 ### 創建Maven工程 打開Intellij或Eclipse,新建一個Maven工程(Project),其中GroupId和ArtifactId可以隨便添寫,如Hello 如果不清楚如何創建Maven工程,請大家自行百度。 創建好后(筆者創建的名稱為HelloWorld),如果使用的是Intellij IDE,它會彈出Maven projects need to be imported提示,選擇“Enable Auto-Import”。 工程目錄結構為: ~~~ HelloWorld --src --main --java --resources --test(里面內容可以忽略) --pom.xml ~~~ ### 配置pom.xml文件 打開工程名下的pom.xml,原內容如下: ~~~ <?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>hello</groupId> <artifactId>hello</artifactId> <version>1.0-SNAPSHOT</version> </project> ~~~ 1、添加parent標簽,以下指明SpringBoot版本為1.4.0 ~~~ <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.4.0.RELEASE</version> </parent> ~~~ 2、添加starter-web依賴,因為我們是開發Web平臺,所以必須依賴spring-boot-starter-web,它內置了tomcat容器。 ~~~ <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> </dependencies> ~~~ **添加后完整的pom.xml文件內容為:** ~~~ <?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>hello</groupId> <artifactId>hello</artifactId> <version>1.0-SNAPSHOT</version> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.4.0.RELEASE</version> </parent> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> </dependencies> </project> ~~~ ### 創建入口類 **創建包名** 展開src->main->java,右擊java,新建一個package,名稱為lightsword。右擊lightsword,新建一個java類,名稱為lightsword.java。 lightsword.java內容如下:(增加一個main方法,調用SpringApplication類的run方法,引用了一個SpringBootApplication注解) ~~~ package lightsword; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication public class lightsword { public static void main(String[] args){ SpringApplication.run(lightsword.class, args); } } ~~~ 運行lightsword.java后,出現以下信息表示運行成功: ~~~ ... ... . ____ _ __ _ _ /\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \ ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \ \\/ ___)| |_)| | | | | || (_| | ) ) ) ) ' |____| .__|_| |_|_| |_\__, | / / / / =========|_|==============|___/=/_/_/_/ .... .... : Started lightsword in 3.953 seconds (JVM running for 5.172) ~~~ **為了打印Hello World,我們在main方法加入一行代碼** ~~~ public static void main(String[] args){ SpringApplication.run(lightsword.class, args); System.out.println("Hello world"); } ~~~ 再次運行,結果多了一行Hello world: ... .... : Started lightsword in 3.908 seconds (JVM running for 4.95) Hello world **可能遇到的問題:端口沖突** 如果你電腦上的8080端口號被其它程序(如jenkins)占用了,則運行lightsword會報以下錯誤: ~~~ java.net.BindException: Address already in use ... ... Failed to start component [Connector[HTTP/1.1-8080]] ... ~~~ **解決方法** 在src->main->resources目錄下新建一個文件,名稱為application.properties(這是SpringBoot統一的配置文件) 加了以下一行內容:(取個電腦上可用的端口號,如下面的9527,看過星爺電影的都懂的) server.port = 9527 再次運行即可。 ### 講解 分析我們的入口類lightsword.java。 1. @SpringBootApplication注解,它其實幫我們做了很多事情,包括各種配置,掃描等。它相當于以下三個注解的作用: @Configuration @EnableAutoConfiguration @ComponentScan 為了簡化和方便,我們必須在入口類加入以上注解,當然最方便的就使用@SpringBootApplication一個注解。 2. 調用SpringApplication類的run啟動應用程序。 **后面章節我們都使用9527端口作為講解。**
                  <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>

                              哎呀哎呀视频在线观看