Description: Field ServiceImp in com.controller.Controller required a bean of type ‘com.servic

启动Spring boot项目时,出现如下图类似的问题时
在这里插入图片描述
需要考虑两个原因:
1、Application启动类中有没有添加包扫描注解@ComponentScan(basePackages=“com.gzds”)

@ComponentScan(basePackages="com.gzds")//启动包扫描
@SpringBootApplication
public class MidPrivateCloudApplication {

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

}

2、Controller层和service层有没有添加@Controller和@Service注解

我遇到的问题是:在controller中没找到service注入的bean
在这里插入图片描述
原因:service层没加入@service注解交给spring容器管理,所以扫描不到
在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/qq_41936224/article/details/107356280
今日推荐