关于Spring/Hibernate 3.x升级4.x的小问题

情景:

  之前版本 现在版本
JDK 1.7 1.8
Tomcat v7.0 v8.0
Spring 3.x 4.x
Hibernate 3.x 4.x
MySQL 忘了 5.1.53

分析:

如果升级版本错误,就是这几处的问题。

问题1:

我使用Spring3.X --- jdk8----出现了如下问题:

java.lang.IllegalArgumentException
     org.springframework.asm.ClassReader.<init>(Unknown Source)
     org.springframework.asm.ClassReader.<init>(Unknown Source)
     org.springframework.asm.ClassReader.<init>(Unknown Source)
原因:Spring3.X --- jdk8不兼容
解决:

  一:把jdk版本换成1.7 or 1.7以下

  二:使用spring-4.0-RELEASE及以上版本

问题2:

Spring4.x的事务管理没有起作用。

解决:(以下是我碰到的问题解决方法,当然还有其它解决方法我没有列出)

    <!-- 使用FactoryBean创建Spring得到 SessionFactory -->
    <bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
          <!-- 把hibernate.cfg.xml文件中的配置信息注入进来,从而可以删掉配置文件-->
          <property name="dataSource" ref="dataSource"></property>
          <property name="hibernateProperties">
                  <props>
                      <prop key="hibernate.dialect">org.hibernate.dialect.MySQL5InnoDBDialect</prop>
                      <prop key="javax.persistence.validation.mode">none</prop>
                      <prop key="hibernate.show_sql">true</prop>
                      <prop key="hibernate.format_sql">true</prop>
                      <prop key="hibernate.hbm2ddl.auto">update</prop>
                      <prop key="hibernate.current_session_context_class">org.springframework.orm.hibernate4.SpringSessionContext</prop>
                  </props>
          </property>
          <property name="mappingLocations" value="classpath:king/domain/*.hbm.xml"></property>
    </bean>

①如果你的MySQL的版本改动了,这个属性也可能会随着改动。

原因:

如果表的类型为MyISAM,则sping里配置的事务是不起作用的,所以要使用InnoDB类型的表,因为这个类型的表才支持事务。

②3.x时这一处我们都会写thread,4.x要写成SpringSessionContext。


原文地址:https://www.cnblogs.com/kingofkai/p/6142353.html