-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Make RedisOperationsSessionRepository.RedisSession public #1154
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
@vijayaggarwal You should code against Spring Session's public APIs, rather than implementation. Here's an some examples: Raw type approach: class RawConsumer {
@Autowired
private FindByIndexNameSessionRepository sessionRepository;
void consume() {
Session session = (Session) this.sessionRepository
.findByIndexNameAndIndexValue(FindByIndexNameSessionRepository.PRINCIPAL_NAME_INDEX_NAME, "principal")
.values().iterator().next();
session.setAttribute("test", UUID.randomUUID().toString());
this.sessionRepository.save(session);
}
} Parameterized type approach: class ParameterizedConsumer<S extends Session> {
@Autowired
private FindByIndexNameSessionRepository<S> sessionRepository;
void consume() {
S session = this.sessionRepository
.findByIndexNameAndIndexValue(FindByIndexNameSessionRepository.PRINCIPAL_NAME_INDEX_NAME, "principal")
.values().iterator().next();
session.setAttribute("test", UUID.randomUUID().toString());
this.sessionRepository.save(session);
}
} See also #849. Closing as answered. If you have additional questions or feel that your original question isn't properly answered, please re-open the issue. |
Thanks for the reply @vpavic! Your example works as you are not calling
I can use raw type (i.e. |
@vpavic Also, I cannot re-open this issue. Please consider re-opening it or suggest some other way forward. Thanks a lot! |
Sorry for confusion @vijayaggarwal, I've pasted the wrong example in my answer (though I've linked an issue that contained it) - I've updated the previous comment to address that. |
Thanks @vpavic! I will definitely prefer If I try to create an instance of So, I can't use your parameterized type approach as I can't create an instance of Also, if |
That shouldn't be the case. We have quite a few |
AKAIK, that's how Java works. I looked through Lines 81 to 82 in 003996a
Lines 127 to 130 in 003996a
Suppressing type checks works but isn't desirable. There should be a better way. |
Exactly, that's the point, hence the Lines 123 to 131 in 7fdf287
|
Ah, got it now! Registering as bean does the trick. If @Component
class MyController<S extends Session> {
@Autowired
SessionRepository<S> sessionRepo;
public void myMethod() {
S session = sessionRepo.createSession();
session.setAttribute("key", "value");
sessionRepo.save(session);
}
} I never specified what Closing the issue. Thanks a lot for help @vpavic! |
Btw, somewhat in relation to #114 also, if you think it helps to add a sample project on custom SessionRepository, I can submit a PR. |
Thanks for following up @vijayaggarwal, glad to hear you had this resolved.
Regarding this, please drop a note on #114 itself, since that issue is still open. Thanks! |
I use spring-session in a non-HTTP setup. I grab an instance of
RedisOperationsSessionRepository
and use it to create and save sessions. However,RedisOperationsSessionRepository
creates sessions to typeRedisSession
, which is non-Public. This severely limits my ability to work withRedisSession
s.PS: I found #114 and #725 to be somewhat related to this one, so mentioning them here.
The text was updated successfully, but these errors were encountered: