关于SSM整合报Service层错误问题
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'commandController': Unsatisfied dependency expressed through field 'service': Error creating bean with name 'serviceImp': Unsatisfied dependency expressed through field 'userMapper': No qualifying bean of type [com.cwj.backoffice.web.mapper.UserMapper] found for dependency [com.cwj.backoffice.web.mapper.UserMapper]: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations:
{@org.springframework.beans.factory.annotation.Autowired(required=true)}; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.cwj.backoffice.web.mapper.UserMapper] found for dependency [com.cwj.backoffice.web.mapper.UserMapper]: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: 

{@org.springframework.beans.factory.annotation.Autowired(required=true)}; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'serviceImp': Unsatisfied dependency expressed through field 'userMapper': No qualifying bean of type [com.cwj.backoffice.web.mapper.UserMapper] found for dependency [com.cwj.backoffice.web.mapper.UserMapper]: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations

: {@org.springframework.beans.factory.annotation.Autowired(required=true)}; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.cwj.backoffice.web.mapper.UserMapper] found for dependency [com.cwj.backoffice.web.mapper.UserMapper]: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: 

{@org.springframework.beans.factory.annotation.Autowired(required=true)}
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:573)
    at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88)
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:350)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1214)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:543)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:775)
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:861)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:541)
    at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:444)
    at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:326)
    at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:107)
    at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:5181)
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5704)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:145)
    at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:1018)
    at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:994)
    at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:652)
    at org.apache.catalina.startup.HostConfig.manageApp(HostConfig.java:1900)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.apache.tomcat.util.modeler.BaseModelMBean.invoke(BaseModelMBean.java:301)
    at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanServerInterceptor.java:819)
    at com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.java:801)
    at org.apache.catalina.mbeans.MBeanFactory.createStandardContext(MBeanFactory.java:619)
    at org.apache.catalina.mbeans.MBeanFactory.createStandardContext(MBeanFactory.java:566)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.apache.tomcat.util.modeler.BaseModelMBean.invoke(BaseModelMBean.java:301)
    at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanServerInterceptor.java:819)
    at com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.java:801)
    at com.sun.jmx.remote.security.MBeanServerAccessController.invoke(MBeanServerAccessController.java:468)
    at javax.management.remote.rmi.RMIConnectionImpl.doOperation(RMIConnectionImpl.java:1468)
    at javax.management.remote.rmi.RMIConnectionImpl.access$300(RMIConnectionImpl.java:76)
    at javax.management.remote.rmi.RMIConnectionImpl$PrivilegedOperation.run(RMIConnectionImpl.java:1309)
    at java.security.AccessController.doPrivileged(Native Method)
    at javax.management.remote.rmi.RMIConnectionImpl.doPrivilegedOperation(RMIConnectionImpl.java:1408)
    at javax.management.remote.rmi.RMIConnectionImpl.invoke(RMIConnectionImpl.java:829)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:357)
    at sun.rmi.transport.Transport$1.run(Transport.java:200)
    at sun.rmi.transport.Transport$1.run(Transport.java:197)
    at java.security.AccessController.doPrivileged(Native Method)
    at sun.rmi.transport.Transport.serviceCall(Transport.java:196)
    at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:573)
    at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:834)
    at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.lambda$run$0(TCPTransport.java:688)
    at java.security.AccessController.doPrivileged(Native Method)
    at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:687)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
    at java.lang.Thread.run(Thread.java:748)
Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'serviceImp': Unsatisfied dependency expressed through field 'userMapper': No qualifying bean of type [com.cwj.backoffice.web.mapper.UserMapper] found for dependency [com.cwj.backoffice.web.mapper.UserMapper]: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.cwj.backoffice.web.mapper.UserMapper] found for dependency [com.cwj.backoffice.web.mapper.UserMapper]: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:573)
    at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88)
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:350)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1214)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:543)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
    at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:187)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:1208)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1048)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1018)
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:570)
    ... 62 more
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.cwj.backoffice.web.mapper.UserMapper] found for dependency [com.cwj.backoffice.web.mapper.UserMapper]: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoSuchBeanDefinitionException(DefaultListableBeanFactory.java:1398)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1051)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1018)
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:570)
    ... 76 more

