SpringBoot 启动的三种方式

一、SpringBoot启动方式1 

只能将本服务(本controller启动)

Springboot默认端口号为8080

@RestController

@EnableAutoConfiguration

public class HelloController {

    @RequestMapping("/hello")

    public String index() {

    return "Hello World";

 }

    public static void main(String[] args) {

    SpringApplication.run(HelloController.class, args);

    }

}

启动主程序,打开浏览器访问http://localhost:8080/index,可以看到页面输出Hello World

2.8SpringBoot启动方式2

常规的做法

@ComponentScan(basePackages = "com.controller")---控制器扫包范围

@ComponentScan(basePackages = "com.itmayiedu.controller")

@EnableAutoConfiguration

public class App {

    public static void main(String[] args) {

        SpringApplication.run(App.class, args);

    }

}


猜你喜欢

转载自blog.csdn.net/fwk19840301/article/details/79368446