pep1.commons.jpa.config.JpaConfig Maven / Gradle / Ivy
/*
* Copyright (C) 2016 Leonard Osang
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
package pep1.commons.jpa.config;
import com.fasterxml.jackson.core.Version;
import com.fasterxml.jackson.databind.Module;
import com.fasterxml.jackson.databind.module.SimpleModule;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.h2.H2ConsoleAutoConfiguration;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.boot.autoconfigure.liquibase.LiquibaseAutoConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import pep1.commons.hashid.HashIdService;
import pep1.commons.jpa.error.JpaHandlerExceptionAdvice;
import pep1.commons.jpa.jackson.PageDeserializer;
import pep1.commons.jpa.jackson.PageSerializer;
import pep1.commons.util.AutowireHelper;
@Slf4j
@Configuration
@EnableTransactionManagement
@Import({
LiquibaseAutoConfiguration.class,
DataSourceAutoConfiguration.class,
H2ConsoleAutoConfiguration.class
})
public class JpaConfig {
@Bean
public AutowireHelper autowireHelper() {
return new AutowireHelper();
}
@Bean
public HashIdService hashId() {
return new HashIdService("verycomplicatedsalt", 6);
}
@Bean
public JpaHandlerExceptionAdvice jpaHandlerExceptionAdvice() {
return new JpaHandlerExceptionAdvice();
}
@Bean
public Module pageModule() {
return new SimpleModule(
"PageModule",
new Version(1, 0, 0, null, null, null)
)
.addDeserializer(org.springframework.data.domain.Page.class, new PageDeserializer())
.addSerializer(org.springframework.data.domain.Page.class, new PageSerializer());
}
}