Spring Boot项目测试test包与src包各类的目录对应问题
默认包的结构:
①主程序所在包及其下面的所有子包里面的组件都会被默认扫描进来
②若在主程序包外面建立一个Controller类,返回字符串,则会产生404页面丢失,原因是主程序的组件适用范围不能囊括到主程序包外
test在main包外:
test在main包内:
③若一定要建在主程序所在包的外面,则在主程序的注解:@SpringBootApplication后面加上
“(scanBasePackages)=“主程序外的那个Controller类所在的包名称””,如@SpringBootApplication(scanBasePakages=”com.zat“)
或者使用把@SpringBootApplication(scanBasePakages=”com.zat“)改成
@SpringBootConfiguration
@EnableAotuConfiguration
@ComponentScan(“com.zat”)指定扫描路径,重新启动
④一个@SpringBootApplication等同于@SpringBootConfiguration
@EnableAotuConfiguration
@ComponentScan(”com.zat.boot“)