微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

[Java web]Spring+Struts2+Hibernate整合过程2

摘要

上篇文章介绍了一种整合方式,不妨就叫做有hibernate配置文件的方式,这里介绍一种不用hibernate.cfg.xml的一种配置方式,为了方便,就仍在上篇的demo中,继续修改了。

步骤

因为hibernate.cfg.xml中配置的是数据库的相关配置,以及映射关系,关于这部分配置完全可以在applicationContext.xml中进行整合。数据库的4要素也可以单独提取到jdbc.properties文件中。

在src目录下新建jdbc.properties文件,将4要素配置上

jdbc.driverClass=MysqL.jdbc.Driver jdbc.jdbcUrl=jdbc:MysqL: jdbc.user==abcd

在applicationContext.xml引入该文件即可

修改后配置如下

spring-beans.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" factorybean"> figLocation" value="classpath:hibernate.cfg.xml"> 属性文件 property-placeholder sspath:jdbc.properties" factorybean" org.hibernate.dialect.MysqLDialect sql"true update sql"true 添加其他的配置,这里不再写了,可以参考hibernate.cfg.xml中的配置 com/ssh/domain/User.hbm.xml cope设置为prototype cope

<span style="color: #0000ff;"></<span style="color: #800000;">beans<span style="color: #0000ff;">>

这时完全可以把hibernate.cfg.xml删除

测试结果

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