程序大猩猩Halley 2021-08-05 17:16 采纳率: 100%
浏览 73
已结题

自动装配失败,springmvc注入service失败

controller层

@RestController
public class StudentController {
    @Autowired
    @Qualifier("studentService")
    private StudentService studentService;
    //学生登录
    @RequestMapping("/student/login")
    public String login(@RequestParam String sId,@RequestParam String sPwd, Model model){
        Map<String,Object> map = new HashMap<>();
        map.put("sId",Integer.valueOf(sId));
        map.put("sPwd",sPwd);
        Student student = studentService.login(map);
        System.out.println(studentService);
        if (student != null)
            return "sInfo";
        else {
            model.addAttribute("Error",false);
            return "student";
        }
    }
}

配置文件aplicaitonContext

<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:context="http://www.springframework.org/schema/context"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
       http://www.springframework.org/schema/beans/spring-beans.xsd
       http://www.springframework.org/schema/context
       http://www.springframework.org/schema/context/spring-context.xsd">
    <!--导入其他spring配置文件-->
    <import resource="spring-dao.xml"/>
    <import resource="springmvc-servlet.xml"/>
    <!--context内容-->
    <context:component-scan base-package="com.hoary.service"></context:component-scan>
    <context:annotation-config/>

    <!--dao层的bean-->
    <bean id="studentMapper" class="com.hoary.dao.StudentMapperImpl">
        <property name="sqlSessionTemplate" ref="sqlSession"></property>
    </bean>
    <bean id="managerMapper" class="com.hoary.dao.ManagerMapperImpl">
        <property name="sqlSessionTemplate" ref="sqlSession"></property>
    </bean>
    <bean id="bookMapper" class="com.hoary.dao.BookMapperImpl">
        <property name="sqlSessionTemplate" ref="sqlSession"></property>
    </bean>
    <bean id="recordMapper" class="com.hoary.dao.RecordMapperImpl">
        <property name="sqlSessionTemplate" ref="sqlSession"></property>
    </bean>

    <!--service层的bean-->
    <bean id="studentService" class="com.hoary.service.StudentServiceImpl">
        <property name="recordMapper" ref="recordMapper"></property>
        <property name="studentMapper" ref="studentMapper"></property>
        <property name="bookMapper" ref="bookMapper"></property>
    </bean>
    <bean id="managerService" class="com.hoary.service.ManagerServiceImpl" >
        <property name="bookMapper" ref="bookMapper"></property>
        <property name="studentMapper" ref="studentMapper"></property>
        <property name="managerMapper" ref="managerMapper"></property>
    </bean>

    <bean id="/student" class="com.hoary.controller.StudentController"></bean>
</beans>

我运行时就报错
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'studentController': Unsatisfied dependency expressed through field 'studentService'; nested exception is
org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.hoary.service.StudentService' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true), @org.springframework.beans.factory.annotation.Qualifier(value=studentService)}

  • 写回答

3条回答 默认 最新

      报告相同问题?

      相关推荐 更多相似问题

      问题事件

      • 系统已结题 8月14日
      • 已采纳回答 8月6日
      • 创建了问题 8月5日

      悬赏问题

      • ¥15 如何抓这个函数的包wx.updateShareMenu
      • ¥15 需要数据分析!时间紧!
      • ¥15 关于免费论文查重系统的问题。
      • ¥15 朋友们,这个sim函数是出了什么问题了呢
      • ¥15 【MRT数据导入问题】MRT处理modis数据提示opening input header file怎么解决?
      • ¥15 嵌入式系统综合设计题有会的教一下嘛?
      • ¥15 yolov5转onnx验证出错
      • ¥15 proteus仿真LCD不点亮
      • ¥15 C语言红绿灯时间问题
      • ¥15 matlab仿真实现定位算法