日期:2014-05-19 浏览次数:20838 次
<context:annotation-config /> <context:component-scan base-package="com.itadmin" /> <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"> <property name="driverClassName" value="${jdbc.driverClassName}" /> <property name="url" value="${jdbc.url}" /> <property name="username" value="${jdbc.username}" /> <property name="password" value="${jdbc.password}" /> </bean> <context:property-placeholder location="/WEB-INF/jdbc.properties" /> <bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean"> <property name="dataSource" ref="dataSource" /> <property name="annotatedClasses"><!-- 将实体类注入annotatedClasses属性 --> <list> <value>com.itadmin.model.User</value> <value>com.itadmin.model.Product</value> <value>com.itadmin.model.ProductLog</value> <value>com.itadmin.model.SaleRecord</value> <value>com.itadmin.model.User</value> </list> </property> <!-- hibernate的一些配置 --> <property name="hibernateProperties"> <props> <prop key="hibernate.dialect">org.hibernate.dialect.OracleDialect</prop> <prop key="hibernate.show_sql">true</prop> <prop key="hibernate.format_sql">true</prop> <prop key="hibernate.current_session_context_class">thread</prop> </props> </property> </bean> <bean id="loginAction" class="com.itadmin.action.LoginAction"> <property name="userService"> <ref bean="userService"/> </property> </bean> <bean id="logoutAction" class="com.itadmin.action.LogoutAction"> </bean> <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager"> <property name="sessionFactory"> <ref local="sessionFactory" /> </property> </bean> <bean id="txManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager"> <property name="sessionFactory" ref="sessionFactory" /> </bean> <tx:annotation-driven transaction-manager="txManager"/> </beans>
package com.itadmin.service; @Service("productService") public class ProductService { private LogDao logDao; // private ProductDao productDao = new ProductDao(); // private LogDao logDao = new LogDao(); private ProductDao productDao; private Map productsMap; public LogDao getLogDao() { return logDao; } @Transactional public Product getProductById(int id) { Product product = productDao.findProductById(id); return product; } public ProductDao getProductDao()