2017-05-07 60 views
0

我正在嘗試更改cookie名稱以及我的web領域的超時值。在Guice中爲Shiro設置屬性

這裏是我的境界: -

public class TTShiroWebModule extends ShiroWebModule 
{ 
    public TTShiroWebModule(ServletContext inServletContext) 
    { 
     super(inServletContext); 
    } 

    @SuppressWarnings("unchecked") 
    @Override 
    protected void configureShiroWeb() 
    { 
     bind(CacheManager.class).to(MemoryConstrainedCacheManager.class); 
     bindConstant().annotatedWith(Names.named("sessionManager.cookie.name")).to("SECURITYSESSIONID"); 
     bindConstant().annotatedWith(Names.named("securityManager.sessionManager.globalSessionTimeout")).to(3600000); 
     expose(CacheManager.class); 
     expose(WebSecurityManager.class); 

     addFilterChain("/login/*", ANON); 
     addFilterChain("/markup/*", USER, NO_SESSION_CREATION); 

     bindRealm().to(TestRealm.class); 
    } 

    @Override 
    protected void bindSessionManager(AnnotatedBindingBuilder<SessionManager> inBind) 
    { 
     inBind.to(DefaultWebSessionManager.class).asEagerSingleton(); 
    } 
} 

望着那回來的響應,它看起來像我們還在使用JSESSIONID。我究竟做錯了什麼?

我已經嘗試在安裝TTShiroWebModule之前放置bindConstant。似乎沒有工作。

回答

0

我改變了我的bindSessionManager方法是這樣的: -

@Override 
protected void bindSessionManager(AnnotatedBindingBuilder<SessionManager> inBind) 
{ 
    inBind.to(DefaultWebSessionManager.class).asEagerSingleton(); 
} 

看代碼,我不認爲這是一個更好的方式。不幸的是,setter方法沒有標記@Inject :(