Maven项目Spring Boot启动

1. pom.xml中增加配置

    
        org.springframework.boot
        spring-boot-starter-parent
        2.0.0.RELEASE
    

    
        
            org.springframework.boot
            spring-boot-starter-web
        
    

2. 创建启动类

创建package learningops.urlshortener

package learningops.urlshortener;

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

/**
 * @author learningops
 * @date 01/03/2018
 */
@SpringBootApplication
@ComponentScan
public class Application implements CommandLineRunner {
    @Override
    public void run(String... args) throws Exception {
    }

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

3. 创建Controller

创建一个package learningops.urlshortener.controller

package learningops.urlshortener.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @author learningops
 * @date 22/03/2018
 */
@Controller
public class IndexController {

    @RequestMapping("/")
    @ResponseBody
    String home() {
        return "Hello World!";
    }
}

4. 运行

mvn spring-boot:run

你可能感兴趣的:(Maven项目Spring Boot启动)