首页 > 编程语言 > 详细

springBoot---ComponentScan扫包

时间:2021-01-04 11:47:05      阅读:43      评论:0      收藏:0      [点我收藏+]

1.先新增一个接口类

package demo.controller;


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


@Controller
@EnableAutoConfiguration

public class springHello {
@RequestMapping("/getUser")
@ResponseBody
String home() {
return "Hello World! 我是一个大帅哥,我是大飞哥";
}
}

技术分享图片

 

 

2.新增扫包范围

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@EnableAutoConfiguration //开启自动配置
@ComponentScan("demo.controller")
public class DemoApplication {

@RequestMapping("/getName")
String home() {
return "Hello World! 我是一个大帅哥";
}

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

技术分享图片

 

 

3.实际结果

技术分享图片

 

 技术分享图片

 

springBoot---ComponentScan扫包

原文:https://www.cnblogs.com/wendy-0901/p/14228769.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!