「Spring Boot」ポート番号を変更して画面を表示する

2021年9月27日

1.コントローラ側

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
package com.example.demo;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
//アノテーションRestController
@RestController
public class Sample {
//アノテーションGetMappingの使用
@GetMapping("/cft")
public String getMsg() {
return "study skill and become smart";
}
}
package com.example.demo; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RestController; //アノテーションRestController @RestController public class Sample { //アノテーションGetMappingの使用 @GetMapping("/cft") public String getMsg() { return "study skill and become smart"; } }
package com.example.demo;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

//アノテーションRestController
@RestController
public class Sample {
      
      //アノテーションGetMappingの使用
      @GetMapping("/cft")
      public String getMsg() {
            
            return "study skill and become smart";
      }

}

2.ポート番号を変更

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
application.properties
server.port =8788
application.properties server.port =8788
application.properties
server.port =8788

3.pom.xmlに依存関係ライブラリを追加
20~24行目 追記

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional>
</dependency>
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-devtools</artifactId> <optional>true</optional> </dependency>
<dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-devtools</artifactId>
      <optional>true</optional>
</dependency>

4.動作確認
(1).プロジェクトを右クリックする
(2).「実行(R)」->[Spring Boot アプリケーション]をクリックする
(3).URLを入力して実行する
http://127.0.0.1:8788/cft

結果
study skill and become smart

Spring Boot

Posted by arkgame