zoukankan      html  css  js  c++  java
  • spring 整合Mybatis 错误:Error creating bean with name 'loginController': Injection of autowired dependencies failed......xxxxx

    Error creating bean with name 'loginController': Injection of autowired dependencies failed......xxxxx

      运行环境:jdk1.7.0_17+tomcat 7 + spring:3.2.0 +mybatis:3.2.7+ eclipse

      错误:在使用框架时候启动报错:Error creating bean with name 'loginController': Injection of autowired dependencies failed......xxxxx

      错误原因:在使用springmvc 注解开发中从错误来看提示我有一个bean 无法注入到容器,反复查看着了些资料是我没有告诉系统我的service是那个没有添加注解倒置的,特此写下原因记录下

      解决办法:可以看到我下面接口实现service类并没有任何注解,只需要加上注解就ok了  "@Service" 告诉系统這是我的service

        

      错误代码:

     1 [org.springframework.beans.factory.support.DefaultListableBeanFactory] - Returning cached instance of singleton bean 'xxhhTableConcernCustomMapper'
     2 [org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor] - Autowiring by type from bean name 'loginServiceImpl' to bean named 'xxhhTableConcernCustomMapper'
     3 [org.springframework.beans.factory.annotation.InjectionMetadata] - Processing injected element of bean 'loginServiceImpl': AutowiredFieldElement for private com.xxhh.mapper.XxhhTableLikeCustomMapper com.xxhh.service.impl.LoginServiceImpl.likeCustomMapper
     4 [org.springframework.beans.factory.support.DefaultListableBeanFactory] - Returning cached instance of singleton bean 'xxhhTableLikeCustomMapper'
     5 [org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor] - Autowiring by type from bean name 'loginServiceImpl' to bean named 'xxhhTableLikeCustomMapper'
     6 [org.springframework.beans.factory.annotation.InjectionMetadata] - Processing injected element of bean 'loginServiceImpl': AutowiredFieldElement for private com.xxhh.mapper.XxhhTableOrdercommetsCustomMapper com.xxhh.service.impl.LoginServiceImpl.xxhhTableOrdercommetsCustomMapper
     7 [org.springframework.beans.factory.support.DefaultListableBeanFactory] - Returning cached instance of singleton bean 'xxhhTableOrdercommetsCustomMapper'
     8 [org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor] - Autowiring by type from bean name 'loginServiceImpl' to bean named 'xxhhTableOrdercommetsCustomMapper'
     9 [org.springframework.beans.factory.support.DefaultListableBeanFactory] - Finished creating instance of bean 'loginServiceImpl'
    10 [org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor] - Autowiring by type from bean name 'loginController' to bean named 'loginServiceImpl'
    11 [org.springframework.beans.factory.annotation.InjectionMetadata] - Processing injected element of bean 'loginController': AutowiredFieldElement for private com.xxhh.service.BabyService com.xxhh.controller.LoginController.babyService
    12 [org.springframework.web.context.support.XmlWebApplicationContext] - Exception encountered during context initialization - cancelling refresh attempt
    13 org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'loginController': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.xxhh.service.BabyService com.xxhh.controller.LoginController.babyService; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.xxhh.service.BabyService] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
    14     at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:334)
    15     at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1210)
    16     at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:537)
    17     at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476)
    18     at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:303)
    19     at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
    20     at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:299)
    21     at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
    22     at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:755)
    23     at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:757)
    24     at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:480)
    25     at org.springframework.web.servlet.FrameworkServlet.configureAndRefreshWebApplicationContext(FrameworkServlet.java:663)
    26     at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:629)
    27     at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:677)
    28     at org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:548)

      相关代码:

      Controller

     1 @Controller
     2 public class LoginController {
     3     //定义个loginservlice 属性
     4     @Autowired private LoginService loginService;
     5     //定义babyservice 
     6     @Autowired private BabyService babyService;
     7     
     8     /**
     9      * 传一个学生id  查询学生所有相关资料 粉丝 点赞 关注 个人资料 以及卖出的 发布的宝贝。 
    10      * @param student_id
    11      * @return
    12      */
    13     @ResponseBody
    14     @RequestMapping(value="/selectxxhh_user",method={RequestMethod.GET})
    15     public Map<String, Object> selecAllUsermMeanst(@RequestParam(value="student_id",required=false)String student_id) {
    16         System.out.println(student_id);
    17         XxhhTableOrdercommets xxhhTableOrdercommets = new XxhhTableOrdercommets();
    18         xxhhTableOrdercommets.setStudentId(Integer.valueOf(student_id));
    19         Map<String, Object>map = new HashMap<String,Object>();
    20         //通过service 接口调用接口实现类然后实现类在操作数据库查询
    21         XxhhTableUser xxhhTableUser = loginService.selecAllUsermMeanst(Integer.valueOf(student_id));
    22         List<XxhhTableFans> fasnList = loginService.selectAllFans(Integer.valueOf(student_id));
    23         List<XxhhTableConcern> concernList = loginService.selectAllConcern(Integer.valueOf(student_id));
    24         List<XxhhTableLike> likesList = loginService.selectAllLike(Integer.valueOf(student_id));
    25         List<XxhhTableOrdercommets> ordercommets = loginService.selectAllOrdercommets(Integer.valueOf(student_id));
    26         List<XxhhTableBaby>babySelles =babyService.selectAllReleases(Integer.valueOf(student_id));
    27         List<XxhhTableBaby> babySales = babyService.selectAllSelles(Integer.valueOf(student_id));
    28         if (null == xxhhTableUser) {
    29                 map.put("result", 1);
    30                 map.put("data", "网络连接失败");
    31         }else {
    32             map.put("xxhhTableUser", xxhhTableUser);
    33             map.put("AllFans", fasnList);
    34             map.put("AllConcernList", concernList);
    35             map.put("AllLikes", likesList);
    36             map.put("AllOrdercommets", ordercommets);
    37             map.put("AllSelles", babySelles);
    38             map.put("AllSale", babySales);
    39             map.put("result", 0); 
    40         }
    41         
    42         return map;
    43     }

    接口service

    public interface BabyService {
        
        //查询发布的宝贝
        List<XxhhTableBaby> selectAllReleases(Integer student_id);
        //查询卖出的宝贝
        List<XxhhTableBaby> selectAllSelles(Integer student_id);
        
    
    }

    接口实现类

    public class BabyServiceImpl implements BabyService {
        
        @Autowired 
        private XxhhTableBabyCustomMapper xxhhTableBabyCustomMapper;
        
        //发布的宝贝
        @Override
        public List<XxhhTableBaby> selectAllReleases(Integer student_id) {
            // TODO Auto-generated method stub
            return xxhhTableBabyCustomMapper.selectAllReleases(student_id);
        }
    
        //卖出的宝贝
        @Override
        public List<XxhhTableBaby> selectAllSelles(Integer student_id) {
            // TODO Auto-generated method stub
            return xxhhTableBabyCustomMapper.selectAllSelles(student_id);
        }
    
    }
  • 相关阅读:
    读取XML并绑定至RadioButtonList
    获取客户端IP地址
    Repeater控件数据导出Excel
    验证用户必选CheckBox控件
    限制CheckBoxList控件只能单选
    获取客户端电脑名称
    获取Repeter的Item和ItemIndex
    获取DataList控件的主键和索引
    InsusExportToExcel Library
    ASP.NET网页打印
  • 原文地址:https://www.cnblogs.com/tanglie/p/7872896.html
Copyright © 2011-2022 走看看