Skip to content

Instantly share code, notes, and snippets.

@andersonkxiass
Last active October 16, 2018 20:13
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andersonkxiass/e385efcbed03415e2c41063c4fea8820 to your computer and use it in GitHub Desktop.
Save andersonkxiass/e385efcbed03415e2c41063c4fea8820 to your computer and use it in GitHub Desktop.
Spring boot + postgres (Remotely)
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'org.springframework.boot:spring-boot-gradle-plugin:1.5.1.RELEASE'
}
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'spring-boot'
apply plugin: 'war'
sourceCompatibility = 1.8
targetCompatibility = 1.8
war {
baseName = 'spring-example'
version = '0.1.0'
}
repositories {
jcenter()
maven { url "http://repo.spring.io/libs-snapshot" }
}
configurations {
providedRuntime
compile.exclude group:'ch.qos.logback'
}
// In this section you declare the dependencies for your production and test code
dependencies {
compile("org.springframework.boot:spring-boot-starter")
compile("org.springframework.boot:spring-boot-starter-web")
providedRuntime 'org.springframework.boot:spring-boot-starter-tomcat'
compile("org.springframework.boot:spring-boot-starter-data-jpa")
compile group: 'org.postgresql', name: 'postgresql', version: '9.4-1200-jdbc41'
}
task wrapper(type: Wrapper) {
gradleVersion = '2.3'
}
@Configuration
@PropertySource({ "classpath:persistence.properties" })
public class DatabaseConfig {
@Bean
@Primary
@ConfigurationProperties(prefix = "spring.datasource")
public DataSource dataSource() {
return DataSourceBuilder.create().build();
}
}
@SpringBootApplication
@ComponentScan
public class MyApplication extends SpringBootServletInitializer {
public static void main(String[] args) {
SpringApplication.run(MyApplication.class, args);
}
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(MyApplication.class);
}
}
spring.jpa.database=POSTGRESQL
spring.datasource.platform=postgres
spring.datasource.url=jdbc:postgresql://yourhost:5432/databaseName?ssl=true&sslfactory=org.postgresql.ssl.NonValidatingFactory
spring.datasource.username=""
spring.datasource.password=""
spring.datasource.driver-class-name=org.postgresql.Driver
spring.datasource.testWhileIdle=true
spring.datasource.validationQuery=SELECT 1
spring.jpa.show-sql=true
spring.jpa.hibernate.ddl-auto=create-drop
spring.jpa.hibernate.naming-strategy=org.hibernate.cfg.ImprovedNamingStrategy
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect
@maslick
Copy link

maslick commented Apr 23, 2018

hey, what if I don't want ssl? what should i specify in spring.datasource.url ? Thanks :)

@Jazzepi
Copy link

Jazzepi commented Jul 27, 2018

@maslick Something like this. spring.datasource.url=jdbc:postgresql://localhost:5432/postgres?useSSL=false

@abishek-sampath
Copy link

any idea where the ssl certs will be picked up from if we set ssl=true in the datasource url?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment