-
spring data jpa @Entity schema, catalog properties처리하기.IT/spring 2021. 3. 24. 16:49
spring data jpa @Entity schema, catalog properties처리하기.
@Component @Slf4j public class HibernateInterceptor extends EmptyInterceptor { private static Environment env; public HibernateInterceptor() { } @Autowired public HibernateInterceptor(Environment env) { this.env = env; } @Override public String onPrepareStatement(String sql) { if (null != env) { String regEx = "\\$\\{([\\\\.\\w_-]+)\\}"; Pattern pat = Pattern.compile(regEx); Matcher match = pat.matcher(sql); while (match.find()) { sql = sql.replace(match.group(), env.getProperty(match.group(1))); } return super.onPrepareStatement(sql); } else { return super.onPrepareStatement(sql); } } }
@Getter @Setter @EqualsAndHashCode(callSuper=false) @Entity @Table(name= MemberUsersBase.TABLE, catalog = "${project.properties.member-schema}") public class CoreMemberUsers extends MemberUsersBase { }
yaml
spring: profiles: db application: name: db jpa: show-sql: false atabase-platform: org.hibernate.dialect.MySQL5InnoDBDialect hibernate: ddl-auto: none naming: physical-strategy: org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl properties: hibernate.ejb.interceptor: com.....core.interceptor.HibernateInterceptor project: properties: member-schema: member_dev
'IT > spring' 카테고리의 다른 글
spring boot 세션만료 감지 (0) 2021.04.22 spring boot 로컬에서 smtp mail 테스트하기 (0) 2021.02.18 어디에서나 Spring 컨터이너 Bean 객체 얻어오기 (0) 2021.02.08 spring 시작(startup)과 끝 (end) 이벤트 받아오기 (0) 2021.02.08 Intellij spring entity jpa Persistence 기능 Diagram (0) 2021.02.08