简体   繁体   English

春天的抽象类变量

[英]Abstract class variable with spring

I am using spring and Hibernate and Dao design pattern for the my project, In my GenericDaoImpl (Abstract class) class has "tenentId", I want to set the "tenentId" when use login to the System. 我在我的项目中使用spring和Hibernate和Dao设计模式,在我的GenericDaoImpl (抽象类)类中具有“ tenentId”,我想在登录系统时设置“ tenentId”。 My other DaoImpl classes extends from GenericDaoImpl , so I need to set the tenentId(It's define in GenericDaoImpl ) user login time and reset the "tenentId" when user log out. 我的其他DaoImpl类继承自GenericDaoImpl ,所以我需要设置tenentId(在GenericDaoImpl定义)用户登录时间,并在用户注销时重置“ tenentId”。

What is the best way to do this? 做这个的最好方式是什么?

In my test cases I tried @Autowired the "GenericDaoImpl" but I couldn't do that, It throws an exception telling, org.springframework.beans.factory.NoSuchBeanDefinitionException: No unique bean of type . 在我的测试案例中,我尝试了@Autowired“ GenericDaoImpl”,但我无法做到这一点,它抛出一个异常告诉org.springframework.beans.factory.NoSuchBeanDefinitionException: No unique bean of type I know the problem now, 我知道问题了

(We can't create instance of abstract classes,if use tenantId as static variable, is it going to be a problem?) Can any one suggest me any solution? (如果使用tenantId作为静态变量,我们将无法创建抽象类的实例,这会有问题吗?)有人可以建议我任何解决方案吗?

Thank you, Udeshika 谢谢Udeshika

if you are developing multi-tenancy application and would like to have tenant aware application context then have a look spring-tenancy . 如果您正在开发多租户应用程序,并且希望拥有租户感知的应用程序上下文,那么请查看spring-tenancy This will help you to have beans injected which are tenant aware. 这将帮助您注入具有租户意识的bean。

if you want to multi-tenancy at hibernate layer then you can also look at multi-tenancy feature of hibernate. 如果您想在休眠层进行多租户,那么您还可以查看休眠的多租户功能。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM