简体   繁体   中英

Tomcat configuration for Spring Boot with Postgresql

I've got working Spring Boot application: https://github.com/kswr/wallets-api (develop branch) which connects to the local Postgres instance and can perform get operation. But when I put .war on Tomcat instance, I get the following error

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

I'm not sure if it's Spring Boot or Tomcat problem, I tried to install postgres driver for Tomcat and configure it as follows in $CATALINA_HOME/conf/Catalina/localhost/wallets-api-develop.xml but it doesn't seem to change anything

<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>

It was in fact problem with application.properties; apparently -D arguments work at runtime, whilst my Jenkins pipeline provided them only on compilation thus application-staging.properties (which contained correct datasource configuration) couldn't be used by Tomcat.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM