今天在做测试时遇到的这个错误,后来搜索找到原因,这个是hibernate默认配置 覆盖了我们自己的连接池配置有关
<bean name="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver" />
<property name="url" value="jdbc:mysql:///jk2" />
<property name="username" value="root" />
<property name="password" value="1234" />
</bean>
我在连接池中已经配置了 账号密码,可是还是不能连接数据库,,
只需要在sessionfactory bean中添加账号密码的配置就可以了,相当于在配置一遍,覆盖hibernate的默认配置
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.generate_statistics">true</prop>
<prop key="hibernate.connection.release_mode">auto</prop>
<prop key="hibernate.autoReconnect">true</prop>
<prop key="hibernate.form_sql">true</prop>
<prop key="hibernate.connection.username">root</prop>
<prop key="hibernate.connection.password">1234</prop>
<prop key="hibernate.connection.url">jdbc:mysql:///jk2</prop>
<prop key="hibernate.default_batch_fetch_size">30</prop>
</props>
</property>
</bean>
在配置中添加上面绿色的三行就好了
我在这里找到的 http://19841026.iteye.com/blog/2160555