struts2+spring3+hibernate3整合(二)转载
3.1 導入hibernate3.3的包
在這里,由于我用的是myeclipse8.5,所以我是采用IDE自動導入的方法.我懶.途中的hibernate配置一切按照IDE導入的正常程序進行.
當然,我有3個表:user,address,user_address
從字面上理解是user與address是一對多關系,但由于我要測試多對多,所以,這里是多對多關系,不然也不會有個中間表出現了.
3.2? 配置spring3的applicationContext.xml文件:
view plaincopy to clipboardprint?
<!-- 配置hibernate DataSource -->?
??? <bean id="DataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">?
??????? <property name="driverClassName" value="com.mysql.jdbc.Driver"/>?
??????? <property name="url" value="jdbc:mysql://localhost:3306/test"/>?
??????? <property name="username" value="root"/>?
??????? <property name="password" value="oookkk"/>?
??????? <!-- 連接池啟動時的初始值 -->?
??????? <property name="initialSize" value="1"/>?
??????? <!-- 連接池的最大值 -->?
??????? <property name="maxActive" value="500"/>?
??????? <!-- 最大空閑值.當經過一個高峰時間后,連接池可以慢慢將已經用不到的連接慢慢釋放一部分,一直減少到maxIdle為止 -->?
??????? <property name="maxIdle" value="3"/>?
??????? <!--? 最小空閑值.當空閑的連接數少于閥值時,連接池就會預申請去一些連接,以免洪峰來時來不及申請 -->?
??????? <property name="minIdle" value="2"/>?
??? </bean>?
??????
??? <!-- 配置hibernate的sessionFactory -->?
??? <bean id="SessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">?
??? <property name="dataSource" ref="DataSource"/>?
??? <property name="mappingResources">?
????? <list>?
??????? <value>test/hibernate/User.hbm.xml</value>?
??????? <value>test/hibernate/Address.hbm.xml</value>?
????? </list>?
??? </property>?
??? <property name="hibernateProperties">?
????? <value>?
??????????
??????? hibernate.dialect=org.hibernate.dialect.MySQL5Dialect??
??????? hibernate.hbm2ddl.auto=update?
??????? hibernate.show_sql=false?
??????? hibernate.format_sql=false?
??????? hibernate.cache.use_second_level_cache=true?
??????? hibernate.cache.use_query_cache=false?
??????? hibernate.cache.provider_class=org.hibernate.cache.EhCacheProvider??
????? </value>?
??? </property>?
? </bean>?
轉載于:https://www.cnblogs.com/dynasty/archive/2011/05/09/2040767.html
總結
以上是生活随笔為你收集整理的struts2+spring3+hibernate3整合(二)转载的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: java IO接口
- 下一篇: 如何更好地挖掘泰山的文化内涵和旅游价值?