ssm整合项目无法创建bean问题解决办法

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userController': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userServiceImpl': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.myproject.dao.UserDao] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@javax.annotation.Resource(shareable=true, lookup=, name=, description=, authenticationType=CONTAINER, type=class java.lang.Object, mappedName=)};

1.相信很多初学者在搭配ssm框架的时候大部分都遇到过类似的问题,没错就是它了,找了好久才知道是什么原因:

正确的包名是com.myproject.(......),而我在配置spring文件application的时候写成了myporject.......(真的坑自己)

2.解决办法:

仔细检查application以及是否导包,当然咯,大部分还是出在配置文件的问题,所以大家在搭配框架的时候配置文件的描述一定要正确,而且要仔细,特别是在配置文件中引用自己项目的包名的时候,最好把包名直接复制粘贴到引用的配置文件中去,不要手写,不要手写,不要手写,重要的事情说三遍,因为一个字母的错误可能让你怀疑人生;还有就是在编写实现代码的时候一定要在类上加上注解,比如service层的类名上加上@Service,controller层的类名上加上@Controller。。。。等等之类的注解,不然也会报类似的错误;总结:大家在报类似的错误的时候仔细检查配置文件

猜你喜欢

转载自blog.csdn.net/java_MrZHANG/article/details/81130419
今日推荐