求写hibernate写标注时与spring做集成的完整配置 求写hibernate写标注时与spring做集成的完整配置分别写在hibernate.cfg.xml和applicationContext.xml或者全写在applicationContext.xml都可以 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 springside非常完美www.springside.org.cn springside万一项目组里没人会用,而且我也不会用 <?xml version="1.0" encoding="UTF-8"?><!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd"><beans> <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"> <property name="driverClassName" value="com.microsoft.sqlserver.jdbc.SQLServerDriver"> </property> <property name="url" value="jdbc:sqlserver://localhost:1433;databaseName=BookShop"> </property> <property name="username" value="sa"></property> <property name="password" value="sasa"></property> </bean> <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"> <property name="dataSource"> <ref bean="dataSource" /> </property> <property name="hibernateProperties"> <props> <prop key="hibernate.dialect"> org.hibernate.dialect.SQLServerDialect </prop> </props> </property> <property name="mappingResources"> <list> <value>com/bookshop/entity/BookStoreInfoZ.hbm.xml</value> <value>com/bookshop/entity/BookStoreInfoA.hbm.xml</value> <value>com/bookshop/entity/PayCashInfo.hbm.xml</value> <value>com/bookshop/entity/RecRetBookInfo.hbm.xml</value> <value>com/bookshop/entity/SendRetBookInfo.hbm.xml</value> <value>com/bookshop/entity/SendSubInfo.hbm.xml</value> <value>com/bookshop/entity/DepreInfo.hbm.xml</value> <value> com/bookshop/entity/ReceiveSubInfo.hbm.xml</value> <value>com/bookshop/entity/BuyerInfo.hbm.xml</value> <value>com/bookshop/entity/PublisherInfo.hbm.xml</value> <value>com/bookshop/entity/BookInfo.hbm.xml</value> <value>com/bookshop/entity/ReceiveCashInfo.hbm.xml</value> <value>com/bookshop/entity/InstoreInfo.hbm.xml</value> <value>com/bookshop/entity/ProviderInfo.hbm.xml</value> <value>com/bookshop/entity/TypeInfo.hbm.xml</value> <value>com/bookshop/entity/OutStoreInfoA.hbm.xml</value> <value>com/bookshop/entity/OutStoreInfoZ.hbm.xml</value> <value>com/bookshop/entity/SendInfo.hbm.xml</value> <value>com/bookshop/entity/InnerOutInfo.hbm.xml</value> <value>com/bookshop/entity/UserInfo.hbm.xml</value> <value>com/bookshop/entity/MainSendSubInfo.hbm.xml</value> <value>com/bookshop/entity/MainReceiveSubInfo.hbm.xml</value> <value>com/bookshop/entity/MainOutStoreInfoA.hbm.xml</value> <value>com/bookshop/entity/MainRecRetBookInfo.hbm.xml</value> <value>com/bookshop/entity/MainSend.hbm.xml</value> <value>com/bookshop/entity/MainSendRetBookInfo.hbm.xml</value> <value>com/bookshop/entity/MainDepreInfo.hbm.xml</value> </list> </property> </bean> 这是我用hibernate3.1,spring 1.x 配置的。不知道能不能帮助你。能的话。分就给我吧。。 applicationContext.xml 配置文件<?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd"> <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"> <property name="driverClassName"> <value>com.mysql.jdbc.Driver</value> </property> <property name="url"> <value>jdbc:mysql://localhost:3306/los</value> </property> <property name="username"> <value>root</value> </property> <property name="password"> <value>root</value> </property> </bean> <!--SessionFactory --> <bean id="mySessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"> <property name="dataSource"> <ref bean="dataSource" /> </property> <property name="mappingResources"> <list> <value>com\domain\Pricings.hbm.xml</value> <value>com\domain\Users.hbm.xml</value> <value>com\domain\UsersService.hbm.xml</value> </list> </property> <property name="hibernateProperties"> <props> <prop key="hibernate.dialect"> org.hibernate.dialect.MySQLDialect </prop> <prop key="hibernate.show_sql">true</prop> <prop key="hibernate.hbm2ddl.auto">update</prop> </props> </property> </bean> <!-- transactionManager --> <bean id="myTransactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager"> <property name="sessionFactory" ref="mySessionFactory"></property> </bean> <!-- dao --> <bean id="priDAO" class="com.dao.PricingsDAOImpl"> <property name="sessionFactory" ref="mySessionFactory"></property> </bean> <!-- target --> <bean id="priServiceTarget" class="com.service.PricingsServiceImpl"> <property name="priDAO" ref="priDAO"></property> </bean> <!-- transaction proxy --> <bean id="pricingsService" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean"> <property name="target" ref="pricingsServiceTarget"></property> <property name="transactionManager" ref="myTransactionManager"></property> <property name="transactionAttributes"> <props> <prop key="*">PROPAGATION_REQUIRED</prop> </props> </property> </bean> <!-- 资费action --> <bean id="abstract" abstract="true" scope="prototype"> <property name="pricingsService" ref="pricingsService" /> </bean> <bean name="/feeShowAll" class="com.action.PricingsAction" parent="abstract"/> <bean name="/feeAdd" class="com.action.PricingsAction" parent="abstract" /> <bean name="/feeUpdateForm" class="com.action.PricingsAction" parent="abstract"/> <bean name="/feeForUpdate" class="com.action.PricingsAction" parent="abstract"/> <bean name="/feeUpdate" class="com.action.PricingsAction" parent="abstract" /> <bean name="/feeShowDelete" class="com.action.PricingsAction" parent="abstract" /> <bean name="/feeDelete" class="com.action.PricingsAction" parent="abstract" /> </beans> <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"> <property name="configLocation" value="classpath:hibernate.cfg.xml"> </property> </bean> <bean id="BaseServices" class="org.liuhong.work.uitl.BaseService"> <property name="sessionFactory" ref="sessionFactory" /> </bean> <bean id="UserServices" parent="txProxyTemplate"> <property name="target"> <bean class="org.liuhong.work.services.UserServiceImpl"> <property name="services" ref="BaseServices" /> </bean> </property> </bean> <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager"> <property name="sessionFactory"> <ref bean="sessionFactory" /> </property> </bean> <bean id="txProxyTemplate" abstract="true" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean"> <property name="transactionManager"> <ref bean="transactionManager" /> </property> <property name="transactionAttributes"> <props> <prop key="save*"> PROPAGATION_REQUIRED,-java.lang.Exception </prop> <prop key="update*">PROPAGATION_REQUIRED</prop> <prop key="delete*">PROPAGATION_REQUIRED</prop> <prop key="*">PROPAGATION_REQUIRED</prop> </props> </property> </bean></beans> 这个我觉得看了 没用,还有web.xml里的 <?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:jee="http://www.springframework.org/schema/jee" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-2.5.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd" default-lazy-init="true"> <description>UTS For Spring FrameWork 1.1</description> <!--配置数据源JDBC--> <bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> <property name="locations"> <list> <value>classpath:jdbc.properties</value> </list> </property> </bean> <!-- 使用annotation 自动注册bean,并保证@Required,@Autowired的属性被注入 --> <!-- --> <context:component-scan base-package="com.train" /> <bean id="mydatasource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"> <property name="driverClassName"> <value>com.microsoft.sqlserver.jdbc.SQLServerDriver</value> </property> <property name="url"> <value>${jdbc.url}</value> </property> <property name="username"> <value>${jdbc.username}</value> </property> <property name="password"> <value>${jdbc.password}</value> </property> <property name="maxActive"> <value>100</value> </property> <property name="maxIdle"> <value>100</value> </property> <property name="maxWait"> <value>120000</value> </property> <property name="poolPreparedStatements" value="true" /> <property name="defaultAutoCommit"> <value>false</value> </property> </bean> <!--建立Hibernate SessionFactory--> <bean id="mySessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean"> <property name="dataSource"> <ref local="mydatasource"/> </property> <property name="namingStrategy"> <bean class="org.hibernate.cfg.ImprovedNamingStrategy" /><!-- 命名规范如:OrderItem:order_item --> </property> <property name="hibernateProperties"> <props> <prop key="hibernate.dialect">org.hibernate.dialect.SQLServerDialect</prop> <prop key="hibernate.show_sql">true</prop> <prop key="hibernate.jdbc.fetch_size">50</prop> <prop key="hibernate.jdbc.batch_size">100</prop> <prop key="hibernate.cache.use_query_cache">true</prop> <!-- <prop key="hibernate.hbm2ddl.auto">update</prop> 自动和数据库比较更改数据库 --> <prop key="hibernate.cache.provider_class"><!-- 缓存接口类 --> org.hibernate.cache.EhCacheProvider </prop> <prop key="hibernate.cache.provider_configuration_file_resource_path"> /ehcache/ehcache-hibernate-local.xml </prop> </props> </property> <property name="packagesToScan"> <list> <value>com.train.entity</value> <value>com.train.entity.*</value> </list> </property> </bean> <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager"> <property name="sessionFactory"> <ref local="mySessionFactory" /> </property> </bean> <!-- 使用annotation定义事务 --> <tx:annotation-driven transaction-manager="transactionManager" /> </beans> 选项左右切换 使用openSessionInViewFilter出现could not initialize proxy - no Session异常 搞struts2的必看,偶尔发现的一个东西 谁帮我反编译这个class文件 Struts标签问题 javamail. 金蝶Java面试回来,郁闷死了。。。 resin 3.0.8 端口80,启动正常,为什么访问确显示404错误,resin3.0.8好像没有监听.. 来谈谈你做过的网站项目的框架设计 列表页没有数据,急!!! 高手请帮忙!在XML文件的某个节点中如何使用XPath方法查询? 两个问题
www.springside.org.cn
万一项目组里没人会用,而且我也不会用
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd"><beans>
<bean id="dataSource"
class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName"
value="com.microsoft.sqlserver.jdbc.SQLServerDriver">
</property>
<property name="url"
value="jdbc:sqlserver://localhost:1433;databaseName=BookShop">
</property>
<property name="username" value="sa"></property>
<property name="password" value="sasa"></property>
</bean>
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource">
<ref bean="dataSource" />
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">
org.hibernate.dialect.SQLServerDialect
</prop>
</props>
</property>
<property name="mappingResources">
<list>
<value>com/bookshop/entity/BookStoreInfoZ.hbm.xml</value>
<value>com/bookshop/entity/BookStoreInfoA.hbm.xml</value>
<value>com/bookshop/entity/PayCashInfo.hbm.xml</value>
<value>com/bookshop/entity/RecRetBookInfo.hbm.xml</value>
<value>com/bookshop/entity/SendRetBookInfo.hbm.xml</value>
<value>com/bookshop/entity/SendSubInfo.hbm.xml</value>
<value>com/bookshop/entity/DepreInfo.hbm.xml</value>
<value> com/bookshop/entity/ReceiveSubInfo.hbm.xml</value>
<value>com/bookshop/entity/BuyerInfo.hbm.xml</value>
<value>com/bookshop/entity/PublisherInfo.hbm.xml</value>
<value>com/bookshop/entity/BookInfo.hbm.xml</value>
<value>com/bookshop/entity/ReceiveCashInfo.hbm.xml</value>
<value>com/bookshop/entity/InstoreInfo.hbm.xml</value>
<value>com/bookshop/entity/ProviderInfo.hbm.xml</value>
<value>com/bookshop/entity/TypeInfo.hbm.xml</value>
<value>com/bookshop/entity/OutStoreInfoA.hbm.xml</value>
<value>com/bookshop/entity/OutStoreInfoZ.hbm.xml</value>
<value>com/bookshop/entity/SendInfo.hbm.xml</value>
<value>com/bookshop/entity/InnerOutInfo.hbm.xml</value>
<value>com/bookshop/entity/UserInfo.hbm.xml</value>
<value>com/bookshop/entity/MainSendSubInfo.hbm.xml</value>
<value>com/bookshop/entity/MainReceiveSubInfo.hbm.xml</value>
<value>com/bookshop/entity/MainOutStoreInfoA.hbm.xml</value>
<value>com/bookshop/entity/MainRecRetBookInfo.hbm.xml</value>
<value>com/bookshop/entity/MainSend.hbm.xml</value>
<value>com/bookshop/entity/MainSendRetBookInfo.hbm.xml</value>
<value>com/bookshop/entity/MainDepreInfo.hbm.xml</value>
</list>
</property>
</bean> 这是我用hibernate3.1,spring 1.x 配置的。不知道能不能帮助你。能的话。分就给我吧。。
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd"> <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close">
<property name="driverClassName">
<value>com.mysql.jdbc.Driver</value>
</property>
<property name="url">
<value>jdbc:mysql://localhost:3306/los</value>
</property>
<property name="username">
<value>root</value>
</property>
<property name="password">
<value>root</value>
</property>
</bean>
<!--SessionFactory -->
<bean id="mySessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource">
<ref bean="dataSource" />
</property>
<property name="mappingResources">
<list>
<value>com\domain\Pricings.hbm.xml</value>
<value>com\domain\Users.hbm.xml</value>
<value>com\domain\UsersService.hbm.xml</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">
org.hibernate.dialect.MySQLDialect
</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.hbm2ddl.auto">update</prop>
</props>
</property>
</bean>
<!-- transactionManager -->
<bean id="myTransactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="mySessionFactory"></property>
</bean>
<!-- dao -->
<bean id="priDAO" class="com.dao.PricingsDAOImpl">
<property name="sessionFactory" ref="mySessionFactory"></property>
</bean>
<!-- target -->
<bean id="priServiceTarget" class="com.service.PricingsServiceImpl">
<property name="priDAO" ref="priDAO"></property>
</bean>
<!-- transaction proxy -->
<bean id="pricingsService" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
<property name="target" ref="pricingsServiceTarget"></property>
<property name="transactionManager" ref="myTransactionManager"></property>
<property name="transactionAttributes">
<props>
<prop key="*">PROPAGATION_REQUIRED</prop>
</props>
</property>
</bean>
<!-- 资费action -->
<bean id="abstract" abstract="true" scope="prototype">
<property name="pricingsService" ref="pricingsService" />
</bean>
<bean name="/feeShowAll" class="com.action.PricingsAction" parent="abstract"/>
<bean name="/feeAdd" class="com.action.PricingsAction" parent="abstract" />
<bean name="/feeUpdateForm" class="com.action.PricingsAction" parent="abstract"/>
<bean name="/feeForUpdate" class="com.action.PricingsAction" parent="abstract"/>
<bean name="/feeUpdate" class="com.action.PricingsAction" parent="abstract" />
<bean name="/feeShowDelete" class="com.action.PricingsAction" parent="abstract" />
<bean name="/feeDelete" class="com.action.PricingsAction" parent="abstract" />
</beans>
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="configLocation" value="classpath:hibernate.cfg.xml">
</property>
</bean> <bean id="BaseServices" class="org.liuhong.work.uitl.BaseService">
<property name="sessionFactory" ref="sessionFactory" />
</bean> <bean id="UserServices" parent="txProxyTemplate">
<property name="target">
<bean class="org.liuhong.work.services.UserServiceImpl">
<property name="services" ref="BaseServices" />
</bean>
</property>
</bean> <bean id="transactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory">
<ref bean="sessionFactory" />
</property>
</bean>
<bean id="txProxyTemplate" abstract="true"
class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
<property name="transactionManager">
<ref bean="transactionManager" />
</property>
<property name="transactionAttributes">
<props>
<prop key="save*"> PROPAGATION_REQUIRED,-java.lang.Exception
</prop>
<prop key="update*">PROPAGATION_REQUIRED</prop>
<prop key="delete*">PROPAGATION_REQUIRED</prop>
<prop key="*">PROPAGATION_REQUIRED</prop>
</props>
</property>
</bean>
</beans>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:jee="http://www.springframework.org/schema/jee"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-2.5.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd" default-lazy-init="true">
<description>UTS For Spring FrameWork 1.1</description>
<!--配置数据源JDBC-->
<bean id="propertyConfigurer"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>classpath:jdbc.properties</value>
</list>
</property>
</bean>
<!-- 使用annotation 自动注册bean,并保证@Required,@Autowired的属性被注入 -->
<!-- -->
<context:component-scan base-package="com.train" />
<bean id="mydatasource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName">
<value>com.microsoft.sqlserver.jdbc.SQLServerDriver</value>
</property>
<property name="url">
<value>${jdbc.url}</value>
</property>
<property name="username">
<value>${jdbc.username}</value>
</property>
<property name="password">
<value>${jdbc.password}</value>
</property>
<property name="maxActive">
<value>100</value>
</property>
<property name="maxIdle">
<value>100</value>
</property>
<property name="maxWait">
<value>120000</value>
</property>
<property name="poolPreparedStatements" value="true" />
<property name="defaultAutoCommit">
<value>false</value>
</property>
</bean>
<!--建立Hibernate SessionFactory-->
<bean id="mySessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource">
<ref local="mydatasource"/>
</property>
<property name="namingStrategy">
<bean class="org.hibernate.cfg.ImprovedNamingStrategy" /><!-- 命名规范如:OrderItem:order_item -->
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.SQLServerDialect</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.jdbc.fetch_size">50</prop>
<prop key="hibernate.jdbc.batch_size">100</prop>
<prop key="hibernate.cache.use_query_cache">true</prop>
<!--
<prop key="hibernate.hbm2ddl.auto">update</prop> 自动和数据库比较更改数据库
-->
<prop key="hibernate.cache.provider_class"><!-- 缓存接口类 -->
org.hibernate.cache.EhCacheProvider
</prop>
<prop
key="hibernate.cache.provider_configuration_file_resource_path">
/ehcache/ehcache-hibernate-local.xml
</prop>
</props>
</property>
<property name="packagesToScan">
<list>
<value>com.train.entity</value>
<value>com.train.entity.*</value>
</list>
</property>
</bean>
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory">
<ref local="mySessionFactory" />
</property>
</bean>
<!-- 使用annotation定义事务 --> <tx:annotation-driven transaction-manager="transactionManager" />
</beans>