问题遇到的现象和发生背景
自己写springmvc项目时遇到的一个问题,spring无法实例化bean(我在bean的无参构造里输出一句话,控制台没有输出)
在类上面加@Service注解,spring没有实例化改类,手动在配置文件里实例化也不行。
操作环境、软件版本等信息
idea tomcat8.5.82 jdk8
尝试过的解决方法
检查了web.xml里的spring监听器,检查了spring配置文件里面的组件扫描器,检查了@Service注解
就是不能实例化service,真的是醉了
部分报错信息:
10-Dec-2022 15:03:20.641 警告 [http-nio-8080-exec-3] org.springframework.context.support.AbstractApplicationContext.refresh Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'baseModulesController': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.yzic.service.impl.UserServiceImpl' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@javax.annotation.Resource(shareable=true, lookup=, name=, description=, authenticationType=CONTAINER, type=class java.lang.Object, mappedName=)}
10-Dec-2022 15:03:20.641 严重 [http-nio-8080-exec-3] org.springframework.web.servlet.FrameworkServlet.initServletBean Context initialization failed