一:搭建Maven3环境:
①:下载Maven3.
解压 --> 配置M2_HOME 环境变量 -->Maven在下载所依赖的jar里,默认所放的位置为:
${USER_HOME}/.m2/repository 文件夹下.我们可以修改setting.xml文件的位置来指定. <localRepository>/path/to/local/repo</localRepository>
②:下载Eclipse的m2eclipse插件
URL:
③:设置Eclipse的maven插件的属性,按自己爱好;也可保持不变.
二:创建一个Maven工程, web-app
三:增加src/main/resources; src/test/java; src/java/resources等source Folder,(按maven管理项目的习惯)
四:添加maven对jar文件的依赖;
需要说明的是
①:cglib-nodep这个jar包为后来新增的,原来带的cglib包要移除掉,否则会出现错误;
②:jar250-api:这个jar包是使用基于注解的spring和hibernate增加的,@Resources.
五:配置文件:(只有spring+hibernate部分)
<?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:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.1.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd"> <!-- 分散配置 --> <context:property-placeholder location="classpath:database.properties" /> <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"> <property name="driverClass" value="${driverClass}" /> <property name="jdbcUrl" value="${jdbcUrl}" /> <property name="user" value="${user}" /> <property name="password" value="${password}" /> <property name="maxPoolSize" value="${maxPoolSize}" /> <property name="initialPoolSize" value="${initialPoolSize}" /> <property name="acquireIncrement" value="${acquireIncrement}" /> <property name="minPoolSize" value="${minPoolSize}" /> </bean> <!-- 配置sessionFactory --> <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"> <property name="dataSource" ref="dataSource" /> <property name="hibernateProperties"> <props> <prop key="hibernate.dialect">${hibernate.dialect}</prop> <prop key="hibernate.hbm2ddl">${hibernate.hbm2ddl}</prop> <prop key="hibernate.show_sql">${hibernate.show_sql}</prop> </props> </property> <property name="mappingDirectoryLocations"> <list> <value>classpath:com/skywares/eos/pojo</value> </list> </property> </bean> <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager"> <property name="sessionFactory" ref="sessionFactory" /> </bean> <!-- 基于注解的自动扫描的包 --> <context:component-scan base-package="com.skywares.eos.service"></context:component-scan> <context:component-scan base-package="com.skywares.eos.dao"></context:component-scan> <context:annotation-config /> <!-- 注解驱动事务的配置 --> <tx:annotation-driven transaction-manager="transactionManager" /> </beans>六:Java类的配置;
Service层:
BaseService: 事务控制要在Service层
DAO层:
baseDao层:(注入SessionFactory)
七:hibernate映射文件配置(略)及database属性文件略
八:Junit测试类:(略)