Platform.sh is now Upsun. Click here to learn more
Upsun Fixed User Documentation

Configure Spring with PostgreSQL

Try Upsun for 15 days
After that, enjoy the same, game-changing Upsun features for less with the First Project Incentive!¹ A monthly $19 perk!
Activate your 15-day trial
¹Terms and conditions apply

PostgreSQL is an open-source relational database technology. Spring has a robust integration with this technology: Spring Data JPA.

The first step is to choose the database that you would like to use in your project. Define the driver for PostgreSQL and the Java dependencies. Then determine the DataSource client using the Java configuration reader library.

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import sh.platform.config.Config;
import sh.platform.config.PostgreSQL;

import javax.sql.DataSource;

@Configuration
public class DataSourceConfig {

    @Bean(name = "dataSource")
    public DataSource getDataSource() {
        Config config = new Config();
        PostgreSQL database = config.getCredential("database", PostgreSQL::new);
        return database.get();
    }
}