@Configuration @EnableTransactionManagement @EnableJpaRepositories(entityManagerFactoryRef = "emfRadiusFttx", transactionManagerRef = "tmRadiusFttx", basePackages = ["com.entre.databases.radiusfttx.domain"]) @ConfigurationProperties(prefix = "databases.radiusfttx") class RadiusFttxPersistence { var host = "" var port = "" var username = "" var password = "" var schema = "" @Primary @Bean("dsRadiusFttx") fun dataSource() = TomcatDataSource().apply { username = this@RadiusFttxPersistence.username password = this@RadiusFttxPersistence.password url = "jdbc:postgresql://$host:$port/$schema" driverClassName = "org.postgresql.Driver" minIdle = 1 initialSize = 1 validationQuery = "SELECT 1" } fun hibernateJpaVendorAdapter() = HibernateJpaVendorAdapter().apply { setDatabasePlatform("org.hibernate.dialect.PostgreSQL9Dialect") setShowSql(false) } @Primary @Bean("emfRadiusFttx") fun entityManagerFactory() = LocalContainerEntityManagerFactoryBean().apply { setPackagesToScan("com.entre.databases.radiusfttx.domain") jpaVendorAdapter = hibernateJpaVendorAdapter() dataSource = dataSource() persistenceUnitName = "puRadiusFttx" afterPropertiesSet() } @Primary @Bean("tmRadiusFttx") fun transactionManager() = JpaTransactionManager().apply { entityManagerFactory = entityManagerFactory().`object` } }