Skip to content

Commit 6e6ed84

Browse files
committed
修复会话管理器配置
1 parent 84c780d commit 6e6ed84

File tree

5 files changed

+42
-19
lines changed

5 files changed

+42
-19
lines changed

hsweb-web-core/src/main/java/org/hsweb/web/core/session/redis/RedisHttpSessionManagerConfiguration.java

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import org.hsweb.web.core.session.HttpSessionManagerListener;
55
import org.springframework.beans.factory.annotation.Autowired;
66
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
7+
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
78
import org.springframework.context.annotation.Bean;
89
import org.springframework.context.annotation.Configuration;
910
import org.springframework.core.Ordered;
@@ -14,25 +15,17 @@
1415
import javax.annotation.Resource;
1516
import java.util.List;
1617

17-
/**
18-
* Created by zhouhao on 16-5-27.
19-
*/
2018
@Configuration
2119
@ConditionalOnBean(value = RedisOperationsSessionRepository.class, name = "sessionRedisTemplate")
22-
@Order(Ordered.HIGHEST_PRECEDENCE)
20+
@ConditionalOnWebApplication
2321
public class RedisHttpSessionManagerConfiguration {
24-
@Autowired(required = false)
25-
private List<HttpSessionManagerListener> httpSessionManagerListeners;
2622

2723
@Resource(name = "sessionRedisTemplate")
2824
private RedisTemplate sessionRedisTemplate;
2925

30-
@Bean
31-
public HttpSessionManager sessionListener(RedisOperationsSessionRepository repository) {
26+
@Bean(name = "httpSessionManager")
27+
public HttpSessionManager redisHttpSessionManager(RedisOperationsSessionRepository repository) {
3228
RedisHttpSessionManager redisHttpSessionManager = new RedisHttpSessionManager();
33-
if (httpSessionManagerListeners != null) {
34-
redisHttpSessionManager.setListeners(httpSessionManagerListeners);
35-
}
3629
redisHttpSessionManager.setSessionRedisTemplate(sessionRedisTemplate);
3730
redisHttpSessionManager.setRedisOperationsSessionRepository(repository);
3831
return redisHttpSessionManager;

hsweb-web-core/src/main/java/org/hsweb/web/core/session/simple/SimpleHttpSessionManagerAutoConfiguration.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,16 @@
1111
@ConditionalOnWebApplication
1212
public class SimpleHttpSessionManagerAutoConfiguration {
1313

14-
@Bean
15-
public HttpSessionManager simpleHttpSessionManager() {
14+
@Bean(name = "httpSessionManager")
15+
public HttpSessionManager httpSessionManager() {
1616
SimpleHttpSessionManager httpSessionManager = new SimpleHttpSessionManager();
1717
return httpSessionManager;
1818
}
1919

2020
@Bean
21-
public UserLoginOutListener sessionListener() {
21+
public UserLoginOutListener sessionListener(HttpSessionManager httpSessionManager) {
2222
UserLoginOutListener loginOutListener = new UserLoginOutListener();
23-
loginOutListener.setHttpSessionManager(simpleHttpSessionManager());
23+
loginOutListener.setHttpSessionManager(httpSessionManager);
2424
return loginOutListener;
2525
}
2626
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
local ids = redis.call('KEYS', 'http.session.user:*');
2+
local ids_ = {};
3+
for i, v in ipairs(ids) do
4+
5+
local userId = v:sub(19,-1);
6+
local sessoinId = redis.call('GET', v);
7+
local sessionExists = redis.call('EXISTS', 'spring:session:sessions:' .. sessoinId);
8+
if (sessionExists== 1)
9+
then
10+
table.insert(ids_, userId);
11+
else
12+
return sessoinId;
13+
-- redis.call("DEL", 'http.session.user:' .. userId);
14+
end
15+
end
16+
return ids_;

hsweb-web-service/hsweb-web-service-simple/src/main/java/org/hsweb/web/service/impl/FormDeployContextLoaderListener.java

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
package org.hsweb.web.service.impl;
22

3+
import org.hsweb.ezorm.meta.TableMetaData;
34
import org.hsweb.web.bean.common.QueryParam;
5+
import org.hsweb.web.bean.po.form.Form;
46
import org.hsweb.web.service.form.DynamicFormService;
57
import org.hsweb.web.service.form.FormService;
8+
import org.slf4j.Logger;
9+
import org.slf4j.LoggerFactory;
610
import org.springframework.beans.factory.InitializingBean;
711
import org.springframework.context.ApplicationContextInitializer;
812
import org.springframework.context.ApplicationEvent;
@@ -16,10 +20,12 @@
1620
@Component
1721
public class FormDeployContextLoaderListener implements ApplicationListener<ContextRefreshedEvent> {
1822
@Resource
19-
private FormService formService;
23+
private FormService formService;
2024
@Resource
2125
private DynamicFormService dynamicFormService;
2226

27+
private Logger logger = LoggerFactory.getLogger(this.getClass());
28+
2329
@Override
2430
public void onApplicationEvent(ContextRefreshedEvent event) {
2531
if (event.getApplicationContext().getParent() != null) return;
@@ -28,9 +34,15 @@ public void onApplicationEvent(ContextRefreshedEvent event) {
2834
try {
2935
formService.select(param).forEach(form -> {
3036
try {
31-
dynamicFormService.deploy(form);
37+
Form deployed = formService.selectDeployed(form.getName());
38+
if (null != deployed) {
39+
TableMetaData metaData = dynamicFormService.parseMeta(deployed);
40+
dynamicFormService.getDefaultDatabase().reloadTable(metaData);
41+
} else {
42+
dynamicFormService.deploy(form);
43+
}
3244
} catch (Exception e) {
33-
throw new RuntimeException(e);
45+
logger.error("部署{}:({})失败", form.getName(), form.getRemark(), e);
3446
}
3547
});
3648
} catch (Exception e) {

hsweb-web-service/hsweb-web-service-simple/src/main/java/org/hsweb/web/service/impl/form/DynamicFormServiceImpl.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,9 @@ public Database getDefaultDatabase() {
9898

9999
@Override
100100
public TableMetaData parseMeta(Form form) {
101-
return formParser.parse(form);
101+
TableMetaData metaData = formParser.parse(form);
102+
initDefaultField(metaData);
103+
return metaData;
102104
}
103105

104106
@Override

0 commit comments

Comments
 (0)