运行环境:Spring框架整合MaBitis框架

问题叙述:

  在Spring配置文件applicationContext-mybatis.xml中配置好mybatis之后

  

<?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:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd">
<!--当前配置文件用于管理mybatis-->
<!--加载资源文件,需要用到context命名空间-->
<context:property-placeholder location="classpath:com/bjsxt/config/commons/db.properties"/>
<!--配置数据源,在spring-jdbc.jar中提供了一个测试用的数据源-->
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="${db.driver}"/>
<property name="url" value="${db.url}"/>
<property name="username" value="${db.username}"/>
<property name="password" value="${db.password}"/>
</bean>
<!--配置sqlSessionFactory对象,在MyBatis-Spring.jar中提供-->
<bean id="factory" class="org.mybatis.spring.SqlSessionFactoryBean">
<!--注入数据源-->
<property name="dataSource" value="dataSource"/>
<!--配置别名-->
<property name="typeAliases" value="com.bjsxt.pojo"/>
</bean>
<!--配置映射扫描,在mybatis-spring.xml中提供-->
<bean id="msc" class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<!--扫描位置-->
<property name="basePackage" value="com.bjsxt.mapper"/>
<!--注入工厂对象-->
<property name="sqlSessionFactoryBeanName" value="factory"/>
</bean> </beans>

  接下来配置applicationContext-service.xml,其中需要注入userMapper

  

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd">
<!--此配置文件用于管理service对象-->
<bean id="userService" class="com.bjsxt.service.impl.UserServiceImpl">
<!--注入UserMapper对象-->
<property name="userMapper" ref="userMapper"/>
</bean>
</beans>

 出现:

原因分析:

这里的错误,是因为系统找不到userMapper,因为没有定义,在没有用Spring的时候,userMapper是通过sqlSession的getMapper方法获得的,

当使用Spring进行配置MyBstis时,sqlSession对象和userMapper已经通过配置文件进行生成,但是这个过程是在程序正式启动运行过程中才会

产生的,此处虽然会报错,但是不影响程序运行,但是不解决总让人感觉不舒服,下面是解决方案:

问题解决:

鼠标放在有错误的这一行,前面会有一个类似灯泡的图标,点击下三角,按照图上选择Disable  inspextion选项,进行标注,表明,此问题忽略,可以正常编译

 

Idea中Spring整合MyBatis框架中配置文件中对象注入问题解决方案的更多相关文章

  1. Maven项目中Spring整合Mybatis

    Maven项目中Spring整合Mybatis 添加jar包依赖 spring需要的jar包依赖 <dependency> <groupId>org.springframewo ...

  2. 阶段3 3.SpringMVC·_07.SSM整合案例_08.ssm整合之Spring整合MyBatis框架

    service能供成功的调用到service对象就算是整合成功 如果能把生成的代理对象也存大IOC的容器中.那么ServiceImpl就可以拿到这个对象 做一个注入,然后就可以调用代理对象的查询数据库 ...

  3. spring整合mybatis框架

    1.导入jar包 2.配置文件 a.    applicationContext.xml文件 <beans xmlns="http://www.springframework.org/ ...

  4. 阶段3 3.SpringMVC·_07.SSM整合案例_09.ssm整合之Spring整合MyBatis框架配置事务

    spring加入声明式的事物 配置事物 配置事物管理器 需要一个dataSource,引入上面的dataSource 配置事务通知 引入上面的transactionManager事物管理器 find开 ...

  5. OSGI企业应用开发(十)整合Spring和Mybatis框架(三)

    上篇文章中,我们已经完成了OSGI应用中Spring和Mybatis框架的整合,本文就来介绍一下,如何在其他Bundle中,使用Mybatis框架来操作数据库. 为了方便演示,我们新建一个新的Plug ...

  6. OSGI企业应用开发(八)整合Spring和Mybatis框架(一)

    到目前为止,我们已经学习了如何使用Blueprint將Spring框架整合到OSGI应用中,并学习了Blueprint&Gemini Blueprint的一些使用细节.本篇文章开始,我们將My ...

  7. flink 流式处理中如何集成mybatis框架

    flink 中自身虽然实现了大量的connectors,如下图所示,也实现了jdbc的connector,可以通过jdbc 去操作数据库,但是flink-jdbc包中对数据库的操作是以ROW来操作并且 ...

  8. SSM:spring+springmvc+mybatis框架中的XML配置文件功能详细解释(转)

    原文:https://blog.csdn.net/yijiemamin/article/details/51156189# 这几天一直在整合SSM框架,虽然网上有很多已经整合好的,但是对于里面的配置文 ...

  9. 0927-转载:SSM:spring+springmvc+mybatis框架中的XML配置文件功能详细解释

    这篇文章暂时只对框架中所要用到的配置文件进行解释说明,而且是针对注解形式的,框架运转的具体流程过两天再进行总结. spring+springmvc+mybatis框架中用到了三个XML配置文件:web ...

随机推荐

  1. c:forTokens标签循环输出

    对带有相同符合格式内容进行分割输出,例如,varstr="1,2,3,4,5,6"; c:forTokens属性说明表 引用 varStatus,它们描述了迭代的当前状态,如下这些 ...

  2. 4.Go-结构体、结构体指针和方法

    4.1.结构体 结构体:将一个或多个变量组合到一起形成新的类型,这个类型就是结构体,结构体是值类型 定义结构体和赋值 //Learn_Go/main.go package main import &q ...

  3. POJ2718Smallest Difference(暴力全排列)

    传送门 题目大意:升序输入十进制数 没有重复 分成两个非空集合 每个集合组成一个数(不能有前导零) 求两个数差的最小值. 题解:全排列...我数组从1开始怎么一直WA...还有这个输入值得学习. 代码 ...

  4. [LeetCode] 187. Repeated DNA Sequences 求重复的DNA序列

    All DNA is composed of a series of nucleotides abbreviated as A, C, G, and T, for example: "ACG ...

  5. python 获取日期以及时间

    >>> import datetime >>> >>> i = datetime.datetime.now() >>> prin ...

  6. netcat 传输T级别大文件

    接收端 nc -d -l 5002 |tar xf - nohup  sh receive.sh  &   发送端 tar cf - . | nc  1.1.1.1  5002 nohup   ...

  7. 使用nodemon提高nodejs调试效率

    1.安装 nodemon 直接用npm安装既可,键入命令: npm -g install nodemon .如果不行,检查电脑有没有联网,联网后输入 sudo npm -g install nodem ...

  8. 33,Leetcode 搜索旋转排序数组-C++ 递归二分法

    题目描述 假设按照升序排序的数组在预先未知的某个点上进行了旋转. ( 例如,数组 [0,1,2,4,5,6,7] 可能变为 [4,5,6,7,0,1,2] ). 搜索一个给定的目标值,如果数组中存在这 ...

  9. HUSKY CLOCK1.0上线啦!

    有人需要HUSKY CLOCK1.0下载资源的请联系1335415335@qq.com! 感谢支持,您的认可是我们前进的动力!

  10. Redis学习之zskiplist跳跃表源码分析

    跳跃表的定义 跳跃表是一种有序数据结构,它通过在每个结点中维持多个指向其他结点的指针,从而达到快速访问其他结点的目的 跳跃表的结构 关于跳跃表的学习请参考:https://www.jianshu.co ...