使用SprinBoot基於Maven環境配置,使用Spring-boot-run啟動,使用jetty啟動


 【楔子】通常我們啟動項目直接Run,現在我們采用基於Maven使用一個插件就是通過Spring Boot運行插件。

配置的方式。

【新建maven項目】

【pom配置】:

<?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.smart</groupId>
    <artifactId>chapter2</artifactId>
    <version>1.0</version>


<!--添加一個Boot Web 啟動器-->
    <dependencies>
        <!--添加一個Boot Web 啟動器-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
            <version>1.3.3.RELEASE</version>
        </dependency>




    </dependencies>
    <build>
        <plugins>
            <!--配置運行插件-->
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>
</project>

其中的插件:

 <build>
        <plugins>
            <!--配置運行插件-->
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

引用SpringBoot運行插件

【java代碼】:

package com.smart;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@EnableAutoConfiguration
public class BbsDemo {
    @RequestMapping("/")
    public  String index(){
        return "歡迎光臨ee論壇";
    }
    public static void main(String[] args) throws Exception{
        SpringApplication.run(BbsDemo.class,args);
    }

}

【運行】:

在工具欄點View-toolWindow-Maven Project

類似如此打開刷新Maven Project  ,在plugins里找到SpringBoot項目,啟用spring-boot:run

打開瀏覽器:http://localhost:8080/  

 

 【Jetty運行】Spring-Boot默認使用Tomcat運行,如果想要使用Jetty啟動當前應用,則直接添加相應依賴包,相比以前的我們也配置過Tomcat的吧,SpringBoot關鍵功能依賴包申明,自己只需要寫幾行代碼,配置的事情讓Spring去搞定。

我們添加如下代碼:

 <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-jetty</artifactId>
            <version>1.3.3.RELEASE</version>
        </dependency>

啟動應用,看下Jetty是否成功啟動項目應用。

成功啟動,瀏覽網頁,效果如上

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM