这个问题困扰了我很久
试了很多方法,查了很多资料都不可用
于是我重新建了项目,把东西一一删除重新拷贝,无意中发现了错在哪
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);
然后正常了,涨知识,分享给大家