浜旀湀 14, 2019 10:52:08 涓嬪崍 org.apache.catalina.core.ApplicationContext log
淇℃伅: Log4jServletContextListener ensuring that Log4j starts up properly.
浜旀湀 14, 2019 10:52:08 涓嬪崍 org.apache.catalina.core.ApplicationContext log
淇℃伅: Log4jServletContextListener ensuring that Log4j shuts down properly.
浜旀湀 14, 2019 10:52:08 涓嬪崍 org.apache.catalina.core.ApplicationContext log
淇℃伅: Closing Spring root WebApplicationContext

求大佬帮帮忙,已经找了一天了,UserMapper还有Service一直报错。

package com.cwj.backoffice.web.mapper;

import com.cwj.backoffice.web.User.Items;
import com.cwj.backoffice.web.User.User;

import java.util.List;


public interface UserMapper {
    public void save(User user);
    public List<Items> select();
}



<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
        PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.cwj.backoffice.web.mapper.UserMapper">
    <insert id="save" parameterType="user">
        INSERT INTO t_user(id,username,password) values(#{id},#{username},#{password});
    </insert>

    <select id="select" resultType="items">
        SELECT * FROM t_user;
    </select>
</mapper>
package com.cwj.backoffice.web.UserService;

import com.cwj.backoffice.web.User.Items;
import com.cwj.backoffice.web.User.User;

import java.util.List;

public interface Service {
    public void save(User user);
    public List<Items> select();
}


/**
 * Copyright (C), 2015-2019, XXX有限公司
 * FileName: ServiceImp
 * Author:   50427
 * Date:     2019/5/14 18:43
 * Description:
 * History:
 * <author>          <time>          <version>          <desc>
 * 作者姓名           修改时间           版本号              描述
 */
package com.cwj.backoffice.web.UserService.Imp;

        import com.cwj.backoffice.web.User.Items;
        import com.cwj.backoffice.web.User.User;
        import com.cwj.backoffice.web.UserService.Service;
        import com.cwj.backoffice.web.mapper.UserMapper;
        import org.springframework.beans.factory.annotation.Autowired;
        import org.springframework.stereotype.Component;

        import java.util.List;

/**
 * 〈一句话功能简述〉<br>
 * 〈〉
 *
 * @author 50427
 * @create 2019/5/14
 * @since 1.0.0
 */
@org.springframework.stereotype.Service
public class ServiceImp implements Service {
    @Autowired
    UserMapper userMapper;
    @Override
    public void save(User user) {
        userMapper.save(user);
    }

    @Override
    public List<Items> select() {

        return userMapper.select();
    }
}


5个回答

1.在UserMapper接口上加上注解@Repository
2.在ServiceImp实现类上面加上@Service("service")

u013254183
老王搞BUG 回复qq_43764144: 你是用的springboot 搭建项目的吗,加@MapperScan(value = "com.cwj.backoffice.web.mapper")了吗
大约一年之前 回复
qq_43764144
qq_43764144 还是报这个错::org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'commandControllers': Unsatisfied dependency expressed through field 'service': Error creating bean with name 'service': Unsatisfied dependency expressed through field 'userMapper': No qualifying bean of type [com.cwj.backoffice.web.mapper.UserMapper] fou
大约一年之前 回复

Mapper接口上加个@Mapper注解

qq_19309473
鹏程萬鲤 回复qq_43764144: 你的springMVC配置文件呢?
大约一年之前 回复
qq_43764144
qq_43764144 @Mapper在接口上么有这个注解
大约一年之前 回复

我给出的解决方案是:把mapper.xml中的sql语句后面的分号去掉


SELECT * FROM t_user;

 这句代码中的items是什么?没懂!
 还有就是返回的类型是一个List,应该使用resultMap返回,而不是使用resultType
qq_43764144
qq_43764144 还是那样,好像和有是一样的
大约一年之前 回复
qq_43764144
qq_43764144 大佬,这个是类似与一个User的类,
大约一年之前 回复

你的那个applicationContext.xml里面扫描了所有类吗?如果没有的话你mapper里面的parameterType="user"就不能这么写

猜想可能是没有扫到包。图片说明

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