SSH笔记三 反向生成DAO 优化开发目录
2009-09-23 00:00:00 来源:WEB开发网3.3 正如你看到的,我们将数据连接信息以及DAO配置分别放在了 data-source.xml和ssim-dao.xml中,那我们就来创建他们。
data-source.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.5.xsd">
<bean id="ssimdb.TxManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="ssimdb.session.factory" />
</bean>
<bean id="ssimdb.mssql" class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close">
<property name="driverClassName" value="com.mysql.jdbc.Driver">
</property>
<property name="url" value="${ssimdb.mysql.url}" />
<property name="username" value="${ssimdb.mysql.username}" />
<property name="password" value="${ssimdb.mysql.password}" />
<property name="maxIdle" value="10" />
<property name="minIdle" value="2" />
<property name="maxActive" value="10" />
</bean>
<bean id="ssimdb.session.factory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource">
<ref bean="ssimdb.mssql" />
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">
org.hibernate.dialect.MySQLDialect
</prop>
</props>
</property>
<property name="mappingResources">
<list>
<value>dao/SsimUser.hbm.xml</value>
</list>
</property>
</bean>
</beans>
ssim-dao.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.5.xsd">
<bean id="SsimUserDAO" class="net.selitech.ssim.dao.SsimUserDAO">
<property name="sessionFactory">
<ref bean="ssimdb.session.factory" />
</property>
</bean>
</beans>
到了这里,运行一下SsimUserDAOTest,看看结果,如果顺利通过,该恭喜你完成了我们今天的任务了。
更多精彩
赞助商链接