运行环境: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. P3273 【[SCOI2011]棘手的操作】

    此题用可并堆勉强过,需加输入优化,但是这里有个问题就是set总是过不了一组数据,用multiset时间有点高,不懂这个问题,请懂此问题的给我留言. 左偏树+并查集 下面上代码: #include &l ...

  2. day 24

    I am a slow walker, but I never walk back. 我走得很慢,但是我从来不会后退.

  3. Ztree + bootstarp-table 使用

    Ztree + bootstarp-table  使用 一. Ztree 1.引入js/css文件  Ztree官网 <!--ztree--> <link rel="sty ...

  4. MySQL实战45讲学习笔记:第二十八讲

    一.读写分离架构 在上一篇文章中,我和你介绍了一主多从的结构以及切换流程.今天我们就继续聊聊一主多从架构的应用场景:读写分离,以及怎么处理主备延迟导致的读写分离问题. 我们在上一篇文章中提到的一主多从 ...

  5. AOP小记

    编程思想演进:POP(Procedure Oriented Programming)-> OOP(Object Oriented Programming)-> AOP(Aspect Ori ...

  6. [LeetCode] 410. Split Array Largest Sum 分割数组的最大值

    Given an array which consists of non-negative integers and an integer m, you can split the array int ...

  7. 修改Windows中文用户名为英文(更全面的方法)

    网上方法很多,但是大多不全面. 我的建议是 1,新建/切换管理员账号 net user administrator /active:yes 然后点击桌面,使用Alt+F4组合键 注销中文用户名账号,并 ...

  8. tomcat 指定(自定义)JDK路径的两种方式

      1.情景展示 tomcat7使用jdk1.7:tomcat8使用jdk1.8.两个tomcat在一台机器下同时启动,你会发现这两个tomcat使用的是一个版本的jdk, 那就是你配置过的JAVA_ ...

  9. JSP还有必要学吗?这篇文章告诉你

    阅读本文大概需要 12.4 分钟. 来源:http://suo.im/4wqRi7 作者:杨明翰 前戏   前后端分离已成为互联网项目开发的业界标准使用方式,通过nginx+tomcat的方式(也可以 ...

  10. 从头学一次J2EE笔记

    1.在Servlet3.5规范之前,Java Web 应用的绝大部分组件都通过web.xml 文件来配置管理, Servlet3.0 规范可通过Annotation来配置管理Web组件,因此web.x ...