Spring+Hibernate 如何配置数据源
1个回答
展开全部
<?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.mysql.jdbc.Driver</value>
</property>
<property name="url">
<value>jdbc:mysql://localhost:3306/DBName</value> //配置
</property>
<property name="username">
<value>root</value> //配置用户名
</property>
<property name="password">
<value>123</value> //配置密码
</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.MySQLDialect
</prop>
</props>
</property>
<property name="mappingResources">
<list>
<value>com/vo/User.hbm.xml</value></list>
</property>
</bean>
<bean id="userDAO" class="com.dao.UserDAOSupport">
<property name="sessionFactory">
<ref bean="sessionFactory"/>
</property>
</bean>
</beans>
这里hibernate的datasource交给了 spring来管理
如果有疑问继续问
<!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.mysql.jdbc.Driver</value>
</property>
<property name="url">
<value>jdbc:mysql://localhost:3306/DBName</value> //配置
</property>
<property name="username">
<value>root</value> //配置用户名
</property>
<property name="password">
<value>123</value> //配置密码
</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.MySQLDialect
</prop>
</props>
</property>
<property name="mappingResources">
<list>
<value>com/vo/User.hbm.xml</value></list>
</property>
</bean>
<bean id="userDAO" class="com.dao.UserDAOSupport">
<property name="sessionFactory">
<ref bean="sessionFactory"/>
</property>
</bean>
</beans>
这里hibernate的datasource交给了 spring来管理
如果有疑问继续问
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询