package org.macula.boot.core.config;

import org.macula.boot.core.config.core.CoreConfigProperties;
import org.macula.boot.core.config.json.MaculaJackson2ObjectMapperBuilderCustomizer;
import org.macula.boot.core.context.support.ReloadableResourceBundleMessageSource;
import org.macula.boot.exception.handler.ServiceExceptionAspect;
import org.macula.boot.exception.translator.HibernateExceptionTranslator;
import org.macula.boot.exception.translator.PersistenceExceptionTranslator;
import org.springframework.beans.BeansException;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
import org.springframework.boot.autoconfigure.context.MessageSourceAutoConfiguration;
import org.springframework.boot.autoconfigure.context.MessageSourceProperties;
import org.springframework.boot.autoconfigure.data.redis.RedisAutoConfiguration;
import org.springframework.boot.autoconfigure.jackson.Jackson2ObjectMapperBuilderCustomizer;
import org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.context.MessageSource;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.data.redis.repository.configuration.EnableRedisRepositories;
import org.springframework.util.StringUtils;

import java.time.Duration;

/**
 * <p>
 * <b>CoreAutoConfiguration</b> Core模块的自动配置入口
 * 在系统数据源之前配置时，系统默认的JPA、JDBC等都会靠后
 * </p>
 *
 * @author Rain
 * @since 2019-01-22
 */

@Configuration
@EnableConfigurationProperties({CoreConfigProperties.class})
@EnableRedisRepositories
@AutoConfigureBefore({RedisAutoConfiguration.class, DataSourceAutoConfiguration.class,
        HibernateJpaAutoConfiguration.class, MessageSourceAutoConfiguration.class})
@AutoConfigureAfter({JacksonAutoConfiguration.class})
@Import({RedisConfiguration.class, DataSourceConfiguration.class, JpaRepositoriesConfiguration.class})
public class CoreAutoConfiguration implements ApplicationContextAware {

    @Bean
    public HibernateExceptionTranslator hibernateExceptionTranslator() {
        return new HibernateExceptionTranslator();
    }

    @Bean
    public PersistenceExceptionTranslator persistenceExceptionTranslator() {
        return new PersistenceExceptionTranslator();
    }

    @Bean
    public ServiceExceptionAspect serviceExceptionAspect() {
        return new ServiceExceptionAspect();
    }

    @Bean
    public Jackson2ObjectMapperBuilderCustomizer jackson2ObjectMapperBuilderCustomizer() {
        return new MaculaJackson2ObjectMapperBuilderCustomizer();
    }

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        org.macula.boot.ApplicationContext.setContainer(applicationContext);
    }
}

@@ -31,16 +31,87 @@
 onfig;%0A%0A
+import org.macula.boot.core.config.context.MessageSourceConfiguration;%0A
 import o
@@ -2152,21 +2152,22 @@
 gure
-Before(%7BRedis
+After(%7BJackson
 Auto
@@ -2181,30 +2181,56 @@
 ration.class
-, Data
+%7D)%0A@AutoConfigureBefore(%7BMessage
 SourceAutoCo
@@ -2251,29 +2251,14 @@
 ass,
-%0A        HibernateJpa
+ Redis
 Auto
@@ -2281,16 +2281,21 @@
 ass,
- Message
+%0A        Data
 Sour
@@ -2323,39 +2323,22 @@
 lass
-%7D)%0A@AutoConfigureAfter(%7BJackson
+, HibernateJpa
 Auto
@@ -2352,24 +2352,26 @@
 ration.class
+, 
 %7D)%0A@Import(%7B
@@ -2370,16 +2370,50 @@
 Import(%7B
+MessageSourceConfiguration.class, 
 RedisCon
@@ -2429,16 +2429,24 @@
 n.class,
+%0A       
  DataSou
@@ -3364,8 +3364,9 @@
     %7D%0A%7D%0A
+%0A

fix bug