1.場(chǎng)景還原
springboot配置相當(dāng)簡(jiǎn)單,人人皆知茎活。怎么把springboot工程部署到云服務(wù)器上呢沸版?可能有人會(huì)說(shuō),博主你前篇不是講了java工程的云部署把楞件;但是我想澄清一點(diǎn)的是衫生,我前篇的工程都是ssm框架搭建的裳瘪,而springboot可是自帶tomcat嘍!這就有點(diǎn)麻煩....淡定罪针,往下看
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
就是這個(gè)文件 包羅了ssm框架的煩瑣配置彭羹,哪個(gè)程序員不愛呢?那么既然愛站故,請(qǐng)深愛皆怕!將遠(yuǎn)程數(shù)據(jù)庫(kù)連接配好毅舆,這里不再贅述西篓。
②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
這里要注意的是,打包方式j(luò)ar,不再是war
jar
自定義打包名稱
helloworldorg.springframework.bootspring-boot-maven-pluginspring-milestonehttp://repo.spring.io/libs-release
3.實(shí)現(xiàn)方案
①開始打jar包
跟前篇步驟一樣憋活,點(diǎn)開右邊的Maven Project岂津,點(diǎn)擊Lifecycle,最后雙擊packet,生成jar包
②將剛打的jar上傳至云服務(wù)器的java目錄下
③運(yùn)行命令:java -jar helloworld.jar,然后springboot工程的內(nèi)置tomcat就開啟了
訪問(wèn)效果:
這里還沒完呢,當(dāng)然你關(guān)閉當(dāng)前的xshell 命令界面時(shí)悦即,再次訪問(wèn)就失效了吮成,這是因?yàn)閟pringboot內(nèi)置的tomcat隨之也關(guān)閉了,那么有人會(huì)問(wèn)辜梳,這叫什么云部署呀粱甫?跟本地沒兩樣,是啊作瞄,我也這么覺得茶宵;別急,往下看
④常駐云服務(wù)器
運(yùn)行命令: nohup java -jar helloworld.jar &
nohup的意思不掛服務(wù)宗挥,常駐的意思乌庶,除非云服務(wù)器重啟,那就沒法了契耿;最后一個(gè)&表示執(zhí)行命令后要生成日志文件nohup.out
好了瞒大,這樣就不擔(dān)心關(guān)閉xshell,只要云服務(wù)器不關(guān)閉,總能訪問(wèn)的搪桂。
我是張星透敌,歡迎加入博主技術(shù)交流群,群號(hào):313145288
csdn博客鏈接:http://blog.csdn.net/zhangxing52077/article/details/73008359