spring boot 项目部署

本文介绍了Spring Boot项目的部署过程,包括环境准备(Eclipse IDE和JDK 1.8),详细部署步骤,如通过Maven clean package打包,解决可能出现的错误,将WAR文件复制到服务器并用Java命令运行,以及如何通过地址访问。此外,还提到在排除Tomcat时的注意事项。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

spring boot 项目部署

1.环境准备

ide:eclipse

jdk:1.8

2.部署步骤

1.右键项目名称->run as ->7,maven build-> 使用clean package 命令进行打包

这里写图片描述

2.这个过程中可能会出现下边这种错误,在pom文件中添加build 里边的片段就好

[ERROR] Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0.463 s <<< FAILURE! - in com.example.demo.SinosoftApplicationTests
[ERROR] initializationError(com.example.demo.SinosoftApplicationTests)  Time elapsed: 0.006 s  <<< ERROR!
java.lang.IllegalStateException: Unable to find a @SpringBootConfiguration, you need to use @ContextConfiguration or @SpringBootTest(classes=...) with your test

[INFO] 
[INFO] Results:
[INFO] 
[ERROR] Errors: 
[ERROR]   SinosoftApplicationTests.initializationError » IllegalState Unable to find a @...
[INFO] 
[ERROR] Tests run: 1, Failures: 0, Errors: 1, Skipped: 0
[INFO] 
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 7.067 s
[INFO] Finished at: 2018-07-11T14:28:56+08:00
[INFO] Final Memory: 35M/327M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.21.0:test (default-test) on project dh_app: There are test failures.
[ERROR] 
[ERROR] Please refer to H:\project\zz\dh_app\target\surefire-reports for the individual test results.
[ERROR] Please refer to dump files (if any exist) [date]-jvmRun[N].dump, [date].dumpstream and [date]-jvmRun[N].dumpstream.
[ERROR] -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException

 <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
           <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <configuration>
                    <skip>true</skip>
                </configuration>
            </plugin> 
        </plugins>
    </build>

3.打包完成后将target下的war复制到服务器任意路径,并通过cmd 的方式进入该文件夹,使用java -jar —-.war命令运行该程序即可
这里写图片描述

4.输入地址访问

5.需要注意的是排除tomcat需要去掉

<dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        <!--    <exclusions>
                <exclusion>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-starter-tomcat</artifactId>
                </exclusion>
            </exclusions> -->
        </dependency>

==============================================================================================================================================================================

这只是一种方式,第二种方式:我在使用tomcat部署时 发现程序可以运行,但是页面无法访问的情况,希望大神指点。

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值