2 zjjingvheng zjjingvheng 于 2015.07.27 21:59 提问

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)

12个回答

zjq78577117
zjq78577117   2015.07.28 09:30
已采纳

把jdbc.properties,spring.xml,spring-mybatis.xml放到src/main/resources下吧

zjjingvheng
zjjingvheng 好好读,读到了
2 年多之前 回复
zjjingvheng
zjjingvheng 我开始是放到那儿的。。。。读都读不到。
2 年多之前 回复
zjjingvheng
zjjingvheng   2015.07.27 22:02
<context:annotation-config/>    
<context:component-scan base-package="com.dao"/>
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">













class="org.springframework.jdbc.datasource.DataSourceTransactionManager">

CSDNXIAON
CSDNXIAON   2015.07.28 08:43

spring+mybatis
----------------------同志你好,我是CSDN问答机器人小N,奉组织之命为你提供参考答案,编程尚未成功,同志仍需努力!

zjjingvheng
zjjingvheng   2015.07.27 22:00

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">


zjjingvheng
zjjingvheng   2015.07.27 22:04

#

<bean id="transactionManager"

class="org.springframework.jdbc.datasource.DataSourceTransactionManager">

zjjingvheng
zjjingvheng   2015.07.27 22:04
 <context:component-scan base-package="com.dao"/>
    <bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
  <property name="location" value="classpath:jdbc.properties"></property>
   </bean>

   <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
   <property name="driverClassName" value="${jdbc.driverClassName}"></property>
   <property name="url" value="${jdbc.url}"></property>
   <property name="username" value="${jdbc.username}"></property>
   <property name="password" value="${jdbc.password}"></property>
   </bean>

  <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
  <property name="dataSource" ref="dataSource"></property>
  <property name="mapperLocations" value="classpath:com/dao/*.xml"></property>
  </bean>

  <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer" autowire="byName">
  <property name="basePackage" value="com.dao"></property>
  <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory" />
  </bean>

   <bean id="transactionManager"
  class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
  <property name="dataSource" ref="dataSource"></property>
  </bean>
    </beans>


zjjingvheng
zjjingvheng   2015.07.27 22:06

第一次用传上去真难、、、、、、帮忙啊大神们

diaoliwei2
diaoliwei2   Rxr 2015.07.28 05:17

No bean named 'propertyConfigurer' is defined,,这个propertyConfigurer有问题

zjjingvheng
zjjingvheng 是啊不知道哪里的问题。后面的都找不到bean了
2 年多之前 回复
Evankaka
Evankaka   Ds   Rxr 2015.07.28 08:35

<value>classpath: conf/sqlmap/jdbc.properties </value>


加个 看看

zjjingvheng
zjjingvheng   2015.07.28 09:04

图片说明

共12条数据 1 尾页
Csdn user default icon
上传中...
上传图片
插入图片