SpringBoot在本地开发经过,部署到服务器上失败,没法访问

今天刚刚完成了SpringBoot的一个微服务,因而将其打包成war包,而后放在了tomcat中的webapps目录下,但是访问时出现了404错误,以下:web

image

tomacat启动时日志显示
image
第一个显示了 Apache Tomcat/8.0.53,说明tomcat服务没有问题,而是本身项目问题。在启动日志中,能够看出找不到该路由,说明该服务没有启动。

问题缘由

该问题是由于本身打包时没有指明启动类,tomcat找不到项目的启动类。俗话就是,即tomcat解压放进去的war包后,找不到将war包运行起来的入口,至关于找不到项目的“主函数”,不知怎样将它运行起来。故服务没有运行。spring

解决方法

须要在项目中指明启动类,即声明项目的“主函数”,在项目的pom.xl中添加以下代码apache

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <configuration>
                <source>1.8</source>
                <target>1.8</target>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
            <configuration>
              <!--此处为本身的启动类-->
              <mainClass>com.test.app.App</mainClass>
            </configuration>
            <executions>
                <execution>
                    <goals>
                        <goal>repackage</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>
复制代码

<mainClass></mainClass>中写入本身的服务启动类,个人是com.test.app.App,如图: tomcat

image

改完 pom.xml后,使用 mvn clean package 从新打包放到tomcat下的 webapps目录下。 出现以下消息即为运行成功。
image

新手上车,请多指教,若有问题,请邮件联系:young5678@qq.combash

参考

此知识点来自于蚂蚁课堂视频markdown

相关文章
相关标签/搜索