如何使用范围会话?

时间:2016-03-19 16:23:16

标签: java spring session scope javabeans

我的项目实际使用spring + gradle + thymeleaf系统,我想知道当我与其他用户登录时如何启动bean?
我试过了

public class UserData{
List<Questions> questions;
String message;
}
 //in my @Configuration class

   @Bean
   @Scope(proxyMode=ScopedProxyMode.TARGET_CLASS, value="session")
   @ScopedProxy
    public AdminData adminData(){
       return new AdminData();
    }

In my controller, I inject AdminData

    @Controller
    @RequestMapping(value = "/admin/question")
    public class QuestionAdminController {

       @Autowired
       private UserData userData;
    }

但它没有用,bean没有初始化。
我的WebSecurityConfigurerAdapter定义如下:

@Override
protected void configure(HttpSecurity http) throws Exception {
http.csrf().disable(); // temporary disabled for testing file upload
http.headers().frameOptions().disable(); // disabled for h2 console
// Roles permissions        
http.authorizeRequests()
        // Directories access permissions
        .antMatchers("/admin/**").access("hasRole('ADMIN')")
        // All user can access to new routes at the root
        .antMatchers("/**").permitAll()
        // Other requests need the login
        .anyRequest().authenticated()
        // Configure the login page
     .and().formLogin().loginPage("/login")
     .successHandler(customSuccessHandler).permitAll()
        // Default logout from Spring Security
        .and().logout().permitAll()
        .and()
        .sessionManagement()
        .maximumSessions(1).expiredUrl("/login?expired");

}

我不确定会议在注销后会在这里过期。

1 个答案:

答案 0 :(得分:0)

您是否在@configuration类中添加了@EnableAspectJAutoProxy? @scope注释要求spring aop在您的项目中处于活动状态