Alfred Lopez
03/10/2021, 4:01 PMjbnizet
03/10/2021, 4:26 PMAlfred Lopez
03/10/2021, 4:29 PMAlfred Lopez
03/10/2021, 4:30 PMMyObject result = new MyObject();
Alfred Lopez
03/10/2021, 4:30 PMreturn result;
Alfred Lopez
03/10/2021, 4:30 PMAlfred Lopez
03/10/2021, 4:31 PMreturn new MyObject()
jbnizet
03/10/2021, 6:01 PMmyBean.foo
. Or just println(myBean.foo)
.Alfred Lopez
03/10/2021, 6:03 PMic. What I also found out is that although I'm getting different instances of the bean, I'm getting the same instance of the underlying object.
Alfred Lopez
03/10/2021, 6:04 PMAlfred Lopez
03/10/2021, 6:05 PMAlfred Lopez
03/10/2021, 6:05 PMjbnizet
03/10/2021, 6:06 PMAlfred Lopez
03/10/2021, 6:06 PMAlfred Lopez
03/10/2021, 6:06 PMAlfred Lopez
03/10/2021, 6:06 PMAlfred Lopez
03/10/2021, 6:07 PMjbnizet
03/10/2021, 6:07 PMAlfred Lopez
03/10/2021, 6:07 PMjbnizet
03/10/2021, 6:07 PMAlfred Lopez
03/10/2021, 6:07 PMAlfred Lopez
03/10/2021, 6:29 PMAlfred Lopez
03/10/2021, 6:32 PMAlfred Lopez
03/10/2021, 6:32 PMAlfred Lopez
03/10/2021, 6:33 PMAlfred Lopez
03/10/2021, 6:35 PMAlfred Lopez
03/10/2021, 6:36 PMAlfred Lopez
03/10/2021, 6:48 PMjbnizet
03/10/2021, 7:31 PMpackage com.example.demo
import org.springframework.boot.autoconfigure.SpringBootApplication
import org.springframework.boot.runApplication
import org.springframework.stereotype.Service
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RequestParam
import org.springframework.web.bind.annotation.RestController
import org.springframework.web.context.annotation.RequestScope
@SpringBootApplication
class DemoRequestScopeApplication
fun main(args: Array<String>) {
runApplication<DemoRequestScopeApplication>(*args)
}
@RestController
@RequestMapping("/demo")
class DemoController(private val demoService: DemoService, private val otherService: OtherService) {
@GetMapping
fun demo(@RequestParam value: String): String? {
val initialValue = otherService.demo()
demoService.storeValue(value)
val newValue = otherService.demo()
return "$initialValue - $newValue"
}
}
@Service
class OtherService(private val demoService: DemoService) {
fun demo(): String? = demoService.extractValue()
}
@Service
@RequestScope
class DemoService {
private val map = mutableMapOf<String, String>()
fun storeValue(value: String) {
map["value"] = value
}
fun extractValue(): String? = map["value"]
}
Alfred Lopez
03/10/2021, 7:34 PMAlfred Lopez
03/10/2021, 7:35 PM