2 u013465293 u013465293 于 2017.09.01 17:08 提问

spring+activiti+mybatis 配置报错问题。 2C

报错为一个xml配置。但是根本没有这个when的配置。
我项目的xml也没有900多行,最多200行。
这是报的哪的问题?

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'processEngine': FactoryBean threw exception on object creation; nested exception is org.activiti.engine.ActivitiException: Error while building ibatis SqlSessionFactory: Error parsing SQL Mapper Configuration. Cause: org.apache.ibatis.builder.BuilderException: Error creating document instance. Cause: org.xml.sax.SAXParseException; lineNumber: 936; columnNumber: 24; 元素类型为 "when" 的内容必须匹配 "(include|trim|where|set|foreach|choose|if)"。
at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.doGetObjectFromFactoryBean(FactoryBeanRegistrySupport.java:175)
at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.getObjectFromFactoryBean(FactoryBeanRegistrySupport.java:103)
at org.springframework.beans.factory.support.AbstractBeanFactory.getObjectForBeanInstance(AbstractBeanFactory.java:1634)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:254)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:372)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1173)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1067)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:513)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483)
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:197)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:761)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:866)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:542)
at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:443)
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:325)
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:107)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:5118)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5634)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:145)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1571)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1561)
at java.util.concurrent.FutureTask.run(FutureTask.java:262)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:745)
Caused by: org.activiti.engine.ActivitiException: Error while building ibatis SqlSessionFactory: Error parsing SQL Mapper Configuration. Cause: org.apache.ibatis.builder.BuilderException: Error creating document instance. Cause: org.xml.sax.SAXParseException; lineNumber: 936; columnNumber: 24; 元素类型为 "when" 的内容必须匹配 "(include|trim|where|set|foreach|choose|if)"。
at org.activiti.engine.impl.cfg.ProcessEngineConfigurationImpl.initSqlSessionFactory(ProcessEngineConfigurationImpl.java:922)
at org.activiti.engine.impl.cfg.ProcessEngineConfigurationImpl.init(ProcessEngineConfigurationImpl.java:642)
at org.activiti.engine.impl.cfg.ProcessEngineConfigurationImpl.buildProcessEngine(ProcessEngineConfigurationImpl.java:612)
at org.activiti.spring.SpringProcessEngineConfiguration.buildProcessEngine(SpringProcessEngineConfiguration.java:65)
at org.activiti.spring.ProcessEngineFactoryBean.getObject(ProcessEngineFactoryBean.java:60)
at org.activiti.spring.ProcessEngineFactoryBean.getObject(ProcessEngineFactoryBean.java:32)
at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.doGetObjectFromFactoryBean(FactoryBeanRegistrySupport.java:168)
... 28 more
Caused by: org.apache.ibatis.builder.BuilderException: Error parsing SQL Mapper Configuration. Cause: org.apache.ibatis.builder.BuilderException: Error creating document instance. Cause: org.xml.sax.SAXParseException; lineNumber: 936; columnNumber: 24; 元素类型为 "when" 的内容必须匹配 "(include|trim|where|set|foreach|choose|if)"。
at org.apache.ibatis.builder.xml.XMLConfigBuilder.parseConfiguration(XMLConfigBuilder.java:106)
at org.apache.ibatis.builder.xml.XMLConfigBuilder.parse(XMLConfigBuilder.java:89)
at org.activiti.engine.impl.cfg.ProcessEngineConfigurationImpl.parseMybatisConfiguration(ProcessEngineConfigurationImpl.java:954)
at org.activiti.engine.impl.cfg.ProcessEngineConfigurationImpl.initMybatisConfiguration(ProcessEngineConfigurationImpl.java:937)
at org.activiti.engine.impl.cfg.ProcessEngineConfigurationImpl.initSqlSessionFactory(ProcessEngineConfigurationImpl.java:918)
... 34 more
Caused by: org.apache.ibatis.builder.BuilderException: Error creating document instance. Cause: org.xml.sax.SAXParseException; lineNumber: 936; columnNumber: 24; 元素类型为 "when" 的内容必须匹配 "(include|trim|where|set|foreach|choose|if)"。
at org.apache.ibatis.parsing.XPathParser.createDocument(XPathParser.java:253)
at org.apache.ibatis.parsing.XPathParser.(XPathParser.java:122)
at org.apache.ibatis.builder.xml.XMLMapperBuilder.(XMLMapperBuilder.java:74)
at org.apache.ibatis.builder.xml.XMLConfigBuilder.mapperElement(XMLConfigBuilder.java:316)
at org.apache.ibatis.builder.xml.XMLConfigBuilder.parseConfiguration(XMLConfigBuilder.java:104)
... 38 more
Caused by: org.xml.sax.SAXParseException; lineNumber: 936; columnNumber: 24; 元素类型为 "when" 的内容必须匹配 "(include|trim|where|set|foreach|choose|if)"。
at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(ErrorHandlerWrapper.java:198)
at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.error(ErrorHandlerWrapper.java:134)
at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:437)
at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:368)
at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:325)
at com.sun.org.apache.xerces.internal.impl.dtd.XMLDTDValidator.handleEndElement(XMLDTDValidator.java:1994)
at com.sun.org.apache.xerces.internal.impl.dtd.XMLDTDValidator.endElement(XMLDTDValidator.java:879)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanEndElement(XMLDocumentFragmentScannerImpl.java:1782)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:2973)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:606)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:510)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:848)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:777)
at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:141)
at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(DOMParser.java:243)
at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:347)
at org.apache.ibatis.parsing.XPathParser.createDocument(XPathParser.java:251)
... 42 more

