运行环境: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. java第三讲课后动手动脑及代码编写

    1. 类就是类型,对象就是这种类型的实例,也就是例子.类是抽象的东西,对象是某种类的实实在在的例子.例如:车是一个类,汽车,自行车就是他的对象. 对象的定义方法? (1)对象声明:类名 对象名: (2 ...

  2. 求职-DB相关职位常见face题

    数据分析是个通用技能,适合各行各业,比如运营.产品.分析等职位都会要求会数据分析. 一.考察对数据分析岗位的理解与职业规划 数据分析师与数据工程师的区别在哪里? 为什么转行, 为什么没在公司内部转岗? ...

  3. File.createNewFile和 File.createTempFile比较和区别

    原文地址:http://wzhiju.iteye.com/blog/1119037 最近,在看代码时看到了一个方法, File.createTempFile() ,由此联想到File.createNe ...

  4. [RN] React Native 使用 Redux 比较详细和深刻的教程

    React Native 使用 Redux 比较详细和深刻的教程 React Native 使用 Redux https://www.jianshu.com/p/06fc18cef56a http:/ ...

  5. 【转】Java 泛型

    转载:https://www.cnblogs.com/lwbqqyumidi/p/3837629.html. 一. 泛型概念的提出(为什么需要泛型)? 首先,我们看下下面这段简短的代码: public ...

  6. [LeetCode] 753. Cracking the Safe 破解密码

    There is a box protected by a password. The password is n digits, where each letter can be one of th ...

  7. [LeetCode] 337. House Robber III 打家劫舍之三

    The thief has found himself a new place for his thievery again. There is only one entrance to this a ...

  8. [LeetCode] 25. Reverse Nodes in k-Group 每k个一组翻转链表

    Given a linked list, reverse the nodes of a linked list k at a time and return its modified list. k  ...

  9. 第09组 Beta冲刺(4/5)

    队名:观光队 链接 组长博客 作业博客 组员实践情况 王耀鑫 过去两天完成了哪些任务 文字/口头描述 学习 展示GitHub当日代码/文档签入记录 无 接下来的计划 完成短租车,页面美化 还剩下哪些任 ...

  10. WC 2008 观光计划(斯坦纳树)

    题意 https://www.lydsy.com/JudgeOnline/problem.php?id=2595 思路 是一道比较裸的斯坦纳树呢- 题意等价于选出包含一些点的最小生成树,这就是斯坦纳树 ...