/*
 * ********************************************************************************************************************
 *
 *                     :*$@@%$*:                         ;:                ;;    ;;
 *                   :@@%!  :!@@%:                       %!             ;%%@@%$ =@@@@@@@%;     @%@@@%%%%@@@@@
 *                  :@%;       :$=                       %%$$$%$$         ;$$  ;$@=   !@$
 *                  =@!                                  %!              @ $=;%   !@@@%:      !$$$$$$$$$$$$$$=
 *                  =@*                                  %!              @ $= % %@=   =%@!      %=
 *             *$%%! @@=        ;=$%%%$*:                %!              @ $= % =%%%%%%@$      *%:         =%
 *           %@@!:    !@@@%=$@@@@%!  :*@@$:              %!              @ $= % $*     ;@      @*          :%*
 *         ;@@!          ;!!!;:         ;@%:      =======@%========*     @ $$ % $%*****$@     :@$=*********=@$
 *         $@*   ;@@@%=!:                *@*
 *         =@$    ;;;!=%@@@@=!           =@!
 *          %@$:      =@%: :*@@@*       %@=                    Copyright (c) 2016-2019.  北京上格云技术有限公司
 *           ;%@@$=$@@%*       *@@@$=%@@%;
 *              ::;::             ::;::                                              All rights reserved.
 *
 * ********************************************************************************************************************
 */

package com.persagy.server.messagecenter

import com.alibaba.fastjson.PropertyNamingStrategy
import com.persagy.service.json.SJsonHttpMessageConverter
import org.mybatis.spring.annotation.MapperScan
import org.springframework.boot.SpringApplication
import org.springframework.boot.autoconfigure.SpringBootApplication
import org.springframework.boot.builder.SpringApplicationBuilder
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer
import org.springframework.cloud.client.discovery.EnableDiscoveryClient
import org.springframework.cloud.netflix.eureka.EnableEurekaClient
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.ComponentScan


/**
 * 应用配置
 *
 * @author  Andy
 */
@ComponentScan(basePackages = ["com.persagy.server", "com.persagy"])           // 配置组件扫描路径
@MapperScan("com.persagy", "com.persagy.server")                       // Mapper组件扫描路径
@EnableEurekaClient
@EnableDiscoveryClient
@SpringBootApplication
open class MessageCenterApp : SpringBootServletInitializer() {

    /**
     * 配置应用
     *
     * @param   application     应用构建对象
     */
    override fun configure(application: SpringApplicationBuilder): SpringApplicationBuilder {
        return application.sources(MessageCenterApp::class.java)
    } // Function configure

    /**
     * 配置FastJson
     *
     * @return  HttpMessageConverters
     */
    @Bean
    @Suppress("MoveLambdaOutsideParentheses")
    open fun jsonHttpMessageConverters(): SJsonHttpMessageConverter {
        val fastConverter = SJsonHttpMessageConverter()
        fastConverter.propertyNamingStrategy = PropertyNamingStrategy.PascalCase
        return fastConverter

    } // Function fastJsonHttpMessageConverters()

//    @Bean
//    open fun fastJsonHttpMessageConverters(): HttpMessageConverters {
//        // 1.定义一个converters转换消息的对象
//        val fastConverter = FastJsonHttpMessageConverter()
//        // 2.添加fastjson的配置信息，比如: 是否需要格式化返回的json数据
//        val fastJsonConfig = FastJsonConfig()
//        fastJsonConfig.setSerializerFeatures(SerializerFeature.PrettyFormat)
//        // 3.在converter中添加配置信息
//        fastConverter.setFastJsonConfig(fastJsonConfig)
//        // 4.将converter赋值给HttpMessageConverter
//        // 5.返回HttpMessageConverters对象
//        return HttpMessageConverters(fastConverter)
//    }


} // Class Application

/**
 * Web应用入口
 *
 * @param   args        命令行参数
 */
fun main(args: Array<String>) {
    SpringApplication.run(MessageCenterApp::class.java, *args)
    return
} // Function main()
