search

Home  >  Q&A  >  body text

java - After changing Spring boot to war and deploying it to the local tomcat, the project cannot be accessed

1. I followed the online tutorial to change the Spring boot project into war for packaging, then deployed it on the local tomcat7.0, started tomcat, and found that the project could not be accessed when accessing the project.

2.Pom file content

<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. Startup class configuration

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;
@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 class

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. Configuration file information

6. Directly use the maven install command to package on eclipse

Put this war package under the webapps directory of tomcat on the local machine, and change its name to demo.war


7. Start Tomcat7

8. Test access, access error

Please tell me what’s wrong with this?

某草草某草草2754 days ago859

reply all(2)I'll reply

  • 阿神

    阿神2017-05-17 10:00:46

    The server.port configured in your application.yml is configured with the port number of tomcat built into spring boot. After it is packaged into a war package and deployed on an independent tomcat, the server.port you configured will not work.

    reply
    0
  • 高洛峰

    高洛峰2017-05-17 10:00:46

    From your screenshot log, it can be seen that tomcat has been started successfully. The port is 8080
    http://127.0.0.1:8080/demo/test

    reply
    0
  • Cancelreply