Last active
October 16, 2018 20:13
-
-
Save andersonkxiass/e385efcbed03415e2c41063c4fea8820 to your computer and use it in GitHub Desktop.
Spring boot + postgres (Remotely)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Configuration | |
@PropertySource({ "classpath:persistence.properties" }) | |
public class DatabaseConfig { | |
@Bean | |
@Primary | |
@ConfigurationProperties(prefix = "spring.datasource") | |
public DataSource dataSource() { | |
return DataSourceBuilder.create().build(); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 Something like this. spring.datasource.url=jdbc:postgresql://localhost:5432/postgres?useSSL=false
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
hey, what if I don't want ssl? what should i specify in
spring.datasource.url
? Thanks :)