-
Notifications
You must be signed in to change notification settings - Fork 43
/
Application.kt
55 lines (46 loc) · 2.09 KB
/
Application.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package io.spring.messenger
import com.fasterxml.jackson.annotation.JsonInclude.Include
import com.fasterxml.jackson.databind.ObjectMapper
import io.spring.messenger.domain.Message
import io.spring.messenger.domain.User
import io.spring.messenger.repository.MessageRepository
import io.spring.messenger.repository.UserRepository
import org.jetbrains.exposed.spring.SpringTransactionManager
import org.postgis.geojson.PostGISModule
import org.springframework.boot.CommandLineRunner
import org.springframework.boot.autoconfigure.SpringBootApplication
import org.springframework.boot.runApplication
import org.springframework.context.annotation.Bean
import org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder
import org.springframework.transaction.annotation.EnableTransactionManagement
import javax.sql.DataSource
@SpringBootApplication
@EnableTransactionManagement
class Application {
@Bean
fun objectMapper(): ObjectMapper {
val mapper:ObjectMapper = Jackson2ObjectMapperBuilder().modulesToInstall(PostGISModule()).build()
mapper.setSerializationInclusion(Include.NON_NULL)
return mapper
}
@Bean
fun transactionManager(dataSource: DataSource) = SpringTransactionManager(dataSource)
@Bean // PersistenceExceptionTranslationPostProcessor with proxyTargetClass=false, see https://github.com/spring-projects/spring-boot/issues/1844
fun persistenceExceptionTranslationPostProcessor() = PersistenceExceptionTranslationPostProcessor()
@Bean
fun init(ur: UserRepository, mr: MessageRepository) = CommandLineRunner {
ur.createTable()
mr.createTable()
mr.deleteAll()
ur.deleteAll()
ur.create(User("swhite", "Skyler", "White"))
ur.create(User("jpinkman", "Jesse", "Pinkman"))
ur.create(User("wwhite", "Walter", "White"))
ur.create(User("sgoodman", "Saul", "Goodman"))
mr.create(Message("I AM THE ONE WHO KNOCKS!", "wwhite"))
}
}
fun main(args: Array<String>) {
runApplication<Application>(*args)
}