jdbc配置Spring
hibernate.properties
dataSource.password=123 dataSource.username=root dataSource.databaseName=test dataSource.driverClassName=com.mysql.jdbc.Driver dataSource.dialect=org.hibernate.dialect.MySQL5Dialect dataSource.serverName=localhost:3306 dataSource.url=jdbc:mysql://localhost:3306/test dataSource.properties=user=${dataSource.username};databaseName=${dataSource.databaseName};serverName=${dataSource.serverName};password=${dataSource.password} dataSource.hbm2ddl.auto=update
applicationContext.xml
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean"> <property name="dataSource" ref="dataSource" /> <property name="hibernateProperties"> <props> <prop key="hibernate.dialect">${dataSource.dialect}</prop> <prop key="hibernate.hbm2ddl.auto">${dataSource.hbm2ddl.auto}</prop> <prop key="hibernate.hbm2ddl.auto">update</prop> </props> </property> <property name="packagesToScan"> <list> <value>com.mvc.entity</value><!-- 扫描实体类,也就是平时所说的model --> </list> </property> </bean> <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager"> <property name="sessionFactory" ref="sessionFactory" /> <property name="dataSource" ref="dataSource" /> </bean> <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"> <property name="driverClassName" value="${dataSource.driverClassName}" /> <property name="url" value="${dataSource.url}" /> <property name="username" value="${dataSource.username}" /> <property name="password" value="${dataSource.password}" /> </bean>