반응형
자바, 스프링(application.yml)환경에서 postgresql에 ssl 인증서를 사용하여 연결하는 방법
sslmode는 postgresql서버 설정에 따라 [disable, allow, prefer, require, verify-ca, verify-full] 중 선택
ssl 경로 유의할 것
jdbc-url: jdbc:postgresql://${dburl}:${dbport}/${dbschema}?charSet=UTF-8&defaultResultSetType=Cursor&ssl=true&sslmode=require&sslrootcert=src/main/resources/root.crt&sslcert=src/main/resources/postgresql.crt&sslkey=src/main/resources/postgresql.pk8
풀어서본다면 아래와 같다.
jdbc-url: jdbc:postgresql://${dburl}:${dbport}/${dbschema}
?charSet=UTF-8
&defaultResultSetType=Cursor
&ssl=true
&sslmode=require
&sslrootcert=src/main/resources/root.crt
&sslcert=src/main/resources/postgresql.crt
&sslkey=src/main/resources/postgresql.pk8
만약 aws batch라면 경로가 로컬과 다르다.(절대경로 /app)
jdbc-url: jdbc:postgresql://${dburl}:${dbport}/${dbschema}
?charSet=UTF-8
&defaultResultSetType=Cursor
&ssl=true
&sslmode=require
&sslrootcert=/app/resources/root.crt
&sslcert=/app/resources/postgresql.crt
&sslkey=/app/resources/postgresql.pk8
만약 pk8 인증서가 없는 경우 : postgresql.pk8 생성하기 (tistory.com)
이건 EntityManagerFactory 설정 부분
@Bean
public EntityManagerFactory entityManagerFactoryFox() {
JpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
LocalContainerEntityManagerFactoryBean factory = new LocalContainerEntityManagerFactoryBean();
factory.setDataSource(this.dataSourceFox());
factory.setJpaVendorAdapter(vendorAdapter);
ImmutableMap.Builder<String, Object> propertiesBuilder = ImmutableMap.builder();
propertiesBuilder.put("hibernate.hbm2ddl.auto", "none");
propertiesBuilder.put("hibernate.dialect", "org.hibernate.dialect.PostgreSQLDialect");
propertiesBuilder.put("hibernate.show_sql", "true");
propertiesBuilder.put("hibernate.jdbc.lob.non_contextual_creation", "true");
factory.setJpaPropertyMap(propertiesBuilder.build());
factory.setPackagesToScan(new String[]{"com.fox.fox2.fox3.model"});
factory.setPersistenceUnitName("foxname");
factory.afterPropertiesSet();
return factory.getObject();
}
참조 : java - Spring Boot connection to Postgresql with SSL - Stack Overflow
반응형
'IT 자료' 카테고리의 다른 글
java.lang.UnsupportedOperationException: A TupleBackedMap cannot be modified. (0) | 2023.07.13 |
---|---|
java.lang.IllegalArgumentException: Unable to deserialize the execution context (0) | 2023.07.04 |
데이터 레이크 한눈에보기 (0) | 2023.03.04 |
엑셀로 mysql varchar 50의 길이만큼 자르는 방법 (0) | 2022.06.10 |
restTemplate.exchange 예외처리 (0) | 2022.02.14 |