springBoot---ComponentScan扫包

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.实际结果

 

 

 

posted @ 2021-01-04 11:14  沫笙*  阅读(249)  评论(0编辑  收藏  举报