1.アイデアを開き、新しいプロジェクトを作成し、SpringIniverizrを選択します
2。アーティファクトを入力します
3. Webを確認してください
4. [完了]をクリックします
5.プロジェクトを入力して、次のコンテンツを削除します
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 <http://www.w3.org/2001 xsi:schemalocation = "http://maven.apache.org/pom/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.0.sdsd"> <modeleversion> 4.0.0 </modelversion> <グループ <version>0.0.1-SNAPSHOT</version> <packaging>jar</packaging> <name>springbootdemo</name> <description>Demo project for Spring Boot</description> <!--Start dependencies--> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <バージョン> 1.5.2.Release </version> <RecationPath/> <! - リポジトリからのlookup parent-> </parent> <properties> <project.build.sourceencoding> utf-8 </project.build.sourceEncoding <Java.version> 1.8 </java.version> </properties> <dependencies> <! - Webプロジェクト関連の依存関係を開発 - > <依存関係> <groupid> org.springframework.boot </groupid> <artifactid> spring-boot-startertarter-web </artifactid> < <groupid> org.springframework.boot </groupid> <artifactid> spring-boot-starter-test </artifactid> <scope>テスト</scope> </dependency> </dependencies> <! <artifactid> spring-boot-maven-plugin </artifactid> </plugin> </plugins> </build> </project>
6. HelloControllerを作成します
パッケージcom.example; org.springframework.web.bind.annotation.requestmappingをインポートします。 org.springframework.web.bind.annotation.restControllerをインポートします。 @RestController Public Class HelloController {@RequestMapping( "/hello")public string hello(){return "hello、これはスプリングブートデモ"; }}7.プログラムによって自動的に生成されたSpringBootDemoApplicationには、@SpringBootApplicationの注釈があります。この注釈は、このクラスがプログラムのエントリであることを示すために使用されます。
パッケージcom.example; Import org.springframework.boot.springApplication; Import org.springframework.boot.autoconfigure.springbootapplication; // entry@springbootApplication public class springbootdemoApplication {public static void main(string [] args){springapplication.run(springbootdemoapplication.class、args); }}@SpringBootApplication SpringのコンポーネントスキャンとSpringbootの自動構成関数を有効にします。これは、次の3つの注釈を組み合わせることに相当します
(1)@configuration:テーブル名このクラスはJavaベースの構成を使用し、このクラスを構成クラスとして使用します
(2)@componentscan:注釈スキャンを有効にします
(3)@enableautoconfiguration:スプリングブートの自動構成関数をオンにします
8。SpringBootDemoApplicationクラスを実行します
テスト:
アドレスバーにhttp:// localhost:8080/helloを入力します
9. JARパッケージを起動する方法の使用を開始します
(1)最初にプロジェクトがあるディレクトリを入力します。 Macシステムの場合は、プロジェクトを右クリックし、Finderで表示を選択し、Windowsシステムを右クリックして、プロジェクトのExplorerで[表示]を選択します。プロジェクトのあるディレクトリを開くことができます。
(2)ターミナルを開き、プロジェクトが配置されているディレクトリを入力します
cd /Users/shanml/IdeaProjects/SpringbootDemo
MVNインストールを入力して、プロジェクトを構築します
(3)構造が成功した後、プロジェクトターゲットフォルダーに追加のJARパッケージがあります。
(4)Java -Jar Springbootdemo-0.0.1-Snapshot.jarを使用します
JARパッケージを起動するだけです
参照:
シニア兄弟リアオ:2時間でスプリングブートを学びます
上記はこの記事のすべての内容です。みんなの学習に役立つことを願っています。誰もがwulin.comをもっとサポートすることを願っています。