开发者社区 问答 正文

spring+mybatis出现NoSuchBeanDefinitionException异常,是什么原因?

已进行mapper层,dataSource的测试也显示同一个异常:
Test类:

public class Test {
ApplicationContext ac;
@Before
public void Before(){
ac=new ClassPathXmlApplicationContext(new String[]{"classpath*:spring-mybatis.xml"});
}
@org.junit.Test
public void Test1(){

Object s=ac.getBean("propertyConfigurer");

    System.out.println(s);
}
}
org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'propertyConfigurer' is defined
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanDefinition(DefaultListableBeanFactory.java:687)
at org.springframework.beans.factory.support.AbstractBeanFactory.getMergedLocalBeanDefinition(AbstractBeanFactory.java:1168)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:281)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:956)
at com.dao.Test.Test1(Test.java:26)

展开
收起
小旋风柴进 2016-03-04 13:30:24 6664 分享
分享
版权
举报
2 条回答
写回答
取消 提交回答
  • 新人一枚

    mybatis-config.xml中,需要定义

        <mapper resource="tk/mybatis/simple/mapper/CountryMapper.xml"/>

    2019-07-17 18:52:09 举报
    赞同 评论

    评论

    全部评论 (0)

    登录后可评论
  • 把jdbc.properties,spring.xml,spring-mybatis.xml放到src/main/resources下,试试

    2019-07-17 18:52:09 举报
    赞同 评论

    评论

    全部评论 (0)

    登录后可评论
AI助理

你好,我是AI助理

可以解答问题、推荐解决方案等