6个回答

u013465293
u013465293   2017.09.01 17:09

application.xml配置
<?xml version="1.0" encoding="UTF-8"?>
xmlns:context="http://www.springframework.org/schema/context"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx" xmlns:p="http://www.springframework.org/schema/p"
xmlns:util="http://www.springframework.org/schema/util" xmlns:jdbc="http://www.springframework.org/schema/jdbc"
xmlns:cache="http://www.springframework.org/schema/cache"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/util
http://www.springframework.org/schema/util/spring-util.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd">

<!-- 自动扫描spring注解,排除springmvc已扫描的Controller注解 -->
<context:component-scan base-package="com.ln.web">
    <context:exclude-filter type="annotation"
        expression="org.springframework.stereotype.Controller" />
</context:component-scan>

<!-- mybatis与spring整合 -->
<!-- 引入配置文件 -->
<bean id="propertyConfigurer"
    class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    <property name="locations">
        <list>
            <value>classpath*:application.properties</value>
        </list>
    </property>
</bean>
<!-- dataSource 配置 -->
<bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource"
    init-method="init" destroy-method="close">
    <!-- 基本属性 url、user、password -->
    <property name="driverClassName" value="${jdbc.driver}"></property>
    <property name="url" value="${jdbc.url}" />
    <property name="username" value="${jdbc.username}" />
    <property name="password" value="${jdbc.password}" />

    <!-- 配置初始化大小、最小、最大 -->
    <property name="initialSize" value="${ds.initialSize}" />
    <property name="minIdle" value="${ds.minIdle}" />
    <property name="maxActive" value="${ds.maxActive}" />

    <!-- 配置获取连接等待超时的时间 -->
    <property name="maxWait" value="${ds.maxWait}" />

    <!-- 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒 -->
    <property name="timeBetweenEvictionRunsMillis" value="${ds.timeBetweenEvictionRunsMillis}" />

    <!-- 配置一个连接在池中最小生存的时间,单位是毫秒 -->
    <property name="minEvictableIdleTimeMillis" value="${ds.minEvictableIdleTimeMillis}" />

</bean>
<!-- 配置sqlSessionFactory -->
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
    <property name="configLocation" value="classpath:mybatis-config.xml" />
    <property name="dataSource" ref="dataSource" />
    <property name="mapperLocations" value="classpath:com/ln/web/dao/*.xml"></property>
</bean>

<!-- 对dataSource 数据源进行事务管理 -->
<bean id="transactionManager"
    class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
    <property name="dataSource" ref="dataSource"></property>
</bean>

<!-- 扫描mapper接口 -->
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
    <property name="basePackage" value="com.ln.web.dao"></property>
    <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"></property>
</bean>

<!-- 事务管理 通知 -->

tx:attributes
<!-- 对insert,update,delete 开头的方法进行事务管理,只要有异常就回滚 -->



<!-- select,count开头的方法,开启只读,提高数据库访问性能 -->


<!-- 对其他方法 使用默认的事务管理 -->

/tx:attributes
/tx:advice
<!-- 启用对事务注解的支持 -->

<!-- 配置多个数据源 -->
<bean id="dataSource2" class="com.alibaba.druid.pool.DruidDataSource"
    init-method="init" destroy-method="close">
    <!-- 基本属性 url、user、password -->
    <property name="url" value="${jdbc.url_2}" />
    <property name="username" value="${jdbc.username_2}" />
    <property name="password" value="${jdbc.password_2}" />

    <!-- 配置初始化大小、最小、最大 -->
    <property name="initialSize" value="${ds.initialSize}" />
    <property name="minIdle" value="${ds.minIdle}" />
    <property name="maxActive" value="${ds.maxActive}" />

    <!-- 配置获取连接等待超时的时间 -->
    <property name="maxWait" value="${ds.maxWait}" />

    <!-- 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒 -->
    <property name="timeBetweenEvictionRunsMillis" value="${ds.timeBetweenEvictionRunsMillis}" />

    <!-- 配置一个连接在池中最小生存的时间,单位是毫秒 -->
    <property name="minEvictableIdleTimeMillis" value="${ds.minEvictableIdleTimeMillis}" />
