运行环境: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. 【使用篇二】SpringBoot整合Listener(3)

    两种方式: 通过注解扫描完成 Listener 组件的注册 通过方法完成 Listener 组件注册 一.通过注解扫描完成 Listener 组件的注册 1. 编写Listener类 /*** spr ...

  2. 20191003 「HZOJ NOIP2019 Round #8」20191003模拟

    综述 试题为常州集训2019SCDay2 得分\(100+30(0)+28\) 时之终结 问题描述 HZOJ1310 题解 构造题. 发现部分分有一档是 \(Y\) 是 \(2^x\) ,于是自然想到 ...

  3. leetcode 561. 数组拆分 I

    为了理解这种方法,让我们从不同的角度来看待问题.我们需要形成数组元​​素的配对,使得这种配对中最小的总和最大.因此,我们可以查看选择配对中最小值的操作,比如 (a,b)(a,b) 可能会产生的最大损失 ...

  4. Redis删除特定前缀key的优雅实现

    还在用keys命令模糊匹配删除数据吗?这就是一颗随时爆炸的炸弹! Redis中没有批量删除特定前缀key的指令,但我们往往需要根据前缀来删除,那么究竟该怎么做呢?可能你一通搜索后会得到下边的答案 re ...

  5. Linux性能优化实战学习笔记:第五讲

    一.什么是CPU的使用率 1.你最常用什么指标来描述系统的CPU性能? 我想你的答案,可能不是平均负载,也不是CPU上下文切换,而是另一个更直观的指标CPU使用率 CPU使用率到底是怎么算出来的吗? ...

  6. Node.js安装使用-VueCLI安装使用-工程化的Vue.js开发

    作者 | Jeskson 来源 | 达达前端小酒馆 搭建Node.js环境 什么是Node.js简介呢?它是一个基于JavaScript的运行环境,Node.js发布于2009年5月,对Chrome ...

  7. it's over | 2019 CSP-S 第一轮认证

    不知道自己有没有凉,毕竟我们省这么弱(据说有的省80都悬... 其实这几天对初赛基本没什么感觉,可能是没给自己多大压力吧,倒是班上的一群同学似乎比我们还着急,我们的数学课代表兼数竞大佬特意给我画了吉祥 ...

  8. springcloud2.x之management.security.enabled=false报错处理

    1. springcloud1.5.x的消息总线配置是 # RabbitMq的地址.端口,用户名.密码 spring.rabbitmq.host=localhost spring.rabbitmq.p ...

  9. ZJOI 2009 多米诺骨牌(状态压缩+轮廓线+容斥)

    题意 https://www.lydsy.com/JudgeOnline/problem.php?id=1435 思路 一道很好的状压/容斥题,涵盖了很多比较重要的知识点. 我们称每两行间均有纵跨.每 ...

  10. SpringBoot+EventBus使用教程(一)

    一.简介 EventBus是一个基于发布订阅的事件总线,在Java和Android里都可以使用. 二.使用 1.引入pom <dependency> <groupId>org. ...