-
Notifications
You must be signed in to change notification settings - Fork 40.9k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Remove spring.session.store-type in favor of a defined order for which implementation will win when multiple are available #27756
Comments
We've decided to reorder things a bit. We'd like the order to be:
|
We stumbled across this today, when adding a optional support for a Redis session store to an app we look after which is deployed with different session stores by different users. Previously we thought we had been using I tried implemented the suggestion above, e.g. the following looked to be a simple low-impact change to have the desired effect: import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.autoconfigure.session.HazelcastSessionConfiguration;
import org.springframework.boot.autoconfigure.session.JdbcSessionConfiguration;
import org.springframework.boot.autoconfigure.session.RedisSessionConfiguration;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
@Configuration
public class SessionStore {
@ConditionalOnProperty(value = "myapp.session.store-type", havingValue = "hazelcast")
@Import({HazelcastSessionConfiguration.class})
static class HazelcastSession {}
@ConditionalOnProperty(value = "myapp.web.session.store-type", havingValue = "jdbc")
@Import({JdbcSessionConfiguration.class})
static class JdbcSession {}
@ConditionalOnProperty(value = "myapp.web.session.store-type", havingValue = "redis")
@Import({RedisSessionConfiguration.class})
static class RedisSession {}
} The intention being that this would have the side effect of putting
Can anyone suggest a straight forward alternative approach? |
I found these 3 classes which preliminary testing seems to work for our use-case using the pattern above: import org.springframework.session.data.redis.config.annotation.web.http.RedisHttpSessionConfiguration;
import org.springframework.session.hazelcast.config.annotation.web.http.HazelcastHttpSessionConfiguration;
import org.springframework.session.jdbc.config.annotation.web.http.JdbcHttpSessionConfiguration; |
Looking at #27738 caused us to realize that the auto-configuration for Spring Session is more complex than it needs to be. To simplify it, we'd like to remove
spring.session.store-type
. In the unlikely event that multiple session repository implementations are available we should define and document which will be used, just as we do for JDBC connection pools today. If for some reason a user needs multiple session repository implementations on the classpath and our defined ordering doesn't meet their needs, they can define their ownSessionRepository
bean and cause the auto-configuration to back off.The text was updated successfully, but these errors were encountered: