SpringBoot项目的云服务器部署
1.场景还原
springboot配置相当简单,人人皆知。怎么把springboot工程部署到云服务器上呢?可能有人会说,博主你前篇不是讲了java工程的云部署把;但是我想澄清一点的是,我前篇的工程都是ssm框架搭建的,而springboot可是自带tomcat喽!这就有点麻烦....淡定,往下看
2.配置解析
①application.properties文件
# EMBEDDED SERVER CONFIGURATION (ServerProperties)
server.port=8010
server.session-timeout=1800
server.context-path=
server.tomcat.max-threads=0
server.tomcat.uri-encoding=UTF-8
server.tomcat.basedir=target/tomcat # HTTP encoding (HttpEncodingProperties)
spring.http.encoding.charset=UTF-8
spring.http.encoding.enabled=true
spring.http.encoding.force=true #datasource
spring.datasource.url=jdbc:mysql://192.168.0.129/ccoee?useUnicode=true&characterEncoding=UTF-8
spring.datasource.username=zhangxing
spring.datasource.password=zxp52077
spring.datasource.driverClassName=com.mysql.jdbc.Driver #mybatis
mybatis.type-aliases-package=com.cckj.model
mybatis.mapper-locations=classpath:mapper/*.xml #mapper
mapper.mappers=tk.mybatis.mapper.common.Mapper
mapper.not-empty=false
mapper.identity=MYSQL #pagehelper
pagehelper.helperDialect=mysql
pagehelper.reasonable=true
pagehelper.supportMethodsArguments=true
pagehelper.params=count=countSql #logging
#logging.level.root=INFO
#logging.level.org.springframework.web=DEBUG
logging.level.org.zhangxing=DEBUG
就是这个文件 包罗了ssm框架的烦琐配置,哪个程序员不爱呢?那么既然爱,请深爱!将远程数据库连接配好,这里不再赘述。
②pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<packaging>jar</packaging>
<groupId>magic</groupId>
<artifactId>magic</artifactId>
<version>1.0-SNAPSHOT</version> <parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.4.3.RELEASE</version>
</parent> <dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency> <dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
</dependency> <dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency> <dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency> <dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
<version>1.0.10</version>
</dependency> <dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>1.1.1</version>
</dependency> <dependency>
<groupId>tk.mybatis</groupId>
<artifactId>mapper-spring-boot-starter</artifactId>
<version>1.0.0</version>
</dependency> <dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper-spring-boot-starter</artifactId>
<version>1.0.0</version>
</dependency> </dependencies> <build>
<finalName>helloworld</finalName>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
<repositories>
<repository>
<id>spring-milestone</id>
<url>http://repo.spring.io/libs-release</url>
</repository>
</repositories> </project>
这里要注意的是,打包方式jar,不再是war
<packaging>jar</packaging>
自定义打包名称
<build>
<finalName>helloworld</finalName>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
<repositories>
<repository>
<id>spring-milestone</id>
<url>http://repo.spring.io/libs-release</url>
</repository>
</repositories>
③Application启动类代码
@SpringBootApplication
@MapperScan(basePackages = "com.cckj.dao", markerInterface =Mapper.class)
public class Application { public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
注意:各个方法中的测试主函数最好全部注释掉!
3.实现方案
①开始打jar包
跟前篇步骤一样,点开右边的Maven Project,点击Lifecycle,最后双击packet,生成jar包
②将刚打的jar上传至云服务器的java目录下
③运行命令:java -jar helloworld.jar,然后springboot工程的内置tomcat就开启了
注意:部署好之后,需要开放端口号:3306,8089
访问效果:
这里还没完呢,当然你关闭当前的xshell 命令界面时,再次访问就失效了,这是因为springboot内置的tomcat随之也关闭了,那么有人会问,这叫什么云部署呀?跟本地没两样,是啊,我也这么觉得;别急,往下看
④常驻云服务器
运行命令: nohup java -jar helloworld.jar &
nohup的意思不挂服务,常驻的意思,除非云服务器重启,那就没法了;最后一个&表示执行命令后要生成日志文件nohup.out
好了,这样就不担心关闭xshell,只要云服务器不关闭,总能访问的。
我是张星,欢迎加入博主技术交流群,群号:313145288
SpringBoot项目的云服务器部署的更多相关文章
- django 本地项目部署uwsgi 以及云服务器部署 uwsgi+Nginx+Docker+MySQL主从
一 .django 本地项目部署uwsgi 1 本地部署项目 uwsgi安装测试 通过uwsgi 进行简单部署 安装uwsgi命令:pip install uwsgi -i http://pypi.d ...
- 云服务器部署Python项目(nginx+uwsgi+mysql+项目)
python项目部署到云服务器 关注公众号"轻松学编程"了解更多. 一.硬件准备 云服务器,系统ubuntu_16_04 . 注意:要在安全组中开放Http的80端口. 二.软件准 ...
- 【云服务器部署】---Linux下安装nginx
[云服务器部署]---Linux下安装nginx 之前两篇,分别讲了:Linux下安装MySQL 和 springboot项目部署云服务器 nginx安装也是挺简单的.具体步骤如下: 第一步,下载 ...
- MVC - 云服务器部署
本章将和大家分享的是如果在云服务器上部署mvc,云服务器部署其实也不高大上,就和咋们在自己电脑上用iis发布部署站点一样,只是需要使用云解析把自己购买的域名解析到对应的自己的云服务器上,这些都是用的云 ...
- #阿里云#云服务器部署可道云(KodExplorer)
前言:在做一些项目的时候,经常有一些文档交流,修改之后的文档在QQ或微信上发来发去,还要下载,很是不爽,有一个挺有用的东西叫做KodExplorer可道云. kodexplorer可道云是目前国内有代 ...
- 阿里云服务器部署Office online注意事项
阿里云服务器部署Office online注意事项 一.参考配置 实例规格:4核8GB(IO优化) 网络带宽:5Mbps 系统盘:40G 存储盘:200G OS:Windows Server 2016 ...
- 【云服务器部署】---Linux下安装MySQL
[云服务器部署]---Linux下安装MySQL 有关如何阿里云ECS建网站,推荐一片文章,我是是通过这篇文章安装tomcat和jdk的 网址:阿里云ECS建网站(建站)超详细全套完整图文教程! 注意 ...
- Python FLask 腾讯云服务器部署
CentOs 7.0云服务器部署Python Flask 使用: Python 2.7 Flask nginx gunicorn easy_install python-dev yum install ...
- 使用maven构建项目时,SSM和springboot项目的打包与云服务器部署
下面讲讲如何打包SSM和springboot项目,并部署到云服务器上. 由于使用的IDE不同,有的使用eclipse,有的使用idea,所以如果在IDE中按照 maven clean 再 maven ...
随机推荐
- UVA——11988 Broken Keyboard (a.k.a. Beiju Text)
11988 Broken Keyboard (a.k.a. Beiju Text)You’re typing a long text with a broken keyboard. Well it’s ...
- Xamarin.Android真机测试提示[INSTALL_FAILED_UPDATE_INCOMPATIBLE]
Xamarin.Android真机测试提示[INSTALL_FAILED_UPDATE_INCOMPATIBLE] 使用真机测试的时候,出现以下错误提示: Deployment failed ...
- OpenJ_Bailian - 1037 A decorative fence
Discription Richard just finished building his new house. Now the only thing the house misses is a c ...
- POJ1226 Substrings(二分+后缀数组)
题意:给n个字符串,求最长的子串,满足它或它的逆置出现在所有的n个字符串中. 把n个字符串及其它们的逆置拼接,中间用不同字符隔开,并记录suffix(i)是属于哪个字符串的: 跑后缀数组计算heigh ...
- 【bzoj1951】【古代猪文】Lucas定理+欧拉定理+孙子定理
(上不了p站我要死了,当然是游戏原画啊) Description (题面倒是很有趣,就是太长了) 题意: 一个朝代流传的猪文文字恰好为N的k分之一,其中k是N的一个正约数(可以是1和N).不过具体是哪 ...
- k8s学习
k8s简介 在学习k8s之前,相信大家和我一样,肯定都学习和使用过docker容器,并且对容器技术有了一个基本的认识.引用张磊老师的总结:其实一个"容器",实际上是一个由Linux ...
- 【bzoj1001】【最短路】【对偶图】【最大流转最小割】狼抓兔子题解
[BZOJ1001]狼抓兔子 1001: [BeiJing2006]狼抓兔子 Time Limit: 15 Sec Memory Limit: 162 MBSubmit: 18872 Solved ...
- Linux下查看某个进程的网络带宽占用情况
说明: 1.可能查看某个进程的带宽占用需要明确知道PID.进程名字.发送速度.接收速度. 2.很遗憾,在Linux原生的软件中没有这样的一款,只能额外装,最符合以上的情况就只有nethogs. 3.n ...
- XCode工程内多Targets教程
作者 透明de面具 原帖地址 http://www.cocoachina.com/bbs/read.php?tid-10972-fpage-0-toread--page-1.html 相信很 ...
- python3使用configparser解析配置文件
http://www.jb51.net/article/87402.htm 需要注意的是每一个字段后面的值外面没有引号,切记,自己第一次配置时,加了引号,搞了半天 没找到错误,, 在用Python做开 ...