JAVA spring&hibernate資料來源配置不當報錯key postgresIsPool

清風艾艾發表於2021-10-22

    最近,一應用從oracle資料庫向postgresql遷移完成後,啟動應用後,應用日誌提示報錯:

[2021-10-08 17:02:52] ERROR context.ContextLoader - Context initialization failed

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [ applicationContext.xml]

java.util.MissingResourceException: Can't find resource for bundle java.util.PropertyResourceBundle, key postgresIsPool

看日誌提示,applicationContext.xml中無資料來源dataSource引用的postgresIsPool相關的key和value鍵值對。

      檢視applicationContext.xml配置如下:

<bean id="propertyConfigurer"

class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">

<property name="locations">

<list>

<value>classpath:/parameter.properties</value>

<value>classpath:/stat.properties</value>

                                <!--value>classpath:/jdbc.properties</value>-->

<value>classpath:/cams.properties</value>

<value>classpath:/sso.properties</value>

</list>

</property>

<property name="ignoreUnresolvablePlaceholders" value="true" />

</bean>

<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"

destroy-method="close">

<property name="driverClassName">

<value>${jdbc.driverClassName}</value>

</property>

<property name="url">

<value>${jdbc.url}</value>

</property>

<property name="username">

<value>${jdbc.username}</value>

</property>

<property name="password">

<value>${jdbc.password}</value>

</property>

</bean>

看配置檔案,專案的資料來源配置檔案 applicationContext.xml引用了同目錄的 parameter.properties引數檔案,進一步檢視

parameter.properties引數檔案,裡邊只有類似如下oracle相關的配置並無postgresql的配置:

db = oracle

oracleDriver = oracle.jdbc.driver.OracleDriver

oracleUrl = jdbc:oracle:thin:@x.x.x.x:1921/orcl

oracleUser = xxxxxx

oraclePassword = xxxxxxxxx

oracleIsPool = c3p0

oraclePoolName = java:comp/env/jdbc/fsm

oracleType = oracle

根據上述oracle資料來源引數配置編輯postgresql相關配置如下所示:

db = postgresql

postgresqlDriver = org.postgresql.Driver

postgresqlUrl = jdbc:postgresql://x.x.x.x:5432/orcl

postgresqlUser = xxxxxx

postgresqlPassword = xxxxxxxxx

postgresqlIsPool = c3p0

postgresqlPoolName = java:comp/env/jdbc/fsm

postgresqlType = postgresql

    修改完配置之後,java應用程式正常連線到postgresql資料庫。

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/29357786/viewspace-2838865/,如需轉載,請註明出處,否則將追究法律責任。

相關文章