Spring Bootは、「構成に関するコンベンション」の概念のスプリングフレームワークのベストプラクティスの製品として、独立した製品レベルのスプリングフレームワークベースのアプリケーションを迅速に作成するのに役立ちます。ほとんどのスプリングブートアプリケーションは、迅速に実行するためにほとんど構成を必要としません。これは、マイクロサービスと非常に一致するマイクロフレームワークです。
1。スプリングブートアプリケーションパッケージ
Spring Bootアプリケーションは、Tomcatが埋め込まれたJARパッケージに入力でき、直接開始できます。ただし、スプリングブートアプリケーションが開始される前に、最初にパッケージが必要です。この記事では、Mavenプロジェクトのパッケージについて説明しています。パッケージングに必要な前提条件(pom.xmlファイルのコンテンツ)は次のとおりです。
... <パッケージ> jar </packaging> ... <dependency> groupid> org.springframework.boot </groupid> <artifactid> spring-boot-starter-web </artifactid> </dependency> <artifactid> spring-boot-maven-plugin </artifactid> <configuration> <mainclass> com。
パッケージコマンドは次のとおりです。
mvn clean package -dmaven.test.skip = true#demo $ mvn clean package -dmaven.test.skip = true [info]プロジェクトのスキャン.. org.springframework.boot:spring-boot-maven-pluginがありません。 @行38、列17 [警告] [警告]建物の安定性を脅かすため、これらの問題を修正することを強くお勧めします。 ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 0.0.1-snapshot [info] -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------実際にフィルタリングされたリソースをコピーするには、IEビルドはプラットフォームに依存します! /users/ltc/spring boot demo/target/classes [info] [info] --- maven-resources-plugin:2.6:testresources(default-testresources) @ myproject - [info] not test resources [info] [info] [info] --- maven-compiler-plugin:3.1:testcompile(default testcompile) @ compile)ソース[情報] [情報] --- Maven-Surefire-Plugin:2.12.4:test(default-test) @ myproject - [info]テストがスキップされます。 Demo/Target/MyProject-0.0.1-Snapshot.jar [info] [info] --- Spring-boot-maven-plugin:1.5.0.rc1:repackage(default) @ myproject --- [info] ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
またはrun run-> maven build ... eclipse、clean package -dmaven.test.skip = true in goal、run、パッケージが完成します。
2。スプリングブートアプリケーションの起動
スプリングブートの開始コマンドは次のとおりです。
Java -jar application.jar#demo $ java -jarターゲット/myproject -0.0.1 -snapshot.jar。 ____ __ _ /// ___'_ __ _ _ _ _ _ _ _ _ __________ ____ _ / / / / /(() / ___ | '_ |' _ | / / / / / / / / / / / / / / / / / / / / | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | .__ | | _ | | _ | | ===============================================================/_/_/_/:: spring boot ::(v1.4.3.Release)2017-01-13 15:31:36.911情報62119 (/users/ltc/spring boot demo/target/myproject-0.0.1-snapshot.jarは、liutianchi in/user/ltc/spring boot demo)2017-01-13 15:31:36.916 Info 62119 --- [Main] com.test.example:アクティブなプロフィールセット、デフォルトのプロフィールに戻る15:31:36.981 INFO 62119 --- [MAIN] ationConfigemdedWebApplicationContext:更新org.springframework.boot.context.embedded.annotationconfigemdedwebapplicationcontext@b1a58a3:startup startupコンテキストのルートHierarchy2017-01-13 15:31:38.602 INFO 62119 - [MAIN] SBCETTOMCATEMBEDDEDSERVLETCONTAINER:ポートで初期化:2017-01-13 15:31:38.615情報62119--- [メイン] o.apache.catalina.core.StandardService:Starting Service Tomcat2017-01-13 15:31:38.616 Info 62119 --- [Main] org.apache.catalina.core.Standardengine:開始サーブレットエンジン:Apache Tomcat/8.5.62017-01-13 15:38:38.718情報[Ost-StartStop-1] Occc [Tomcat]。[localhost]。 15:31:38.718 INFO 62119 --- [OST-STARTSTOP-1] OSWEB.CONTEXT.CONTEXTLOADER:ROOT WEBAPPLICATIONCONTEXT:初期化完了[/] 2017-01-13 15:31:38.932情報62119 --- [OST-StartStop-1] OsbwServlet.FilterRegistrationBean:マッピングフィルター:「MetricsFilter 'to:[/*] 2017-01-13 15:38.932 Info 62119-] OSBWSERVLET.FILTERREGISTRATIONBEAN:マッピングフィルター:[/*] 2017-01-13 15:31:38.932 INFO 62119 - [OSS-STARTSTOP-1] OSBWSERVLET.FILTERREGISSTRATIONBEAN:MAPPING FILTER: 'HIDDEDHTTPMETHETHODFILTTTER' [/*] 15:31:38.932 INFO 62119 --- [OST-STARTSTOP-1] OSBWSERVLET.FILTERREGISTRATIONBEAN:マッピングフィルター:「HiddenHttpMethodFilter 'to:[/*] 2017-01-13 15:31:38.932 Info 62119フィルター: 'httpputformcontentfilter' to:[/*] 2017-01-13 15:31:38.932 Info 62119 --- [OST-StartStop-1] OSBWSERVLET.FILTERREGISTRATIONBEAN:マッピングフィルター: 'RequestContextFilter' to:[/*] [OST-StartStop-1] OSBWSERVLET.FILTERREGISTRATIONBEAN:マッピングフィルター:「WebRequestLoggingFilter 'to:[/*] 2017-01-13 15:31:38.932 INFO 62119 --- [OST-STARTSTOP-1] OSBWSEXTEXTEXTEXTEXTEXTEXTEXT:MAPPING FILD:' MAPPING FILD: [/*] 2017-01-13 15:31:39.217 INFO 62119 --- [Main] SWSMAREQUESTMAPPINGHANDLERADAPTER:@ControllerAdvice:org.springframework.boot.context.embedded.annotationconfigemdeddedwebplicatextext @bib1a58a3: 15:31:36 CST 2017];コンテキストのroot hierarchy2017-01-13 15:31:39.310 Info 62119 - [Main] SWSMAREQUESTMAPPINGHANDLERMAPPING:MAPPED "{[/]}」 swsmarequestmappinghandlermapping:マッピング "{[/error]}" "to public org.springframework.http.responseentity <java.util.map <java.lang.string、java.lang.object >> org.springframework.boot.autoconfigure.web.basicerrorcontroller.error(javax.servlet.http.httpservletrequest)2017-01-13 15:31:39.313 Info 62119-- [メイン] Swsmmarequestmaptmapping:Mapped "{[/error]、produces = [text/html]}" "to public org.springframework.web.servlet.modelandviewへorg.springframework.boot.autoconfigure.web.basicerrorcontroller.errorhtml(javax.servlet.http.httpservletrequest、javax.servlet.http.httpservletresponse) oswshandler.simpleurlhandlermapping:マッピングされたurlパス[/webjars/**]タイプのハンドラーに[クラスorg.springframework.web.servlet.resource.resource.ResourcehttpRequesthandler] 2017-01-13 15:31:39.338情報62119 URL path [/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]2017-01-13 15:31:39.378 INFO 62119 --- [ main] oswshandler.SimpleUrlHandlerMapping : Mapped URL path [/**/favicon.ico] onto handler of type [class org.springframework.web.servlet.resource.resourcehtprequesthandler] 2017-01-13 15:31:39.665 Info 62119 - [Main] Osbaemvc.Endpointhandlermapp:マッピング{[/Manage/metrics/ {name:.*}]、methods =情報62119 --- [Main] OSBAEMVC.ENDPOINTHANDLERMAPPING:マッピング "{[/manage/metrics ||/manage/metrics.json]、methods =、produces =、produces =}" org.springframework.actuate.endpoint.mvc.endpointmvcadapter.invoke()2017-01-13 15:31:39.666 Info 62119 - [Main] Osbaemvc.Endpointhandlermapping:Mapped "{[/managing/mappings || /MANAGE/mappings.json]、methods= [get]、produces = [application/json]} "}" in to public java.lang.object org.springframework.actuate.endpoint.mvc.endpointmvcadapter.invoke() OSBAEMVC.ENDPOINTHANDLERMAPPING:MAPPED "{[/manage/trace ||/manage/trace.json]、methods = org.springframework.actuate.endpoint.mvc.endpointmvcadapter.invoke()2017-01-13 15:31:39.667 Info 62119 --- [Main] Osbaemvc.EndpointhandLermapping:mapped "{[/manage/info || /MANAGE/info.json]、methods = OSBAEMVC.ENDPOINTHANDLERMAPPING:MAPPED "{[/manage/configpropp ||/manage/configprops.json]、methods= org.springframework.boot.actuate.endpoint.mvc.endpointmvcadapter.invoke()2017-01-13 15:31:39.669 Info 62119 - [Main] Osbaemvc.Endpointhandlermapping:Mapped "{[/Heapdump || /MANAGE/heapdump.json]、methods =、produces = [application/octet-stream]} "public voidにorg.springframework.actuate.endpoint.mvc.heapdumpmvendpoint.invoke(boolean、javax.servlet.http.httpservletrequest、javax.servlet.http.httpservletresponse)throws java.io.ioexception、javax.servlet.servlet.servletexception2017-01-13 15:31.669 Info 62119 --- [Main] OSBAEMVC.ENDPOINTHANDLERMAPP:MAPPED "{[/manage/autoconfig || /MANAGE/autoconfig.json]、methods= OSBAEMVC.ENDPOINTHANDLERMAPPING:MAPPED "{[/MANAGE/ENV/ENV/ENV/ {NAME :*}]、METHODS= org.springframework.actuate.endpoint.mvc.environmentmvendpoint.value(java.lang.string)2017-01-13 15:31:39.673 Info 62119 - [main] osbaemvc.endpointhandlermapp:mapped "[/manabe/venv | /manage/env.json]、methods = OSBAEMVC.ENDPOINTHANDLERMAPPING:MAPPED "{[/manage/health ||/manage/health.json]、produces = [application/json]}" "to public java.lang.object org.springframework.actuate.endpoint.mvc.healthmvendpoint.invoke(java.security.principal)2017-01-13 15:31:39.675 Info 62119 - [main] osbaemvc.endpointhandlermapp:mapped " /MANAGE/dump.json]、methods= [get]、produces =、application/json]} "public public Java.lang.object org.springframework.actuate.endpoint.mvc.endpointmvcadapter.invoke()2017-013 15:31:39.677 Info 62119-- OSBAEMVC.ENDPOINTHANDLERMAPPING:MAPPED "{[/manage/shutdown ||/manage/shutdown.json]、metods= [post]}"} "情報62119 - [メイン] OSBAEMVC.ENDPOINTHANDLERMAPPING:マッピング "{[/manage/beans/beans/beans.json]、methods =、produces =、produces =、application/json]}" org.springframework.actuate.endpoint.mvc.endpointmvcadapter.invoke()2017-01-13 15:31:39.799 Info 62119 - [Main] Osjeaannotationmbeanexporter:JMX曝露のために豆を登録するjmx露出ossupport.defaultlifecycleprocessor:フェーズ02017-01-13 15:31:39.944 INFO 62119 - [MAIN] SBCETTOMCATEMBEDEDDEDSERVLETCONTAINER:TomCatがポート(S)で開始された:8080(HTTP) com.test.example:4.292秒で例を開始しました(4.726で実行されています) 3。スプリングブートアプリが閉じます
スプリングブーツを閉じる主な方法は、HTTPを介してシャットダウン信号を送信するか、サービスストップを使用しています。
Spring Bootアプリを閉じるための前提条件は、pom.xmlが次のコンテンツを追加することです。
<Dependency> groupId> org.springframework.boot </groupid> <artifactid> spring-boot-starter-actuator </artifactid> </dependency>
Application.Propertiesに追加:
#enable shutdownendpoints.shutdown.enabled = true#パスワード検証endpoints.shutdown.sensitive = falseを無効にする
終了コマンドは次のとおりです。
curl -x post host:port/shutdown#demo $ curl -x post http:// localhost:8080/shutdown {"message": "shutting、bye ..."} $ curl -x post http:// localhost:8080/manage/shutdown {"メッセージ"パスを構成する場合は、management.context -path =/application.propertiesで管理する必要があります。シャットダウンコマンドはcurl -xポストホスト:ポート/管理/シャットダウンになります。
4。セキュリティ検証
閉じるときにセキュリティ検証が必要な場合は、pom.xmlファイルを追加します。
<Dependency> groupId> org.springframework.boot </groupid> <artifactid> spring-boot-starter-security </artifactid> </dependency>
Application.Propertiesに追加:
#ENABLE SHUTDOWN SECURETIFICITION ENDPOINT.SHUTDOWN.SENSITITY = TRUE#USERNAME SECURETH.USER.USER.NAME = ADMIN#PASSIREN SECURITY.USER.PASSWORD = ADMIN#ROLIS MANAGEMENT.SECURITY.ROLE = SUPERUSER#PORT MANAGEMENT.PORT = 8081#DECIFY ADDRESS MANAGEMENT.ADDRESS = 127.0.0.0.1
終了コマンドは次のとおりです。
curl -u admin:admin -x post http://127.0.0.1:8081/manage/shutdowdodemo $ curl -u admin:admin -x post http://127.0.0.0.1:8081/manage/shutdown(
上記はこの記事のすべての内容です。みんなの学習に役立つことを願っています。誰もがwulin.comをもっとサポートすることを願っています。