Mybatis+Spring初学之NoSuchBeanDefinitionException出错的处理

这个问题困扰了我很久

试了很多方法,查了很多资料都不可用

于是我重新建了项目,把东西一一删除重新拷贝,无意中发现了错在哪

package com.auto.dao;

import com.auto.annotation.MybatisRegist;
import com.auto.entity.Regist;

@MybatisRegist
public interface RegistDao {

    void add(Regist regist);
}

因为报错是关于Spring的,我查询Spring良久,也是未果,加了bean id声明RegistDao,也不可以

结果是这里错了

package com.auto.test;

import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.auto.dao.RegistDao;
import com.auto.entity.Regist;

public class TestRegist {
    @Test
    public void testAddCost(){
        ApplicationContext ac =
                new ClassPathXmlApplicationContext("spring-mvc.xml");
        RegistDao dao = ac.getBean("registdao",RegistDao.class);
        Regist regist = new Regist();
        regist.setRegist_name("干你妹的");
        regist.setRegist_passwd("198");
        
        dao.add(regist);
    }
}
结果是RegistDao dao = ac.getBean("registdao",RegistDao.class);

中的registdao写错了,后来经我查询才得知getBean方法dao名要首字母小写,其他不变,应当是

RegistDao dao = ac.getBean("registDao",RegistDao.class);

然后正常了,涨知识,分享给大家

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值