关于MyBatis和Spring整合时,No bean named 'xxx' is defined我遇到的问题
2017-10-30 21:12
681 查看
spring的xml文件如下,看了几遍没有问题
<?xml version="1.0" encoding="utf-8"?> <beans xmlns="http://www.springframework.org/schema/beans" 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:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" 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/aop http://www.springframework.org/schema/aop/spring-aop-3.1.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd"> <!-- 加载数据库配置文件 --> <context:property-placeholder location="classpath:db.properties" /> <!-- 配置数据库连接池 采用阿里巴巴的druid连接池--> <bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource"> <property name="driverClassName" value="${jdbc.driver}" /> <property name="url" value="${jdbc.url}" /> <property name="username" value="${jdbc.username}" /> <property name="password" value="${jdbc.pwd}" /> </bean> <!-- 配置mybatis的sqlSessionFactory --> <bean id="sessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"> <property name="dataSource" ref="dataSource" /> <property name="configLocation" value="classpath:mybatis.xml" /> <property name="mapperLocations" value="classpath:mapper/*.xml" /> <property name="typeAliasesPackage" value="com.seckill.vo" /> </bean> <!-- 配置扫描Dao包接口,动态实现Dao包中的接口,并且注入到spring容器中 --> <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer"> <!-- 为什么用sqlSessionFactoryBeanName不用sqlSessionFactory属性, 防止在使用sessionFactory时,从外部db。properties获取的属性还没有注入进来 导致dataSource错误,导致sessionFactory错误 --> <property name="sqlSessionFactoryBeanName" value="sessionFactory" /> <property name="basePackage" value="com.seckill.dao" /> </bean> </beans>
但是一getBean的时候就会报No bean named 'xxx' is defined 错误,后面才发现我把资源文件都放在了src/main/resouces 这个 source Folder下,而这个source Folder是我右键项目new出来的一个source Folder,所以资源文件永远不会加载到项目中去,一直报No bean
named 'xxx' is defined 错误,解决办法就是右键项目 在builder path下 New Souce Folder 这样资源文件才能加载到项目里去.
相关文章推荐
- CXF和spring整合遇到的问题:No bean named 'cxf' is defined
- 关于NoSuchBeanDefinitionException: No bean named 'xxxx' is defined问题解决
- mybatis和spring整合报错:No bean named 'sqlSessionFactory' is defined
- 关于Mybatis "There is no getter for property named 'XXX' in class java.lang.String"的问题
- 关于NoSuchBeanDefinitionException: No bean named 'xxxx' is defined问题解决
- 使用mvc:annotation-driven时遇到的No bean named 'cacheManager' is defined问题
- 关于dao层Bean注入失败报No qualifying bean of type [xxx.xxx.xxx.xxx] is defined错误的问题
- 关于NoSuchBeanDefinitionException: No bean named 'xxxx' is defined问题解决
- mybatis加Spring项目: 解决There is no getter for property named '***' in 'class java.lang.String'问题
- Spring、SpringMVC、Mybatis整合遇到的问题
- 关于Spring整合mybatis时配置MapperScannerConfigurer的问题
- ssh整合启动tomcat遇到的问题 Error creating bean with name 'org.springframework.transaction.interceptor.Transa
- SpringMvc+MyBatis+Spring+Maven整合遇到的问题总结
- 关于spring boot自动注入出现Consider defining a bean of type 'xxx' in your configuration问题解决方案
- mybatis 基本类型的if条件判断问题 There is no getter for property named 'xxx' in 'class Java.lang.Integer'
- 整合spring+mybatis遇到的问题01
- spring boot+mybatis 多数据源报错 No qualifying bean of type [javax.sql.DataSource] is defined:
- org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'xx' is defined
- Mybatis ReflectionException:There is no getter for property named 遇到的问题小结
- 关于spring整合mybatis的扫描器的配置问题