简体   繁体   English

每次检票口都有新豆

[英]new bean for every wicket session

I was creating my first application using Apache wicket and am stuck on a problem. 我正在使用Apache wicket创建第一个应用程序,但遇到了问题。 After the user logs in through the authentication method I have a new session which is created for that user. 用户通过身份验证方法登录后,我将为该用户创建一个新会话。 Now if I wanted to have data stored for just that user how would I use bean to implement that? 现在,如果我只想为该用户存储数据,我将如何使用bean来实现呢?

At the moment i created an interface and a class with get and set methods for the variables i wanted stored and created a bean such as <bean id="springApplicationContext" class="com..util.SpringApplicationContext"/> but what happens is the data gets overwritten but when i change the scope to "session" everyone has the same data in the bean still. 目前,我为要存储的变量创建了一个接口以及一个带有get和set方法的类,并创建了一个像<bean id="springApplicationContext" class="com..util.SpringApplicationContext"/>但发生了什么数据被覆盖,但是当我将范围更改为“会话”时,每个人在Bean中仍然拥有相同的数据。

Thanks 谢谢

The correct way is to use Session scoped Spring bean. 正确的方法是使用Session作用域的Spring bean。 There must be some error in your config if the data is visible to all users. 如果数据对所有用户可见,则配置中必须存在一些错误。 Using Spring has nothing to do with Wicket though! 但是,使用Spring与Wicket无关!

Alternative approach is to store your data in Wicket's Session class. 另一种方法是将数据存储在Wicket的Session类中。 Override MyApplication#newSession() method and return MySession class. 重写MyApplication#newSession()方法并返回MySession类。 The instance of MySession will be stored as an attribute in the HTTP session by Wicket. Wicket会将MySession的实例作为属性存储在HTTP会话中。 You can put any member fields inside MySession, eg; 您可以将任何成员字段放入MySession中,例如;

public class MySession extends WebSession {
  ...
  private MyBean myBean; 
  // setter and getter
  ... 
}

Then in your Wicket code use it with: MySession.get().getMyBean().setSome(thing); 然后在您的Wicket代码中将其用于: MySession.get().getMyBean().setSome(thing);

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

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