spring-boot項目的建立以及部署到外部tomcat的方法

來源:互聯網
上載者:User

項目的建立:
直接從官網下載一個入門例子,地址:http://spring.io/guides/gs/spring-boot/
因為我用的maven構建項目,所以刪除了其他無用的檔案和檔案夾,只保留gs-spring-boot目錄(該目錄下有src和pom.xml);下面是本文: 命令列進入項目目錄(gs-spring-boot),執行”mvn clean” 接著執行”mvn compile” 最後執行”mvn spring-boot:run”

此時spring-boot已經跑起來了,通過localhost:8080/就可以訪問了

註:匯入到eclipse的時候,不要直接open project,要匯入->存在的maven項目;否則提示不是java project

部署到外部tomcat:
參照官網的方法:地址:http://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#build-tool-plugins-maven-packaging 修改入口java檔案,繼承SpringBootServletInitializer類,並覆寫configure方法;

@SpringBootApplicationpublic class Application extends SpringBootServletInitializer {    @Override    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {        return application.sources(Application.class);    }    public static void main(String[] args) throws Exception {        SpringApplication.run(Application.class, args);    }}

2.修改pom.xml檔案: 修改打包類型為war:<packaging>war</packaging> 添加spring-boot-starter-tomcat依賴,scope設定為provided:

<dependency>  <groupId>org.springframework.boot</groupId>  <artifactId>spring-boot-starter-tomcat</artifactId>                 <scope>provided</scope></dependency>

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.