我正在使用Spring Boot应用程序: https://github.com/kswr/wallets-api(开发分支) 它连接到本地Postgres实例并可以执行get操作。 但是,当我在Tomcat实例上放置.war时,出现以下错误
Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'org.springframework.boot.autoconfigure.orm.jpa.
HibernateJpaConfiguration': Unsatisfied dependency expressed through constructor parameter 0;
nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceConfiguration$Hikari.class]: Bean instantiation via factory method failed;
nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.zaxxer.hikari.HikariDataSource]: Factory method 'dataSource' threw exception;
nested exception is org.springframework.boot.autoconfigure.jdbc.DataSourceProperties$DataSourceBeanCreationException: Failed to determine a suitable driver class
我不确定是Spring Boot还是Tomcat问题,我尝试为Tomcat安装postgres驱动程序,并在$CATALINA_HOME/conf/Catalina/localhost/wallets-api-develop.xml
中进行如下配置,但似乎没有任何改变
<Context>
<Resource name="jdbc/postgres" scope="Shareable" type="javax.sql.DataSource"/>
<ResourceParams name="jdbc/postgres">
<parameter>
<name>validationQuery</name>
<value>select version();</value>
</parameter>
<parameter>
<name>url</name>
<value>jdbc:postgresql://localhost:5432/wallets</value>
</parameter>
<parameter>
<name>password</name>
<value>admin</value>
</parameter>
<parameter>
<name>maxActive</name>
<value>4</value>
</parameter>
<parameter>
<name>maxWait</name>
<value>5000</value>
</parameter>
<parameter>
<name>driverClassName</name>
<value>org.postgresql.Driver</value>
</parameter>
<parameter>
<name>username</name>
<value>kswr</value>
</parameter>
<parameter>
<name>maxIdle</name>
<value>2</value>
</parameter>
</ResourceParams>
</Context>
答案 0 :(得分:0)
这实际上是application.properties的问题;显然-D参数在运行时有效,而我的Jenkins管道仅在编译时提供它们,因此Tomcat无法使用application-staging.properties(包含正确的数据源配置)。