SpringBoot项目开发完毕后,支持两种方式部署到服务器:
package cn.itbluebox.springbootdeploy;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RequestMapping("/user")
@RestController
public class UserController {
@RequestMapping("/findAll")
public String findAll(){
return "SUCCESS";
}
}
打包成功,以及对应jar的位置
jar包的位置
D:\AProgramWorkSpace\idea\test\springboot-deploy\target\springboot-deploy-0.0.1-SNAPSHOT.jar
我们发现其位置就在当前项目的target目录下
在jar所在目录的地址栏内输入cmd
输入:java -jar springboot-deploy-0.0.1-SNAPSHOT.jar
访问:http://localhost:8080/user/findAll
war打包后对应配置文件application.properties当中的server.port会失效,如果需要修改端口号需要去Tomcat的配置文件当中设置
<packaging>war</packaging>
SpringbootDeployApplication
去继承SpringBootServletInitializer
重写configure
方法
package cn.itbluebox.springbootdeploy;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
@SpringBootApplication
public class SpringbootDeployApplication extends SpringBootServletInitializer {
public static void main(String[] args) {
SpringApplication.run(SpringbootDeployApplication.class, args);
}
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
return builder.sources(SpringbootDeployApplication.class);
}
}
对应war 的路径
D:\AProgramWorkSpace\idea\test\springboot-deploy\target\springboot-deploy-0.0.1-SNAPSHOT.war
我们发现其位置就在当前项目的target目录下
将war放到Tomcat的安装目录的wabapps的目录下
启动Tomcat,在bin目录下的startup.bat
启动成功
访问:http://localhost:8080/springboot-deploy-0.0.1-SNAPSHOT/user/findAll
修改pom.xml
打包
将war放到Tomcat的安装目录的wabapps的目录下
放入后不用重新启动Tomcat自动会解压对应war
访问http://localhost:8080/springboot/user/findAll
版权说明 : 本文为转载文章, 版权归原作者所有 版权申明
原文链接 : https://code100.blog.csdn.net/article/details/121191014
内容来源于网络,如有侵权,请联系作者删除!