使用:EJB 3.1,JBoss AS 7,RestEasy。EJB 3.1 - 注入會話範圍Pojo
我有一個會話scoped bean,我想要用戶存儲會話的用戶信息。
import java.io.Serializable;
import javax.enterprise.context.SessionScoped
@SessionScoped
public class LoggedInUser implements Serializable {
private String id;
...
}
如果用戶打開我的web應用程序,過濾器提取包含用戶標識的頭信息(應用程序在webseal後面運行)。我需要創建一個登錄用戶對象(請參閱上面的LoggedInUser)(在調用ldap之後)。之後我想在不同的@Stateless Beans中注入這個LoggedInUser對象,但LoggedInUser總是「空」(成員爲空)。
進樣樣品:
@Path("/country")
@Stateless
public class CountryController extends AbstractController {
@Inject
private Logger LOGGER;
@Inject
private LoggedInUser loggedInUser;
//@Inject dont work too..
//private Instance<LoggedInUser> loggedInstance
什麼我錯了?
您應該顯示您認爲應填寫LoggedInUser字段的代碼。 – Deltharis 2014-09-01 09:25:34
填寫LoggedInUser字段的代碼尚不存在。 bean實例化後是否可以更改LoggedInUser字段?或者我必須在LoggedInUser中添加一個@PostContruct方法(所以我也必須在那裏讀取頭文件)。 – user2983732 2014-09-01 09:31:28