Spring-boot学习笔记(1)创建与配置

Spring-boot学习笔记(1)创建与配置,第1张

Spring-boot学习笔记(1)创建与配置
@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
        

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/zaji/5693018.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-12-17
下一篇2022-12-17

发表评论

登录后才能评论

评论列表(0条)

    保存