这个配置文件有错误,文件中的配置未能覆盖hibernate默认的hibernte.properties,请改成如下配置:
<?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="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName">
<value>com.mysql.jdbc.Driver</value>
</property>
<property name="url">
<value>jdbc:mysql://localhost:3306/db_database17
</value>
</property>
<!-- 忽略此处的账号密码配置 <property name="username"> <value>root</value> </property>
<property name="password"> <value>123456</value> </property> -->
</bean>
<!-- 定义Hibernate的sessionFactory -->
<bean id="sessionFactory"
class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="dataSource">
<ref bean="dataSource" />
</property>
<property name="hibernateProperties">
<props>
<!-- 数据库连接方言 -->
<prop key="dialect">org.hibernate.dialect.SQLServerDialect</prop>
<!-- 在控制台输出SQL语句 -->
<prop key="hibernate.show_sql">true</prop>
<!-- 格式化控制台输出的SQL语句 -->
<prop key="hibernate.format_sql">true</prop>
<!-- 必须在此处配置连接数据库的账号 -->
<prop key="hibernate.connection.username">root</prop>
<!-- 必须在此处配置连接数据库的密码 -->
<prop key="hibernate.connection.password">123456</prop>
</props>
</property>
<!--hibernate映射文件 -->
<property name="mappingResources">
<list>
<value>com/mr/user/User.hbm.xml</value>
</list>
</property>
</bean>
<!-- 为DAOSupport注入sessionFactory -->
<bean id="dao" class="com.mr.dao.DAOSupport">
<property name="sessionFactory">
<ref local="sessionFactory" />
</property>
</bean>
<!--定义控制器转发视图类 -->
<bean id="viewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix">
<value>/</value>
</property>
<property name="suffix">
<value>.jsp</value>
</property>
</bean>
<!-- 映射的do -->
<bean name="/save.do" class="com.mr.main.AddUser">
<property name="dst">
<ref local="dao" />
</property>
</bean>
</beans>