thread safe, stateless design using Spring thread safe, stateless design using Spring spring spring

thread safe, stateless design using Spring


Spring beans aren't stateless because they have state (fields). Technically they aren't even immutable because you can change injected fields at any time.

However you can easily make Spring beans immutable by using final fields and constructor injection. Also this kind of state is not problematic from scalability point of view. If your beans contain mutable values that change over time, this is a major issue when clustering. But in Spring services typically contain only dependencies injected at bootstrap time. So they are effectively stateless and immutable.

It doesn't matter on how many servers you run the same Spring application - the beans and dependencies themselves are safe. But if you Spring beans contain counters, caches, mutable maps, etc. - you need to think about them.