zoukankan      html  css  js  c++  java
  • struts2.3+spring3.2+hibernate4.2例子


       有些教程比较老,可是版本更新不等人,基于马士兵老师小例子,自己重新引用了新的包,调试确实有点烦人,但是通过英文文档和google解决问题。官网的更新超快,struts2.3+spring3.2+hibernate4.2很快更新至此,不久又有spring4,其实怎么变都差不多,多一点东西。


         给个资源,struts2.3+spring3.2+hibernate4.2整合包:http://download.csdn.net/detail/iaiti/6234853


         小例子:http://download.csdn.net/detail/iaiti/6240459

       Hibernate4没了HibernateTemplate令我一头雾水,Hibernate4已经可以完全实现事务管理,所以还是用你的session吧。


        MySql建新的数据库,spring;建一个新表:user

    CREATE TABLE user (
      id int NOT NULL auto_increment,
      username varchar(40) default NULL,
      password varchar(30) default NULL,
      PRIMARY KEY  (`id`)
    ) ;


    org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'sessionFactory' is defined 的问题:

         少的bean在beans.xml上补上:

    <bean id="sessionFactory"
    		class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
    </bean>



    由于template的舍弃,用了session的load方法,接下来就是经典的lazy问题,此时需要延时加载到jsp上,写一个filter:

    <filter>
    		<filter-name>openSessionInView</filter-name>
    		<filter-class>org.springframework.orm.hibernate4.support.OpenSessionInViewFilter</filter-class>
    	
    	</filter>
    	
    	<filter-mapping>
    		<filter-name>openSessionInView</filter-name>
    		<url-pattern>/*</url-pattern>
    	</filter-mapping> 


    不然就不要load用get,因为session要关的。


    接着又有经典错误出现: Connection cannot be null when 'hibernate.dialect' not set,写个Hibernate.properties解决。应该是util的包自己写了个static的sessionFactory冲突,个人猜测。


           得知spring的开发者不仅拿着计算机的学位,还拿着音乐博士学位,真厉害。





       

  • 相关阅读:
    昨晚值班将发dla的程序改好后放入正式环境
    本来今天打算不带电脑去值班
    有时候你会觉得,你的不真实让人怀疑,自己却非常尴尬
    其实对于公司的事情分布,我是昨天没有干什么
    异常处理
    反射及内置方法
    绑定方法与非绑定方法
    面向对象之多态
    面向对象之封装
    面向对象三大特性
  • 原文地址:https://www.cnblogs.com/suncoolcat/p/3313070.html
Copyright © 2011-2022 走看看