自己电脑可以做网站服务器,厦门网站建设公司,自己做公司网站,网站制作手机端重生之 SpringBoot3 入门保姆级学习#xff08;04、 包扫描#xff09; 2.1 包扫描 2.1 包扫描 默认包扫描规则#xff1a; SpringBootApplication 标注的就是主程序 SpringBoot 只会扫描主程序下面的包 自动的 component-scan 功能 在 SpringBootApplication 添加参数可以… 重生之 SpringBoot3 入门保姆级学习04、 包扫描 2.1 包扫描 2.1 包扫描 默认包扫描规则 SpringBootApplication 标注的就是主程序 SpringBoot 只会扫描主程序下面的包 自动的 component-scan 功能 在 SpringBootApplication 添加参数可以增加包扫描范围 如SpringBootApplication(scanBasePackages “com.zhong”) 在 SpringBootApplication 直接使用注解 ComponentScan(“com.zhong”) 指定扫描路径 开始可以正常访问 当 controller 包移动到 com.zhong 下面 不能正常访问 解决办法在 Boot302DemoApplication 上注解参数为 scanBasePackages “com.zhong” 也就是你想要扫描的包的位置
package com.zhong.boot302demo;import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;SpringBootApplication(scanBasePackages com.zhong) // 添加包扫描位置
// ComponentScan(com.zhong) // 直接指定扫描路径
public class Boot302DemoApplication {public static void main(String[] args) {SpringApplication.run(Boot302DemoApplication.class, args);}}
重启 SpringBoot 后再次访问