
@RestController
@ComponentScan(basePackages = {"example.controller","example.config"})
@EnableAutoConfiguration
public class MainApplication {
// @RequestMapping("/")
// String home() {
// return "Hello World!";
// }
public static void main(String[] args) {
SpringApplication.run(MainApplication.class, args);
}
}
@RestController
@ComponentScan(basePackages = {"example.controller","example.config"})
@EnableAutoConfiguration
等于
@SpringBootApplication
其中ComponentScan()是用来扫描java中的配置configuration与controller中。
在控制器中添加,@RestController,该注解中包含了@Controller和@ResponseBody 在配置器中添加,@Configuration,表示该类为配置类。
引入依赖
org.springframework.boot spring-boot-starter-web
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)