package xxx.jq

import org.springframework.beans.factory.config.ConfigurableBeanFactory
import org.springframework.boot.SpringApplication
import org.springframework.boot.autoconfigure.EnableAutoConfiguration
import org.springframework.boot.autoconfigure.SpringBootApplication
import org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration
import org.springframework.boot.orm.jpa.EntityScan
import org.springframework.cache.annotation.EnableCaching
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Scope
import org.springframework.data.jpa.convert.threeten.Jsr310JpaConverters
import org.springframework.scheduling.annotation.EnableScheduling
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder

/**
 * アプリの起動クラス.
 *
 * コンバーター用のEntityScanと暗号化のBCryptEncoderをBean化している。
 *
 * @since 2015/10/07
 */
@SpringBootApplication
@EnableScheduling
@EnableCaching
@EntityScan(basePackageClasses = arrayOf(Application::class, Jsr310JpaConverters::class))
@EnableAutoConfiguration(exclude = arrayOf(JacksonAutoConfiguration::class))
open class Application {

    @Bean
    @Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
    open fun passwordEncoder(): BCryptPasswordEncoder {
        return BCryptPasswordEncoder()
    }

    companion object {
        @JvmStatic fun main(args: Array<String>) {
            SpringApplication.run(Application::class.java, *args)
        }
    }
}