Ibatis - 使用名称sqlMapClient创建bean时出错

时间:2016-02-24 15:13:19

标签: java spring hibernate spring-mvc ibatis

我尝试将大型企业应用从2.0.8迁移到3.2。我按照迁移指南进行了编译,并编译了所有项目文件。但是在Spring Context开始时我得到了错误。

[24/02/16 13:50:26:524 CET] 0000000d ContextLoader E org.springframework.web.context.ContextLoader initWebApplicationContext Context initialization failed
                             org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionInterceptor' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Cannot resolve reference to bean 'usuariosBO' while setting bean property 'servicio'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'usuariosBO' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Cannot resolve reference to bean 'usuariosDAO' while setting bean property 'usuariosDAO'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'usuariosDAO' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Cannot resolve reference to bean 'sqlMapClient' while setting bean property 'sqlMapClient'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sqlMapClient' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Invocation of init method failed; nested exception is java.lang.NoSuchMethodError: com/ibatis/sqlmap/engine/builder/xml/SqlMapConfigParser.parse(Ljava/io/InputStream;Ljava/util/Properties;)Lcom/ibatis/sqlmap/client/SqlMapClient;

和(我也反编译iBatis jar并在类SqlMapConfigParse中找到方法解析)

Caused by: java.lang.NoSuchMethodError: com/ibatis/sqlmap/engine/builder/xml/SqlMapConfigParser.parse(Ljava/io/InputStream;Ljava/util/Properties;)Lcom/ibatis/sqlmap/client/SqlMapClient;

我的applicationContext.xml位于WEB-INF

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN 2.0//EN"
"http://www.springframework.org/dtd/spring-beans-2.0.dtd">

<beans>

<bean id="sessionInterceptor" class="app.web.filters.SessionInterceptor">
    <property name="active" value="true"/>
    <property name="intentosConexion" value="2"/>
    <property name="servicio" ref="usuariosBO"/>    
</bean>


<bean id="cacheInterceptor" class="app.web.filters.CacheInterceptor">
    <property name="active" value="true"/>
</bean>

<bean id="localeInterceptor" class="app.web.filters.LocaleInterceptor">
    <property name="active" value="true"/>
</bean>

<bean id="urlInterceptor" class="app.web.filters.UrlInterceptor">
    <property name="active" value="true"/>
    <property name="servicio" ref="usuariosBO"/>
</bean>


<bean id="messageSource" class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
    <property name="alwaysUseMessageFormat" value="true"/>
    <property name="useCodeAsDefaultMessage" value="true"/>
    <property name="defaultEncoding" value="ISO-8859-1"/>
    <property name="basenames">
        <list>
            <value>WEB-INF/classes/app/utils/message</value>
            <value>WEB-INF/classes/app/utils/reports/gor</value>
        </list>
    </property>
</bean>

<bean id="localeResolver" class="org.springframework.web.servlet.i18n.SessionLocaleResolver"/>


<bean id="validatorFactory" class="org.springmodules.validation.commons.DefaultValidatorFactory">
    <property name="validationConfigLocations">
      <list>
        <value>WEB-INF/utils/validator-rules.xml</value>
        <value>WEB-INF/validation.xml</value>
      </list>
    </property>
</bean>

<bean id="beanValidator" class="org.springmodules.validation.commons.DefaultBeanValidator">
    <property name="validatorFactory" ref="validatorFactory"/>
</bean>

<bean id="tilesConfigurer" class="org.springframework.web.servlet.view.tiles2.TilesConfigurer">
    <property name="definitions">
        <list>
            <value>WEB-INF/tiles-defs.xml</value>
        </list>
    </property>
</bean>

<bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
    <property name="jndiName">
        <value>jdbc/HSGRTE</value> 
    </property>
</bean>

<bean id="sqlMapClient" class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
    <property name="configLocation" value="WEB-INF/sqlmap-config.xml"/>
    <property name="dataSource" ref="dataSource"/>
</bean>

<bean id="usuariosBO" class="app.service.impl.UsuariosImplBO">
    <property name="usuariosDAO" ref="usuariosDAO"/>
</bean>

<bean id="usuariosDAO" class="app.repository.impl.UsuariosImplDAO">
    <property name="sqlMapClient" ref="sqlMapClient"/>
</bean>

<bean name="exampleAfterAdvice" class="app.aops.ExampleAfterAdvice">
</bean> 
<bean name="gestionEnviosAfterAdvice" class="app.aops.GestionEnviosAfterAdvice">
    <property name="applicationContextBean" ref="applicationContextBean"/>
</bean>


<bean name="applicationContextBean" class="app.domain.ApplicationContextBean">
</bean>

位于WEB-INF

中的sqlmap-config.xml
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE sqlMapConfig PUBLIC "-//iBATIS.com//DTD SQL Map Config 2.0//EN"  "utils/sql-map-config-2.dtd">
<sqlMapConfig>

<settings
        cacheModelsEnabled="true"
        useStatementNamespaces="true"
        maxRequests="512"
        maxSessions="128"
        maxTransactions="32"
        lazyLoadingEnabled="false"
        enhancementEnabled="true"/>

<typeHandler javaType="java.sql.ResultSet"
                     callback="com.ibatis.sqlmap.engine.mapping.sql.dynamic.elements.RefTypeHandler"/>


<sqlMap resource="app/maps/ListaDistribucion.xml"/>
<sqlMap resource="app/maps/MapaCobertura.xml"/>
<sqlMap resource="app/maps/Clientes.xml"/>
<sqlMap resource="app/maps/Usuarios.xml"/>

</sqlMapConfig>

App有以下jar:

  • ibatis2-的SqlMap-2.1.7.597
  • ibatis2-共2.1.7.597

所有必需的spring依赖项,版本 - 3.2.16.RELEASE

服务器是websphere 7.0

我猜iBatis中的问题,但我不知道是什么问题。

我正在寻求帮助,有什么想法吗?

提前谢谢。

1 个答案:

答案 0 :(得分:0)

解决。问题是spring-orm-3.2.16.RELEASE,类SqlMapClientFactoryBean有不同的方法&#34; buildSqlMapClient&#34;。

解决方案:将jar替换为spring-orm-2.5.jar

如果您知道其他解决方案,请告诉我。