Error creating bean with name 'employeeServiceImpl': Injection of resource depen

126 阅读1分钟

持续创作,加速成长!这是我参与「掘金日新计划 · 10 月更文挑战」的第6天,点击查看活动详情

Error creating bean with name 'employeeServiceImpl': Injection of resource dependencies failed; nested exception is org.springframework.beansTOC

注解失败,今天再做项目遇到这个问题一直未解决,查询相关文档,解决方法如下 applicationContext.xml 下面的注解由原来的 <context:component-scan base-package="bdqn.cn.service"/>改为图片所示 原因:注解范围包含不准确 但是之前做项目,只放service在里面就好用,这次不知道什么原因。 在这里插入图片描述 其他注意 controller里的注解

在这里插入图片描述 service 里的注解

在这里插入图片描述 我的web.xml文件

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"
         version="4.0">

    <servlet>
        <servlet-name>springmvc</servlet-name>
        <!--springMVC核心 DispatcherServlet-->
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <!--初始化参数-->
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>classpath:springmvc-servlet.xml</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>springmvc</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>
    <!-- 指定Spring Bean的配置文件所在目录
              在web.xml中通过contextConfigLocation配置spring,
       contextConfigLocation参数定义了要装入的 Spring 配置文件。 -->
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>classpath:applicationContext.xml</param-value>
    </context-param>
    <!-- Spring配置 -->
    <!-- 当系统启动的时候,spring需要进行一些资源加载或者配置,都需要使用此监听去做 -->
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>
    <!-- spring字符编码过滤器start-->
    <filter>
        <!--① Spring 编码过滤器 -->
        <filter-name>encodingFilter</filter-name>
        <filter-class>
            org.springframework.web.filter.CharacterEncodingFilter
        </filter-class>
        <!--② 编码方式  -->
        <init-param>
            <param-name>encoding</param-name>
            <param-value>UTF-8</param-value>
        </init-param>
        <!--③ 强制进行编码转换 -->
        <init-param>
            <param-name>forceEncoding</param-name>
            <param-value>true</param-value>
        </init-param>
    </filter>
    <!-- ② 过滤器的匹配 URL -->
    <filter-mapping>
        <filter-name>encodingFilter</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
    <!-- spring字符编码过滤器end-->
</web-app>