Hello World với Spring Boot
Trong phần hướng dẫn này sẽ hướng dẫn các bạn tạo ứng dụng Spring boot đơn giản để hiển thị ra dòng chữ:Hello World!
Các bước thực hiện
Bước1:Truy cập vào:https://start.spring io
Tạo ứng dụng spring boot với thông số sau
Bước2:Mở IntellJ Idea.
Mở project vừa tạo và tổ chức lại thư mục dự án như sau:
Bước3:Cài đặt GreetingController
package com.codelean.controller;
import org.springframework.web.bind.annotation RequestMapping;
import org.springframework.web.bind.annotation RestController;
@RestController
public class GreetingController{
@RequestMapping(value="/home")
public String greeting(){
return"Hello World!";
}
}
Bước4:Điều chỉnh lại file GreetingSpringbootApplication
package com.codelean.app;
import org.springframework.boot Spring Application;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;
@SpringBootApplication
@ComponentScan("com.techmely")
public class GreetingSpringbootApplication{
public static void main(String[]args){
SpringApplication.run(GreetingSpringbootApplication.class,args);
}
}
Bước5:Cấu hình và chạy ứng dụng http://localhost:8080/home