java - Spring boot 改成war后部署到本地的tomcat上,無法訪問項目
問題描述
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.springframework.boot.builder.SpringApplicationBuilder;import org.springframework.boot.web.support.SpringBootServletInitializer;@SpringBootApplicationpublic class ApplicationStart extends SpringBootServletInitializer{
public static void main(String[] args){ SpringApplication.run(ApplicationStart.class, args);}@Overrideprotected 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;
@RestControllerpublic class Bargain {
@RequestMapping(value='/test')@ResponseBodypublic String test(){ return 'ECS1';}
}5.配置文件的信息
6.eclipse上直接使用maven install命令打包
將這個war包放到本機的tomcat的webapps目錄下面,并且改名成demo.war
7.啟動Tomcat7
8.測試訪問,訪問報錯
請教我這是哪里有問題啊?
問題解答
回答1:你的application.yml中配置的server.port配置的是spring boot內置的tomcat的端口號, 打成war包部署在獨立的tomcat上之后, 你配置的server.port是不起作用的.
回答2:從你截圖日志看 tomcat已經啟動成功 端口是8080http://127.0.0.1:8080/demo/test
