如何在伺服器上啟動spring
❶ linux閮ㄧ講鏈嶅姟鍣╨inux閮ㄧ講鏈嶅姟
linux鎬庝箞閮ㄧ講springboot錛
Linux閮ㄧ講springboot欏圭洰錛屼袱縐嶆柟寮
閮ㄧ講jar鍖咃紙瀹樻柟鎺ㄨ崘錛
鍦╨inux鏈嶅姟鍣ㄤ笂榪愯孞ar鏂囦歡鏃墮氬父鐨勬柟娉曟槸錛
$java-jartest.jar
榪欑嶆柟寮忕壒鐐規槸ssh紿楀彛鍏抽棴鏃訛紝紼嬪簭涓姝㈣繍琛.鎴栬呮槸榪愯屾椂娌℃硶鍒囧嚭鍘繪墽琛屽叾浠栦換鍔★紝鏈夋病鏈夊姙娉曡㎎ar鍦ㄥ悗鍙拌繍琛屽憿錛
鏂規硶涓錛
$nohupjava-jartest.jar
//nohup鎰忔濇槸涓嶆寕鏂榪愯屽懡浠,褰撹處鎴烽鍑烘垨緇堢鍏抽棴鏃,紼嬪簭浠嶇劧榪愯
//褰撶敤nohup鍛戒護鎵ц屼綔涓氭椂錛岀己鐪佹儏鍐典笅璇ヤ綔涓氱殑鎵鏈夎緭鍑鴻閲嶅畾鍚戝埌nohup.out鐨勬枃浠朵腑
//闄ら潪鍙﹀栨寚瀹氫簡杈撳嚭鏂囦歡銆
鏂規硶浜岋細
$nohupjava-jartest.jar>temp.txt
//榪欑嶆柟娉曚細鎶婃棩蹇楁枃浠惰緭鍏ュ埌浣犳寚瀹氱殑鏂囦歡涓錛屾病鏈夊垯浼氳嚜鍔ㄥ壋寤
jobs鍛戒護鍜宖g鍛戒護錛
$jobs
//閭d箞灝變細鍒楀嚭鎵鏈夊悗鍙版墽琛岀殑浣滀笟錛屽苟涓旀瘡涓浣滀笟鍓嶉潰閮芥湁涓緙栧彿銆
//濡傛灉鎯沖皢鏌愪釜浣滀笟璋冨洖鍓嶅彴鎺у埗錛屽彧闇瑕乫g+緙栧彿鍗沖彲銆
$fg2
鏌ョ湅鏌愮鍙e崰鐢ㄧ殑綰跨▼鐨刾id
netstat-nlp|grep:8080
鏈嶅姟鍣ㄩ泦緹ゆ庝箞鎼寤猴紵Linux騫沖彴鐨勶紵
linux鏈嶅姟鍣ㄩ泦緹ゅ鉤鍙扮殑鎼寤烘瘮杈冪畝鍗曪紝鏈変笓闂ㄧ殑鍧囪杞浠訛紝姣斿俵vs錛宭vs鏄涓涓闆嗙兢緋葷粺錛岀敱寰堝氭湇鍔″櫒緇勬垚錛屽彲浠ユ牴鎹闇瑕侊紝鎶婂畠闂ㄥ垎涓轟笁灞傦紝涓灞傛槸鍓嶇鏈猴紝鐢ㄤ簬鍧囪錛岀浉褰撲簬鍏騫充負緋葷粺鍒嗛厤宸ヤ綔錛屼簩灞傛槸鏈嶅姟鍣ㄧ兢錛屾瘮濡倃eb鏈嶅姟鍣ㄧ兢錛孌NS錛宮ail緹ょ瓑錛岃繖浜涘氨鏄鎺ュ緟鍛橈紝鎶婂潎琛″櫒鍒嗛厤鐨勫伐浣滆繘琛屽勭悊錛岀涓夊眰鏄瀛樺偍璁懼囷紝鐢ㄤ簬瀛樺偍鏁版嵁錛岀浉褰撲簬妗f堝簱銆傜煡閬撹繖浜涘悗錛岃佹惌寤哄氨闈炲父瀹規槗錛屾湁鐜版垚鐨勮蔣浠訛紝姣斿傛垜鏈夊洓鍙皐eb鏈嶅姟鍣錛2鍙版暟鎹搴擄紝1鍙板墠緗鏈猴紝瀹夎卨inux緋葷粺錛屽畨瑁卨vs杞浠訛紝姣斿俬eartbeat-2.1.4-9.el5.i386.rpmheartbeat-ldirectord-2.1.4-9.el5.i386.rpmlibnet-1.1.4-3.el5.i386.rpmheartbeat-devel-2.1.4-9.el5.i386.rpmheartbeat-pils-2.1.4-10.el5.i386.rpmperl-MailTools-1.77-1.el5.noarch.rpmheartbeat-gui-2.1.4-9.el5.i386.rpmheartbeat-stonith-2.1.4-10.el5.i386.rpm褰撶劧榪橀渶瑕侀厤緗錛屼綘鍙浠ヨ嚜宸辯櫨搴︽湁鍏砽vs闆嗙兢鐨勮︾粏瀹夎呰存槑銆傚笇鏈涜兘甯鍔╀綘銆
涓姝ヤ竴姝ユ暀浣犳灦鏋刲inux鏈嶅姟鍣錛
Linux鏈嶅姟鍣ㄧ殑閮ㄧ講錛岄厤緗錛屾惌寤烘ラわ細
1.鍑嗗囷細
1.1.jdk1.8錛歫dk-8u11-linux-x64.tar.gz銆
tomcat錛歛pache-tomcat-8.0.39-windows-x64.zip銆
1.2.鍏堝畨瑁呬釜1.8鐨刯dk錛屾敞鎰忔槸linuxforjdk錛岃佷笉鐒跺彲涓嶈屻
鐒跺悗鏂板緩涓涓猨ava鏂囦歡澶瑰湪鏍圭洰褰曠殑錛堣繖閲岀殑鏍圭洰褰曡侀氳繃cd鍐嶆帴/usr/榪涘叆錛岃屼笉鏄痟ome/xxx錛屽彲浠ラ氳繃pwd鏌ョ湅褰撳墠鎵鍦ㄨ礬寰勶級/usr/涓嬶紝鐢ㄦ潵鏀劇疆瑙e帇鍚庣殑jdk鏂囦歡錛岃繖閲屽洜涓哄悗緙鍚嶆槸tar.gz鎵浠ョ洿鎺ョ敤tar-xf鍛戒護瑙e帇銆
2.閰嶇疆錛
2.1.閰嶇疆JDK鐨勭幆澧冨彉閲忥細鍒/etc/鏂囦歡澶規壘鍒皃rofile鏂囦歡錛岄氳繃鏂囦歡緙栬緫鍛戒護viprofile鍦ㄦ枃浠剁殑鏈灝懼姞涓婂彉閲忓弬鏁幫細
JAVA_HOME=/usr/java/jdk1.8.0_11
PATH=$JAVA_HOME/bin:$PATH
CLASSPATH=.:$JAVA_HOME/jre/lib/rt.jar:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
2.2.鎶婁笅濂界殑tomcat瑙e帇鍒拌嚜瀹氫箟鐨勪竴涓鏂囦歡澶歸噷浜嗭紝鎴戠殑鏄痟ome/pengyy/tomcat/涓嬶紝鍒癱onfig鏂囦歡閲屼慨鏀逛竴涓嬬鍙e彿,vi鍛戒護緙栬緫server.xml錛岄噷闈㈠悗鏉ュ惎鍔ㄧ殑鏃跺8005閭d釜絝鍙f湁鍐茬獊錛屾垜鐩存帴鏀逛簡8088錛岀劧鍚庡張鎶奾ttp璇鋒眰鐨勭鍙f敼鎴愪簡8001錛孫K錛宼omcat閰嶇疆瀹屾垚錛屾病浠涔堣繃澶氱殑姝ラゃ
2.3.灝嗕竴涓瀹屾垚鐨剋eb欏圭洰鎵撴垚war鍖咃紝鏀懼湪tomcat涓嬬殑webapps閲岃В鍘嬨
2.4.榪涘叆鍒皌omcat涓嬬殑bin鐩褰曪紝杈撳叆鍛戒護鍚鍔錛./start.sh錛岀粓姝㈠懡浠./shutdown.sh銆
鍙浠ユ煡鐪嬫棩蹇楋紝鍘籺omcat鐨刲ogs鐩褰曞簳涓嬫煡鐪媍atalina.out鏃ュ織鏂囦歡錛屽彲浠ラ氳繃cat鏌ョ湅鏂囦歡鍛戒護錛屼篃鍙浠tail-f(鍊掓暟澶氬皯琛屽彲浠ヤ負鏁板瓧)catalina.out鏉ユ煡鐪嬨
濡傛灉絝鍙e彿琚鍗犵敤錛屽彲浠ョ敤鍛戒護lsof-i:絝鍙e彿鏉ユ煡鐪嬬鍙e彿琚鍗犵敤鐨勮繘紼嬪彿錛屾垨鑰呭仠姝㈣ヨ繘紼嬶紝鎴栬呬慨鏀箃omcat鐨勭鍙e彿閮藉彲浠ャ
鑰屽綋浣犱笉紜瀹氭槸鍚︾粓姝浜嗗摢涓欏圭洰鐨勬椂鍊欙紝鍙浠ラ氳繃杈撳叆鍛戒護ps-ef|grepjava鏉ユ煡鐪嬩竴涓嬫槸鍚︽湁鍦ㄨ繍琛岀殑欏圭洰錛岄氳繃kill-9榪涚▼鍙峰氨鍙浠ュ共鎺夊摢涓姝e湪榪愯岀殑欏圭洰浜嗐
鏈鍚庨氳繃ifconfig鎴栬卛p鍛戒護鑾峰彇鉶氭嫙鏈虹殑Ip鍦板潃錛屽湪涓繪満涓婇氳繃ip+絝鍙e彿+欏圭洰鏍硅礬寰勭殑鏂瑰紡璁塊棶鍗沖彲銆
linux鎬庝箞鎼寤簑eb鏈嶅姟鍣錛
web鏈嶅姟鍣ㄧ殑綆鍗曟惌寤1銆佸畨瑁呬竴涓鍙浠ユ彁渚泈eb鏈嶅姟鐨勮蔣浠秠um-yinstallhttpd2銆佸惎鍔╤ttpd鏈嶅姟systemctlstarthttpd3銆佽繘鍏ヤ富閰嶇疆鏂囦歡vim/etc/httpd/conf/httpd.conf鍦ㄦよ寖鍥村唴娣誨姞鎴栧垹闄よ劇疆錛屼負浜嗘柟渚跨紪鍐欙紝緙栬緫浜嗕竴涓瀛愰厤緗鏂囦歡/etc/httpd/conf.d/httpd-vhosts.conf4銆佺紪杈戝瓙閰嶇疆鏂囦歡vim/etc/httpd/conf.d/httpd-vhosts.conf姝よ礬寰勫繀涓篶onf.d/*.conf(鎰忥細涓.conf鍚庣紑鍛藉悕)systemctlrestarthttpd閲嶅惎鏈嶅姟5銆佺紪杈戦〉闈㈡祴璇曟枃浠跺湪web鏈嶅姟涓榛樿ゅ瓨鏀劇綉欏墊枃浠剁殑璺寰勶細/var/chaodiquan.com/html榛樿ょ綉欏墊枃浠跺悕瀛楋細index.html6銆佹祻瑙堝櫒嫻嬭瘯ifconfigens33鏌ョ湅ens33緗戝崱鐨勫湴鍧鍦ㄦ祻瑙堝櫒閲岄潰杈撳叆浣犵殑IP灝卞彲浠ョ湅鍒版祴璇曟枃浠墮噷甯屾湜鍙浠ュ府鍔╁埌鐨勫搱錛
❷ 榪愯宻pringboot鏈夊摢鍑犵
閰嶇疆bean鐨勬簮錛屽氨鏄痓ean鐨勬潵婧愶紝灝辨槸娉ㄨВ浜哠pringBootApplication鐨勯偅涓綾匯傛帹鏂錛屾帹鏂搴旂敤綾誨瀷錛屾湁webflux錛寃ebservlet錛宯one鎺ㄦ柇涓葷被錛岃繖涓鏄閫氳繃綰跨▼鍫嗘爤瀹炵幇錛屾瀯閫犱竴涓榪愯屾椂寮傚父錛屾壘寮傚父鍫嗘爤閲岄潰鎵緈ian鎵鍦ㄧ殑閭d釜綾匯
緗戜笂澶у氭暟鐨勮В鍐蟲柟妗堟槸閫氳繃娣誨姞spring-boot-starter-tomcat渚濊禆鏉ヨВ鍐籌紝浣嗗疄嫻嬭瘉鏄庢ゆ柟娉曚笉鍙琛屻
棣栧厛璐翠竴寮犲緢涓嶉敊鐨勫浘錛孲pringBoot鍚鍔ㄧ粨鏋勫浘錛屽浘鐗囧嚭鑷猄pringBoot鍚鍔ㄦ祦紼嬭В鏋愩傛湰鏂囩殑鍒嗘瀽鍩轟簬SpringBoot5錛岄潪Spring鐨勪唬鐮佸彧鏈変笅闈㈣繖涓鍚銆傛彁渚涘ぇ閲忎紭縐鐨刉eb妗嗘灦鏂逛究寮鍙戠瓑絳夈
鍦ㄤ簡瑙SpringBoot鐨勫惎鍔ㄦ祦紼嬬殑鏃跺欙紝鎴戜滑鍏堢湅涓涓嬩竴涓猄pringBoot搴旂敤鏄濡備綍鍚鍔ㄧ殑錛屽備笅鏄涓涓綆鍗曠殑SpringBoot紼嬪簭錛岄潪甯哥殑綆媧侊紝浠栨槸濡備綍鍋氬埌鐨勫憿錛屾垜浠鎺ヤ笅鏉ュ氨灝嗕竴姝ユュ垎瑙c
鎵ц屾牳蹇價un鏂規硶鍒濆嬪寲initialize鏂規硶鎵ц屽畬涔嬪悗錛屼細璋冪敤run鏂規硶錛屽紑濮嬪惎鍔⊿pringBoot銆
SpringBoot鐨勫惎鍔ㄤ富瑕佹槸閫氳繃瀹炰緥鍖朣pringApplication鏉ュ惎鍔ㄧ殑銆
鍦ㄤ簡瑙SpringBoot鐨勫惎鍔ㄦ祦紼嬬殑鏃跺欙紝鎴戜滑鍏堢湅涓涓嬩竴涓猄pringBoot搴旂敤鏄濡備綍鍚鍔ㄧ殑錛屽備笅鏄涓涓綆鍗曠殑SpringBoot紼嬪簭錛岄潪甯哥殑綆媧侊紝浠栨槸濡備綍鍋氬埌鐨勫憿錛屾垜浠鎺ヤ笅鏉ュ氨灝嗕竴姝ユュ垎瑙c
SpringBoot鍦ㄥ惎鍔ㄦ椂錛岄氳繃.postProcessBeanFactory瀹屾垚瀵逛緷璧杍ar鍖呬腑XxAutopConfiguration綾葷殑娉ㄥ唽錛岃嚜鐒禗ubboAutoConfiguration涔熶細琚娉ㄥ唽鍒板瑰櫒鍐呴儴銆
1銆佷互涓嬩袱縐嶆柟寮忔槸灝嗚ラ厤緗鏂囦歡鎵撳寘鍦╦ar鍖呴噷闈浜嗭紝鍗充究鍙鏀逛竴涓絝鍙e彿錛屽紑鍙戜漢鍛樺厛鏀歸厤緗鏂囦歡錛屽啀鎵撳寘錛屽啀榪愯屻傛ゅ勪篃璁板綍涓嬶紝騫惰В寮jar鍖咃紝鐪嬩笅璇ラ厤緗鏂囦歡琚鎵撳寘鍚庯紝鏀劇疆鐨勪綅緗銆
2銆丼pringBoot涓鐨勯厤緗鏂囦歡涓昏佹湁涓夌嶆牸寮忥紝properties銆亂aml銆佸拰xml鏂瑰紡銆
3銆佸傛灉瀛樺湪澧炲姞浜嗛厤緗鏂囦歡鎴栬呭湪閰嶇疆鏂囦歡閲岄潰澧炲姞浜嗗睘鎬у嵈娌℃湁鐢熸晥錛屽彲浠ュ弬鑰冧笂闈㈢殑springboot閰嶇疆鏂囦歡琛ㄨ揪寮忓拰閰嶇疆鏂囦歡鐢熸晥欏哄簭榪涜屾帓鏌ャ傚悗闈㈣繕浼氭湁涓綃囨枃絝犺ㄨ哄熀浜巗pringboot閰嶇疆鍘熺悊濡備綍瀹炵幇鑷瀹氫箟鐨勯厤緗璇誨彇鏂瑰紡銆
4銆侀」鐩錛岄渶瑕佽塊棶澶氫釜鏁版嵁搴擄紝鑰屼笖闇瑕佸湪鏈嶅姟鍣ㄨ繍琛屼笉閲嶆柊鍚鍔ㄧ殑鎯呭喌涓嬶紝鍔ㄦ佺殑淇鏀箂pring涓閰嶇疆鐨勬暟鎹婧恉atasource錛屽湪緗戜笂鎵句簡寰堝氳祫鏂欙紝鏈鍚庢壘鍒頒簡閫傚悎鎴戠殑鏂規硶錛屼笅闈㈡葷粨涓涓嬨
5銆佷互涓婂氨鏄鏆傛椂瀵箂pringboot姣旇緝嫻呯殑鐞嗚В錛屽緟鍚庣畫娣卞叆銆
鍒濆嬪寲initialize鏂規硶鎵ц屽畬涔嬪悗錛屼細璋冪敤run鏂規硶錛屽紑濮嬪惎鍔⊿pringBoot銆傞栧厛閬嶅巻鎵ц屾墍鏈夐氳繃SpringFactoriesLoader錛屽湪褰撳墠classpath涓嬬殑META-INF/spring.factories涓鏌ユ壘鎵鏈夊彲鐢ㄧ殑SpringApplicationRunListeners騫跺疄渚嬪寲銆
SpringBootx鍙鍖哄垎web鐜澧冨拰闈瀢eb鐜澧冿紝鑰屽湪x鐗堟湰涓寮曞叆浜哛eactive鐜澧冿紝鍗沖搷搴斿紡鐜澧.閭d箞鐜板湪SpringBoot鏀鎸佷笁縐嶇幆澧冿細Servlet鐨剋eb鐜澧冦丷eactive鐨剋eb鐜澧冧互鍙婇潪web鐜澧冦
棣栧厛璐翠竴寮犲緢涓嶉敊鐨勫浘錛孲pringBoot鍚鍔ㄧ粨鏋勫浘錛屽浘鐗囧嚭鑷猄pringBoot鍚鍔ㄦ祦紼嬭В鏋愩傛湰鏂囩殑鍒嗘瀽鍩轟簬SpringBoot5錛岄潪Spring鐨勪唬鐮佸彧鏈変笅闈㈣繖涓鍚銆傛彁渚涘ぇ閲忎紭縐鐨刉eb妗嗘灦鏂逛究寮鍙戠瓑絳夈
springboot鍚鍔ㄦ祦紼嬪備笅錛氬惎鍔ㄦ祦紼嬩富瑕佸垎涓轟笁涓閮ㄥ垎錛岀涓閮ㄥ垎榪涜屻丼pringApplication鐨勫垵濮嬪寲妯″潡錛岄厤緗涓浜涘熀鏈鐨勭幆澧冨彉閲忋佽祫婧愩佹瀯閫犲櫒銆佺洃鍚鍣錛岀浜岄儴鍒嗗疄鐜頒簡搴旂敤鍏蜂綋鐨勫惎鍔ㄦ柟妗堬紝鍖呮嫭鍚鍔ㄦ祦紼嬬殑鐩戝惉妯″潡銆佸姞杞介厤緗鐜澧冩ā鍧椼
鍚鍔錛氭瘡涓猄pringBoot紼嬪簭閮芥湁涓涓涓誨叆鍙o紝涔熷氨鏄痬ain鏂規硶錛宮ain閲岄潰璋冪敤SpringApplication.run()鍚鍔ㄦ暣涓猻pring-boot紼嬪簭錛岃ユ柟娉曟墍鍦ㄧ被闇瑕佷嬌鐢ˊSpringBootApplication娉ㄨВ銆
❸ Web鏈嶅姟鍣ㄣ乄eb瀹瑰櫒銆丼ervlet瀹瑰櫒銆丼pring瀹瑰櫒銆丼pringMVC瀹瑰櫒
鎻縐榃eb鏋舵瀯鐨勬牳蹇冪粍浠
鍦ㄦ瀯寤虹幇浠Web搴旂敤鐨勮繃紼嬩腑錛屾湇鍔″櫒銆佸瑰櫒鍜屾嗘灦鎵婕旂潃鑷沖叧閲嶈佺殑瑙掕壊銆傝╂垜浠娣卞叆浜嗚В榪欎簺鍏抽敭緇勪歡錛
- Web鏈嶅姟鍣: 浣滀負搴旂敤鐨勫熀鐭籌紝Web鏈嶅姟鍣ㄥ侫pache銆両IS鍜孴omcat錛屽畠浠澶勭悊HTTP璇鋒眰錛屾棤璁烘槸闈欐佽祫婧愯繕鏄鍔ㄦ佹湇鍔°傚畠浠璐熻矗鍩烘湰鐨勮鋒眰澶勭悊錛屼笌Web瀹瑰櫒鐨勫叧緋繪湁鏃朵細琚娣鋒穯錛屼絾涓昏佽亴璐e湪浜庡熀紜閫氫俊銆
- Web瀹瑰櫒: 浣滀負鏈嶅姟鍣ㄧ殑鎵╁睍錛學eb瀹瑰櫒濡俆omcat錛堟洿鍏蜂綋鍦拌存槸Servlet瀹瑰櫒錛変笓闂ㄨ礋璐e姩鎬佸唴瀹圭殑澶勭悊銆傚畠浠綆$悊Servlet錛堝俤oGet/doPost錛夊拰鐩稿叧緇勪歡錛屽侺isteners鍜孎ilters錛屼絾涓嶅寘鎷浠呭勭悊闈欐佸唴瀹圭殑鏈嶅姟鍣ㄣ
- Servlet瀹瑰櫒: 浣滀負Web瀹瑰櫒鐨勬牳蹇冿紝濡俆omcat錛屾槸Servlet鍔熻兘鐨勭劍鐐廣傚畠璐熻矗Servlet鐨勭敓鍛藉懆鏈熺$悊錛屽寘鎷鍔犺澆銆佸垵濮嬪寲鍜岃祫婧愮$悊錛屼互鍙婄嚎紼嬪畨鍏ㄩ棶棰樼殑澶勭悊銆
Servlet鏄疛ava緙栫▼鐨勭伒欖傦紝瀹冧滑璐熻矗鍝嶅簲瀹㈡埛絝璇鋒眰錛屽傝〃鍗曟暟鎹澶勭悊鍜岀姸鎬佺$悊錛岄氳繃鏍稿績鎺ュ彛javax.servlet.Servlet瀹炵幇銆傚伐浣滄祦紼嬶細瀹㈡埛絝璇鋒眰鈫扴ervlet瀹瑰櫒鈫掓湇鍔″櫒澶勭悊鈫掕繑鍥炵粨鏋溿
闅忕潃鎶鏈榪涙ワ紝濡侸SP鍜孲pringMVC鐨勫嚭鐜幫紝Servlet鐨勮掕壊鏈夋墍婕斿彉錛屼絾鏍稿績緇勪歡涔嬮棿鐨勭晫闄愪緷鐒舵竻鏅般
鍦ㄥ瑰櫒綆$悊涓錛學eb瀹瑰櫒緇存姢Listeners鍜孎ilters錛孲ervlet瀹瑰櫒璐熻矗Servlet錛孲pring綆$悊涓氬姟閫昏緫灞傦紙Service鍜孌ao錛夛紝SpringMVC璐熻矗鎺у埗灞傦紙Controller錛夊拰瑙嗗浘瑙f瀽錛岃孲pring Boot鍒欑粺涓綆$悊鎵鏈塀ean銆傛棭鏈熺殑Spring妗嗘灦閲囩敤鍒嗗眰璁捐★紝渚誇簬妗嗘灦鍒囨崲銆
- Spring+SpringMVC欏圭洰緇撴瀯
- 灝界Service鍜孌ao鍦⊿pring瀹瑰櫒涓錛孋ontroller鍗磋兘娉ㄥ叆瀹冧滑錛岃繖鏄瘲pringMVC欏圭洰鐙鏈夌殑鐗規с
- SpringMVC鏋舵瀯涓錛屾垜浠鏈変笁灞傚瑰櫒錛歐eb瀹瑰櫒銆丼ervlet瀹瑰櫒錛圶mlWebApplicationContext錛屼笌servletContext鍜宻pringMVC.xml鍏寵仈錛夊拰SpringMVC瀹瑰櫒錛堟帶鍒惰嗗浘瑙f瀽鍣ㄥ拰Controller錛夈
- 鍦⊿pring+Mybatis欏圭洰涓錛岄櫎浜嗕笂榪板瑰櫒錛孲pring瀹瑰櫒榪樻槸鍏朵粬瀹瑰櫒鐨勭埗瀹瑰櫒銆
鐗瑰埆瑕佹敞鎰忕殑鏄錛孲pring Boot綆鍖栦簡瀹瑰櫒鐨勬傚康錛屼笉鍐嶅尯鍒嗙埗瀛愬瑰櫒錛屼簨鍔$$悊鍣ㄧ粺涓鐢盨pring瀹瑰櫒澶勭悊錛孋ontroller涓嶅啀閰嶇疆浜嬪姟銆係pringMVC瀹瑰櫒鏄疿mlWebApplicationContext錛屽叾鏍稿績灞炴у俤ispatcherServlet錛屼笌Spring瀹瑰櫒淇濇寔鍏寵仈銆
瀹瑰櫒鐨勫壋寤鴻繃紼嬫槸鏈嶅姟鍣ㄥ惎鍔ㄦ椂鐨勫垵濮嬪寲姝ラわ紝姣斿俆omcat鍚鍔ㄦ椂錛屼細鍚屾椂鍒涘緩Spring鍜孲pringMVC鐨勫瑰櫒瀹炰緥銆係pring Boot欏圭洰涓錛學eb鏈嶅姟鍣ㄤ笌Spring瀹瑰櫒錛圵ebApplicationContext錛夊拰SpringBoot瀹瑰櫒錛圓錛夌揣瀵嗙浉榪烇紝鍚庤呬笉鍐嶆湁parent瀹瑰櫒鐨勬傚康錛屽睍紺轟簡鎶鏈婕旇繘甯︽潵鐨勭畝鍖栧拰楂樻晥銆
閫氳繃榪欎釜璇︾粏鐨勫墫鏋愶紝鎴戜滑鏇村ソ鍦扮悊瑙d簡榪欎簺鍏抽敭緇勪歡濡備綍鍗忎綔錛屼負鏋勫緩楂樻晥銆佺伒媧葷殑Web搴旂敤鎻愪緵浜嗗潥瀹炵殑鏋舵瀯鍩虹煶銆
❹ SpringBoot項目使用war包部署至雲伺服器(Linux+Tomcat)
一、項目打包:
1.更改項目的啟動方式
使用web.xml運行應用程序,指向Application,最後啟動springboot(繼承SpringBootServletInitialier,重寫函數)
public class WarStartApplication extends SpringBootServletInitializer {
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
return builder.sources(Application.class);
}
}
2.更改.properties配置信息
修改相關的地址和配置信息
PS: 可採用STS自帶的動態配置系統(多配置文件)進行開發環境和生產環境的隔離。
3.更改api介面層配置文件(pom.xml)
1)進行war包配置
<packaging>war</packaging>
2)war包打包所需依賴項
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<scope>provided</scope>
</dependency>
4.執行打包操作
1)maven clean清除之前的打包
2)maven install進行打包操作
二、將war包文件上傳至伺服器
1.在api層的target文件夾下找到新生成的項目war包
2.使用rzsz工具上傳war包(rz)
三、使用Tomcat進行項目開放
1.進行 Tomcat的環境部署
2.將war包拷貝到tomcat的webapps文件夾下
3.cd至bin文件夾下(tomcat會自動解壓項目war包並進行項目部署)
使用startup.sh進行tomcat啟動
使用shutdown.sh進行tomcat關閉