在Spring中配置jdbc時,引用的是dbcp.jar包,在db.properties配置文件中,使用了之前的properties配置文件的用戶名username(MySql用戶名)
然后在啟動服務器報了如下幾個異常:
1、org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in class path resource [applicationContext.xml]: Invocation of init method failed; nested exception is org.hibernate.service.spi.ServiceException: Unable to create requested service [org.hibernate.engine.jdbc.env.spi.JdbcEnvironment]
2、Caused by: org.hibernate.service.spi.ServiceException: Unable to create requested service [org.hibernate.engine.jdbc.env.spi.JdbcEnvironment]
3、Caused by: org.hibernate.HibernateException: Access to DialectResolutionInfo cannot be null when 'hibernate.dialect' not set
applicationContext.xml配置文件
db.properties.xml配置文件
后來檢查發現,在加載讀取配置文件的標簽中
<context:property-placeholder location="classpath:dataSource.properties" /> 少了一條屬性system-properties-mode="FALLBACK",
系統默認為system-properties-mode="ENVIRONMENT" 意思就是從系統環境中去讀取,把電腦名當做MySlq的用戶名,修改之后運行成功。