1.場景還原
springboot配置相當簡單,人人皆知。怎么把springboot工程部署到云服務器上呢?可能有人會說,博主你前篇不是講了java工程的云部署把;但是我想澄清一點的是,我前篇的工程都是ssm框架搭建的,而springboot可是自帶tomcat嘍!這就有點麻煩....淡定,往下看
2.配置解析
①application.properties文件
# EMBEDDED SERVER CONFIGURATION (ServerProperties)server.port=8010server.session-timeout=1800server.context-path=server.tomcat.max-threads=0server.tomcat.uri-encoding=UTF-8server.tomcat.basedir=target/tomcat# HTTP encoding (HttpEncodingProperties)spring.http.encoding.charset=UTF-8spring.http.encoding.enabled=truespring.http.encoding.force=true#datasourcespring.datasource.url=jdbc:mysql://192.168.0.129/ccoee?useUnicode=true&characterEncoding=UTF-8spring.datasource.username=zhangxingspring.datasource.password=zxp52077spring.datasource.driverClassName=com.mysql.jdbc.Driver#mybatismybatis.type-aliases-package=com.cckj.modelmybatis.mapper-locations=classpath:mapper/*.xml#mappermapper.mappers=tk.mybatis.mapper.common.Mappermapper.not-empty=falsemapper.identity=MYSQL#pagehelperpagehelper.helperDialect=mysqlpagehelper.reasonable=truepagehelper.supportMethodsArguments=truepagehelper.params=count=countSql#logging#logging.level.root=INFO#logging.level.org.springframework.web=DEBUGlogging.level.org.zhangxing=DEBUG
就是這個文件 包羅了ssm框架的煩瑣配置,哪個程序員不愛呢?那么既然愛,請深愛!將遠程數據庫連接配好,這里不再贅述。
②pom.xml
4.0.0jarmagicmagic1.0-SNAPSHOTorg.springframework.bootspring-boot-starter-parent1.4.3.RELEASEorg.springframework.bootspring-boot-starter-jdbcorg.springframework.bootspring-boot-starter-testorg.springframework.bootspring-boot-starter-webmysqlmysql-connector-javacom.alibabadruid1.0.10org.mybatis.spring.bootmybatis-spring-boot-starter1.1.1tk.mybatismapper-spring-boot-starter1.0.0com.github.pagehelperpagehelper-spring-boot-starter1.0.0helloworldorg.springframework.bootspring-boot-maven-pluginspring-milestonehttp://repo.spring.io/libs-release
這里要注意的是,打包方式jar,不再是war
jar
自定義打包名稱
helloworldorg.springframework.bootspring-boot-maven-pluginspring-milestonehttp://repo.spring.io/libs-release
3.實現方案
①開始打jar包
跟前篇步驟一樣,點開右邊的Maven Project,點擊Lifecycle,最后雙擊packet,生成jar包
②將剛打的jar上傳至云服務器的java目錄下
③運行命令:java -jar helloworld.jar,然后springboot工程的內置tomcat就開啟了
訪問效果:
這里還沒完呢,當然你關閉當前的xshell 命令界面時,再次訪問就失效了,這是因為springboot內置的tomcat隨之也關閉了,那么有人會問,這叫什么云部署呀?跟本地沒兩樣,是啊,我也這么覺得;別急,往下看
④常駐云服務器
運行命令: nohup java -jar helloworld.jar &
nohup的意思不掛服務,常駐的意思,除非云服務器重啟,那就沒法了;最后一個&表示執行命令后要生成日志文件nohup.out
好了,這樣就不擔心關閉xshell,只要云服務器不關閉,總能訪問的。
我是張星,歡迎加入博主技術交流群,群號:313145288
csdn博客鏈接:http://blog.csdn.net/zhangxing52077/article/details/73008359