浏览代码

新增默认的HttpSessionManager

周浩 9 年之前
父节点
当前提交
a62da51db1
共有 1 个文件被更改,包括 26 次插入0 次删除
  1. 26 0
      hsweb-web-core/src/main/java/org/hsweb/web/core/CoreAutoConfiguration.java

+ 26 - 0
hsweb-web-core/src/main/java/org/hsweb/web/core/CoreAutoConfiguration.java

@@ -1,7 +1,17 @@
 package org.hsweb.web.core;
 package org.hsweb.web.core;
 
 
+import org.hsweb.web.core.session.HttpSessionManager;
+import org.hsweb.web.core.session.redis.RedisHttpSessionManager;
+import org.hsweb.web.core.session.siample.SimpleHttpSessionManager;
+import org.hsweb.web.core.session.siample.UserLoginOutListener;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
+import org.springframework.context.annotation.Bean;
 import org.springframework.context.annotation.ComponentScan;
 import org.springframework.context.annotation.ComponentScan;
 import org.springframework.context.annotation.Configuration;
 import org.springframework.context.annotation.Configuration;
+import org.springframework.data.redis.core.RedisTemplate;
+
+import javax.servlet.http.HttpSessionListener;
 
 
 /**
 /**
  * Created by zhouhao on 16-5-6.
  * Created by zhouhao on 16-5-6.
@@ -9,4 +19,20 @@ import org.springframework.context.annotation.Configuration;
 @Configuration
 @Configuration
 @ComponentScan("org.hsweb.web.core")
 @ComponentScan("org.hsweb.web.core")
 public class CoreAutoConfiguration {
 public class CoreAutoConfiguration {
+
+    @Bean
+    @ConditionalOnMissingBean
+    public HttpSessionManager simpleHttpSessionManager() {
+        SimpleHttpSessionManager httpSessionManager = new SimpleHttpSessionManager();
+        return httpSessionManager;
+    }
+
+    @Bean
+    @ConditionalOnMissingBean(HttpSessionManager.class)
+    public HttpSessionListener sessionListener() {
+        UserLoginOutListener loginOutListener = new UserLoginOutListener();
+        loginOutListener.setHttpSessionManager(simpleHttpSessionManager());
+        return loginOutListener;
+    }
+
 }
 }