最近,一应用从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博客 ” ,链接:https://blog.itpub.net/29357786/viewspace-2838865/ ,如需转载,请注明出处,否则将追究法律责任。