标签:autoconf figure map bsp hello contex public back nbsp
SpringBoot第一种启动方式
import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; @RestController //@RestController 修饰的类下所有方法,全部都是返回json格式,这样就不用再方法上加@ResponseBody @EnableAutoConfiguration //@EnableAutoConfiguration 开启自动配置 装配到spring容器中 public class IndexController { @RequestMapping("/demo") public String index(){ return "hello word"; } public static void main(String[] args) { //程序入口,启动类 SpringApplication.run(IndexController.class,args); } }
SpringBoot第二种启动方式
import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.context.annotation.ComponentScan; @ComponentScan("com.example.demo.controller")//扫描包 @EnableAutoConfiguration public class App { public static void main(String[] args) { SpringApplication.run(App.class,args); } }
SpringBoot第三种启动方式
import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication//扫包范围当前包下的所有子包 //@SpringBootApplication 等同于@ComponentScan("com.example.demo.controller")//扫描包 和@EnableAutoConfiguration public class Application { public static void main(String[] args) { SpringApplication.run(Application.class,args); } }
标签:autoconf figure map bsp hello contex public back nbsp
原文地址:https://www.cnblogs.com/smiledGo/p/10853162.html