Mybatis异常: protocol = http host = null

  • Post author:
  • Post category:其他


  1. 问题现象

    1. 程序启动,提示applicationContext.xml文件出错,进一步提示某个mapper文件出错
    2. 具体异常信息如下:红色字为出错的Mapper文件,高亮为主要关注异常信息;

org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘org.mybatis.spring.mapper.MapperScannerConfigurer#0’ defined in class path resource [applicationContext.xml]: Cannot resolve reference to bean ‘sqlSessionFactory’ while setting bean property ‘sqlSessionFactory’; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘sqlSessionFactory’ defined in class path resource [applicationContext.xml]: Invocation of init method failed; nested exception is org.springframework.core.NestedIOException: Failed to parse mapping resource: ‘file

[E:\JavaWorkSpace\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\Smart\WEB-INF\classes\com\huahai\dao\impl\config


\ResidentialInfo_Mapper


.xml]’

; nested exception is org.apache.ibatis.builder.BuilderException: Error creating document instance.  Cause:

java.lang.IllegalArgumentException: protocol = http host = null

at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:359)

at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:108)

at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1481)

at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1226)

at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:543)

at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)

at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)

at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)

at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)

at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202)

at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:120)

at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:678)

at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:520)

at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:444)

at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:326)

at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:107)

at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4842)

at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5303)

at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:147)

at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1407)

at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1397)

at java.util.concurrent.FutureTask.run(Unknown Source)

at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)

at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)

at java.lang.Thread.run(Unknown Source)

  1. 原因分析

    1. 出现该异常的主要原因是mybatis在调用mapper文件的协议头时,获取不到指定连接;
  2. 处理步骤

    1. 我的协议头是这样的:

<!DOCTYPEmapper PUBLIC “—mybatis.org–DTD Mapper 3.0–EN””http:–mybatis.org/dtd/mybatis-3-mapper.dtd”>

  1. 更改后的正确协议头:将“–”更改为“//”

    1. <!DOCTYPE mapper PUBLIC “-//mybatis.org//DTD Mapper 3.0//EN” ”

      http://mybatis.org/dtd/mybatis-3-mapper.dtd

      “>



版权声明:本文为qq_33301113原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。