问题描述
- Spring+mybatis 出现 NoSuchBeanDefinitionException
- 异常信息: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:29)spring-mybatis.xml:
<?xml version=""1.0"" encoding=""UTF-8""?>
xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xmlns:p=""http://www.springframework.org/schema/p""
xmlns:context=""http://www.springframework.org/schema/context""
xmlns:mvc=""http://www.springframework.org/schema/mvc""
xsi:schemaLocation=""http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.1.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd"" default-autowire=""byName"">
context:annotation-config/class=""org.springframework.jdbc.datasource.DataSourceTransactionManager"">
解决方案
<?xml version=""1.0"" encoding=""UTF-8""?>
xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xmlns:p=""http://www.springframework.org/schema/p""
xmlns:context=""http://www.springframework.org/schema/context""
xmlns:mvc=""http://www.springframework.org/schema/mvc""
xsi:schemaLocation=""http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.1.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd"" default-autowire=""byName"">
context:annotation-config/
class=""org.springframework.jdbc.datasource.DataSourceTransactionManager"">
test类:public class Test {
ApplicationContext ac;
@Before
public void Before(){
ac=new ClassPathXmlApplicationContext(new String[]{""classpath*:spring-mybatis.xml""});
}
@org.junit.Testpublic void Test1(){Object s=ac.getBean(""propertyConfigurer""); System.out.println(s);}
}
解决方案二:
context:annotation-config/
class=""org.springframework.jdbc.datasource.DataSourceTransactionManager"">
解决方案三:
spring配置文件中没有一个叫propertyConfigurer的bean配置
解决方案四:
在spring-mybatis.xml配置文件中,没有定义id为propertyConfigurer的bean吧。
解决方案五:
spring+mybatis
解决方案六:
没这个bean,你需要在xml或者使用注解配置
解决方案七:
没有'propertyConfigurer' 这个bean的id值
解决方案八:
propertyConfigurer的bean配置,这个bean没有