Bài đăng nổi bật

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 Codelean!

Các bước thực hiện


Bước 1: Truy cập vào: https://start.spring.io

Tạo ứng dụng spring boot với thông số sau



Bước 2: Mở IntellJ Idea.
Mở project vừa tạo và tổ chức lại thư mục dự án như sau:




Bước 3: 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 CodeLean!";
    }
}

Bước 4: Điều chỉnh lại file GreetingSpringbootApplication

package com.codelean.app;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;

@SpringBootApplication
@ComponentScan
("com.codelean")
public class GreetingSpringbootApplication {

   
public static void main(String[] args) {
        SpringApplication.run(GreetingSpringbootApplication.
class, args);
    }

}

Lưu ý: Thêm @ComponentScan("com.codelean")

Bước 5: Cấu hình và chạy ứng dụng




CodeLean.vn
Facebook: CodeLean Community 

Post a Comment

Mới hơn Cũ hơn