简体   繁体   English

即使多次调用,也只能创建一个spring bean

[英]Create a spring bean only once even though called multiple times

We have two applications communicating with each other. 我们有两个相互通信的应用程序。 When the user is authenticated in the 1st application, we want to pass the user context to the other one. 在第一个应用程序中对用户进行身份验证后,我们希望将用户上下文传递给另一个应用程序。

I want to create the user context for the other application and pass the same to the application but i want to limit the user context creation to only once. 我想为其他应用程序创建用户上下文,并将其传递给应用程序,但我想将用户上下文创建限制为一次。 Can this be achieved by specifying scope="singleton" ? 是否可以通过指定scope="singleton"来实现? Only thing is i will have to do this programatically since, my bean will only be instantiated once the first application authenticates the user. 唯一的事情是我将必须以编程方式执行此操作,因为仅当第一个应用程序对用户进行身份验证后,我的bean才会实例化。

All my services will be calling the 2nd application from the first application and i want to ensure that the user context (spring bean) for the 2nd application is created only once. 我所有的服务都将从第一个应用程序调用第二个应用程序,我想确保第二个应用程序的用户上下文(spring bean)仅创建一次。

Secondly, when a session time-out happens, i will have to freshly create the user context for the 2nd application. 其次,当会话超时发生时,我将不得不为第二个应用程序重新创建用户上下文。

Can someone guide me on this ? 有人可以指导我吗?

I don't think you'd want to pass the user context bean itself but exchange some sort of token. 我认为您不希望传递用户上下文Bean本身,而是交换某种令牌。 Spring uses SAML for single sign on, maybe take a look at that: http://docs.spring.io/spring-security-saml/docs/current/reference/html/configuration-sso.html Spring使用SAML进行单点登录,也许可以看看: http : //docs.spring.io/spring-security-saml/docs/current/reference/html/configuration-sso.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Java方法执行最后一次打印语句三次,即使该方法仅被调用一次 - Java method executes last print statement three times even though the method is only called once 即使重复多次,如何仅打印不同的 integer 值 - How to print only distinct integer values once even though they are repeated multiple times 方法被调用两次,即使它被调用了一次 - Method intercepted twice even though it was called once toString方法似乎只运行一次,即使它被称为多个 - toString method seems to be only working once even tho it is called multiple 即使代码只执行一次,Intellij断点也会停止执行两次 - Intellij break point stops execution two times even though code is executed only once 如何保证bean到Spring只能实例化一次 - How to guarantee a bean is instantiated only once by Spring 在Spring MVC中多次实例化Singleton bean? - Singleton bean instantiated multiple times in Spring MVC? 为什么即使我只调用了一次 super.speak(),这段代码在执行时也会打印两次“Woof”? - Why does this code print “Woof” twice when executed even though I only called super.speak() once? 查看多次调用Scoped Bean preRenderView方法 - View Scoped Bean preRenderView method being called multiple times @Repository中的Spring @PostConstruct函数被多次调用 - Spring @PostConstruct function in a @Repository called multiple times
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM