最近搭建了一个springboot多模块项目:common、model、dao、service、controller
目录结构如下图所示:
application.yml如下:**_
spring:
datasource:
url: jdbc:mysql://localhost:3306/classroom?useUnicode=true&characterEncoding=UTF-8&useSSL=true
username: root
password: root
driver-class-name: com.mysql.jdbc.Driver
**主类WebApplication在WEB模块,代码如下:**
@SpringBootApplication(scanBasePackages = {"cn.zz.dao","cn.zz.web","cn.zz.service"})
public class WebApplication {
public static void main(String[] args) {
System.out.println("start....");
SpringApplication.run(WebApplication.class, args);
}
}
在cn.zz.controller包下面创建了一个TestController用作测试,代码如下:
@RestController
@Slf4j
@RequestMapping("/test")
public class TestController {
@RequestMapping("/hello")
public String test() {
log.debug("hello");
return "hello";
}
}
运行主类,没有报错
浏览器输入http://localhost:8080/test/hello
在Endpoit里面没有找到TestController,怀疑是没有将TestController放入spring容器,但应该能扫描的到阿,真是让人头大,大家知道怎么回事吗┭┮﹏┭┮