有些教程比较老,可是版本更新不等人,基于马士兵老师小例子,自己重新引用了新的包,调试确实有点烦人,但是通过英文文档和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 
		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的开发者不仅拿着计算机的学位,还拿着音乐博士学位,真厉害。





   

 

相关文章:

  • 2021-08-12
  • 2021-08-08
  • 2021-11-23
  • 2021-05-21
  • 2022-12-23
  • 2021-10-25
  • 2022-01-25
  • 2021-05-23
猜你喜欢
  • 2022-12-23
  • 2022-01-10
  • 2021-07-16
  • 2022-12-23
  • 2021-07-05
  • 2021-12-03
  • 2022-12-23
相关资源
相似解决方案