Skip to content

Instantly share code, notes, and snippets.

View Ozsie's full-sized avatar

Oscar Djupfeldt Ozsie

  • Abilia
  • Gothenburg, Sweden
View GitHub Profile
@Ozsie
Ozsie / application.properties
Created May 6, 2018 06:52
Application properties
server.port=0
@Ozsie
Ozsie / Controller.kt
Last active May 6, 2018 06:30
Controller
@RestController
@RequestMapping(value = ["/controller"])
class Controller {
@Autowired lateinit var cache: Cache
@GetMapping(path = ["{key}"])
fun getStuff(@PathVariable("key") key: String) = cache.getUUID(key)
}
@CacheConfig(cacheNames = ["map"])
@Ozsie
Ozsie / HazelcastApplication.kt
Created May 6, 2018 05:59
Hazelcast configuration bean
package com.github.ozsie.hazelcast
import com.hazelcast.config.Config
import com.hazelcast.config.EvictionPolicy
import com.hazelcast.config.MapConfig
import org.springframework.boot.autoconfigure.EnableAutoConfiguration
import org.springframework.boot.autoconfigure.SpringBootApplication
import org.springframework.boot.runApplication
import org.springframework.cache.annotation.EnableCaching
import org.springframework.context.annotation.Bean
@Ozsie
Ozsie / HazelcastApplication.kt
Created May 6, 2018 05:55
Basic application
package com.github.ozsie.hazelcast
import org.springframework.boot.autoconfigure.EnableAutoConfiguration
import org.springframework.boot.autoconfigure.SpringBootApplication
import org.springframework.boot.runApplication
@SpringBootApplication
@EnableAutoConfiguration
class HazelcastApplication
@Ozsie
Ozsie / pom.xml
Last active May 6, 2018 05:50
Hazelcast dependencies
<dependency>
<groupId>com.hazelcast</groupId>
<artifactId>hazelcast</artifactId>
</dependency>
<dependency>
<groupId>com.hazelcast</groupId>
<artifactId>hazelcast-spring</artifactId>
</dependency>
# suppress inspection "UnusedProperty" for whole file
context.initializer.classes=com.github.ozsie.webfluxtest.Beans
@Ozsie
Ozsie / Beans.kt
Last active April 15, 2018 12:43
package com.github.ozsie.webfluxtest
import com.github.ozsie.webfluxtest.handlers.ItemHandler
import com.github.ozsie.webfluxtest.routers.router
import org.springframework.context.ApplicationContextInitializer
import org.springframework.context.support.GenericApplicationContext
import org.springframework.context.support.beans
// See application.properties context.initializer.classes entry
class Beans : ApplicationContextInitializer<GenericApplicationContext> {
package com.github.ozsie.webfluxtest.routers
import com.github.ozsie.webfluxtest.handlers.ItemHandler
import org.springframework.http.MediaType.APPLICATION_JSON
import org.springframework.web.reactive.function.server.router
fun router(itemHandler: ItemHandler) = router {
accept(APPLICATION_JSON).nest {
"/api".nest {
"/items".nest {
@Ozsie
Ozsie / ItemHandler.kt
Last active April 15, 2018 11:51
Item handling functions
package com.github.ozsie.webfluxtest.handlers
import com.github.ozsie.webfluxtest.ItemRepository
import com.github.ozsie.webfluxtest.model.Item
import org.springframework.http.MediaType.APPLICATION_JSON
import org.springframework.web.reactive.function.server.ServerRequest
import org.springframework.web.reactive.function.server.ServerResponse
class ItemHandler(private val itemRepository: ItemRepository) {
package com.github.ozsie.webfluxtest.model
import org.springframework.data.annotation.Id
data class Item(@Id val id: String?, val value: String)