java - Spring boot 改成war後部署到本地的tomcat上,無法存取項目
某草草
某草草 2017-05-17 09:58:46
0
2
868

1.我依照網路上的教學將Spring boot專案改成war進行打包,然後部署在本機的tomcat7.0上,啟動tomcat,存取專案時發現無法存取專案了.

2.pom檔案的內容

<project xmlns="http://maven.apache.org/POM/4... http://maven.apache.org/xsd/maven-4.0.0.xsd">

<modelVersion>4.0.0</modelVersion>
<groupId>com.ming.wei.yue</groupId>
<artifactId>bargain</artifactId>
<packaging>war</packaging>
<version>0.0.1-SNAPSHOT</version>
<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.4.2.RELEASE</version>
</parent>
<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    <java.version>1.8</java.version>
    <start-class>com.ming.wei.yue.ApplicationStart</start-class>
</properties>
<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-devtools</artifactId>
        <optional>true</optional>
    </dependency>
    <!-- 这个未来方便本机测试使用的tomcat -->
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-tomcat</artifactId>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>org.apache.tomcat.embed</groupId>
        <artifactId>tomcat-embed-jasper</artifactId>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>jstl</artifactId>
    </dependency>
</dependencies>
<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
    </plugins>
</build>

</project>

3.啟動類別配置

package com.ming.wei.yue;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springamework. SpringApplicationBuilder;
import org.springframework.boot.web.support.SpringBootServletInitializer;
@SpringBootApplication
public class ApplicationStart extends SpringBootServletInitializer{

public static void main(String[] args){
    SpringApplication.run(ApplicationStart.class, args);
}
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
    return builder.sources(ApplicationStart.class);
}

}

4.controller類別

package com.ming.wei.yue.action;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class Bargain {

@RequestMapping(value="/test")
@ResponseBody
public String test(){
    return "ECS1";
}

}
5.設定檔的資訊

#6.eclipse上直接使用maven install指令打包

##將這個war套件放到本機的tomcat的webapps目錄下面,並且改名成demo.war


#7.啟動Tomcat7

##8.測試訪問,訪問錯誤

#請教我這是哪裡有問題啊?

某草草
某草草

全部回覆(2)
阿神

你的application.yml中配置的server.port配置的是spring boot內置的tomcat的端口號, 打成war包部署在獨立的tomcat上之後, 你配置的server.port是不起作用的.

小葫芦

從你截圖日誌看 tomcat已經啟動成功 連接埠是8080
http://127.0.0.1:8080/demo/test

熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板