</bean>
<!-- 配置sqlSessionFactory -->
<bean id="sqlSessionFactory2" class="org.mybatis.spring.SqlSessionFactoryBean">
    <property name="configLocation" value="classpath:mybatis-config-2.xml" />
    <property name="dataSource" ref="dataSource2" />
    <property name="mapperLocations" value="classpath:com/ln/web/db2/dao/*.xml"></property>
</bean>
<!-- 对dataSource 数据源进行事务管理 -->
<bean id="transactionManager2"
    class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
    <property name="dataSource" ref="dataSource2"></property>
</bean>

<!-- 事务管理 通知 -->
<tx:advice id="txAdvice2" transaction-manager="transactionManager2">
    <tx:attributes>
        <!-- 对insert,update,delete 开头的方法进行事务管理,只要有异常就回滚 -->
        <tx:method name="insert*" propagation="REQUIRED" rollback-for="java.lang.Throwable"/>
        <tx:method name="update*" propagation="REQUIRED" rollback-for="java.lang.Throwable"/>
        <tx:method name="delete*" propagation="REQUIRED" rollback-for="java.lang.Throwable"/>
        <!-- select,count开头的方法,开启只读,提高数据库访问性能 -->
        <tx:method name="select*" read-only="true"/>
        <tx:method name="count*" read-only="true"/>
        <!-- 对其他方法 使用默认的事务管理 -->
        <tx:method name="*"/>
    </tx:attributes>
</tx:advice>
      <!-- 事务 aop 配置 -->
<aop:config>
    <aop:pointcut id="serviceMethods" expression="execution(* com.simple.web.service..*(..))"/>
    <aop:advisor advice-ref="txAdvice" pointcut-ref="serviceMethods"/>
    <aop:advisor advice-ref="txAdvice2" pointcut-ref="serviceMethods"/>
</aop:config>
    <!-- 启用对事务注解的支持 -->
<tx:annotation-driven transaction-manager="transactionManager2" />
<!-- 扫描mapper接口 -->
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
    <property name="basePackage" value="com.ln.web.db2.dao"></property>
    <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory2"></property>
</bean>

u013465293
u013465293   2017.09.01 17:10

activiti配置
activiti.cfg.xml:
<?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">  








<!-- 配置数据源,和系统使用同一个数据源 -->

      <property name="dataSource" ref="activitiDataSource" />  

      <property name="databaseSchemaUpdate" value="true" />  

      <property name="jobExecutorActivate" value="false" />  

      <!-- 统一的事务管理 -->  

      <property name="transactionManager" ref="transactionManager" />  

      <property name="activityFontName"  value="宋体" />  

      <property name="labelFontName"  value="宋体" />  

  <property name="processEngineConfiguration" ref="processEngineConfiguration" />  










u013465293
u013465293   2017.09.01 17:12

activiti配置是这样,上面的错了:
<?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">  



<!-- 配置数据源,和系统使用同一个数据源 -->

      <property name="dataSource" ref="dataSource" />  

      <property name="databaseSchemaUpdate" value="true" />  

      <property name="jobExecutorActivate" value="false" />  

      <!-- 统一的事务管理 -->  

      <property name="transactionManager" ref="transactionManager" />  

      <property name="activityFontName"  value="宋体" />  

      <property name="labelFontName"  value="宋体" />  

  <property name="processEngineConfiguration" ref="processEngineConfiguration" />  










ying_zcx
ying_zcx   2017.09.01 17:17

你有写Mybatis映射文件吗?

kelei2015
kelei2015   2017.09.01 17:28

图片说明Mapper.xml文件中有错误

u013465293
u013465293 回复e206842: 把activiti的东西注释掉,项目跑起来没有问题的
3 个月之前 回复
u013465293
u013465293 我的demo项目中只有一个mybatis映射文件,最多也就100多行,没有936行啊
3 个月之前 回复
u013465293
u013465293   2017.09.04 10:34

解决了,代码配置都没有问题。
spring版本:4.3.8
activiti版本:5.22.0
版本冲突问题。

activiti版本用5.15.1版本没有问题。

Csdn user default icon
上传中...
上传图片
插入图片