Skip to content

Commit

Permalink
Merge pull request iBase4J#26 from iBase4J/develop
Browse files Browse the repository at this point in the history
web数据缓存使用JSON格式
  • Loading branch information
iBase4J authored Aug 22, 2017
2 parents f5d2e35 + 4d248c1 commit 6412513
Show file tree
Hide file tree
Showing 11 changed files with 68 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;

/**
* 用户登录
Expand All @@ -50,8 +49,10 @@ public String getService() {
// 登录
@ApiOperation(value = "用户登录")
@PostMapping("app/login")
public Object login(@ApiParam(required = true, value = "登录帐号和密码") @RequestBody Login user, ModelMap modelMap,
HttpServletRequest request) {
public Object login(Login user, ModelMap modelMap, HttpServletRequest request) {
String uuid = request.getHeader("UUID");
org.springframework.util.Assert.notNull(uuid, "非法操作.");
user = WebUtil.getParameter(request, Login.class);
Assert.notNull(user.getAccount(), "ACCOUNT");
Assert.notNull(user.getPassword(), "PASSWORD");

Expand Down
1 change: 1 addition & 0 deletions iBase4J-Biz-Web/src/main/resources/Spring-config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
<!-- <import resource="spring/mq.xml"/> -->
<import resource="spring/dubbo.xml" />
<!-- <import resource="spring/motan.xml" /> -->
<import resource="spring/redis.xml" />
<import resource="spring/session.xml" />
<import resource="spring/shiro.xml" />
</beans>
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public void doFilter(ServletRequest servletRequest, ServletResponse response, Fi
if (isWhiteReq(request.getRequestURI())) {
chain.doFilter(request, response);
} else {
String token = request.getHeader("token");
String token = request.getHeader("UUID");
if (StringUtils.isNotBlank(token)) {
try {
Token tokenInfo = TokenUtil.getTokenInfo(token);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ public boolean preHandle(HttpServletRequest request, HttpServletResponse respons
try {
UserAgentInfo userAgentInfo = uasParser.parse(request.getHeader("user-agent"));
userAgent = userAgentInfo.getOsName() + " " + userAgentInfo.getType() + " " + userAgentInfo.getUaName();
String uuid = request.getHeader("UUID");
if ("unknown unknown unknown".equals(userAgent) && StringUtils.isNotBlank(uuid)) {
userAgent = uuid;
}
session.setAttribute(Constants.USER_AGENT, userAgent);
} catch (IOException e) {
logger.error("", e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public interface CacheManager {

void sadd(String key, Serializable value);

Set<Object> sall(String key);
Set<?> sall(String key);

boolean sdel(String key, Serializable value);
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,11 @@
* @author ShenHuaJie
* @version 2016年4月2日 下午4:17:22
*/
@SuppressWarnings({ "rawtypes", "unchecked" })
public final class RedisHelper implements CacheManager {
private RedisTemplate redisTemplate;
private RedisTemplate<Serializable, Serializable> redisTemplate;
private final Integer EXPIRE = PropertiesUtil.getInt("redis.expiration");

public void setRedisTemplate(RedisTemplate redisTemplate) {
public void setRedisTemplate(RedisTemplate<Serializable, Serializable> redisTemplate) {
this.redisTemplate = redisTemplate;
CacheUtil.setCacheManager(this);
}
Expand Down Expand Up @@ -136,7 +135,7 @@ public void sadd(String key, Serializable value) {
redisTemplate.boundSetOps(key).add(value);
}

public Set<Object> sall(String key) {
public Set<?> sall(String key) {
return redisTemplate.boundSetOps(key).members();
}

Expand Down
49 changes: 49 additions & 0 deletions iBase4J-Common/src/main/resources/spring/redis.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p" xmlns:c="http://www.springframework.org/schema/c"
xmlns="http://www.springframework.org/schema/beans" xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.0.xsd">
<!-- jedis 配置-->
<bean id="jedisPoolConfig" class="redis.clients.jedis.JedisPoolConfig" >
<!--最小空闲数-->
<property name="minIdle" value="${redis.minIdle}" />
<!--最大空闲数-->
<property name="maxIdle" value="${redis.maxIdle}" />
<!--最大连接数-->
<property name="maxTotal" value="${redis.maxTotal}" />
<!--最大建立连接等待时间-->
<property name="maxWaitMillis" value="${redis.maxWaitMillis}" />
<!--是否在从池中取出连接前进行检验,如果检验失败,则从池中去除连接并尝试取出另一个-->
<property name="testOnBorrow" value="${redis.testOnBorrow}" />
</bean >
<!-- redisCluster配置 -->
<!-- <bean id="redisClusterConfiguration" class="org.springframework.data.redis.connection.RedisClusterConfiguration">
<constructor-arg name="propertySource">
<bean id="resourcePropertySource" class="org.springframework.core.io.support.ResourcePropertySource"
c:name="redis.properties" c:resource="classpath:config/system.properties"/>
</bean>
</constructor-arg>
</bean> -->
<!-- redis服务器中心 -->
<bean id="jedisConnectionFactory" class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory"
p:host-name="${redis.host}" p:port="${redis.port}" p:password="${redis.password}"
p:pool-config-ref="jedisPoolConfig" p:timeout="${redis.timeout}" />
<!-- c:cluster-config-ref="redisClusterConfiguration" -->
<!-- 缓存序列化方式 -->
<bean id="keySerializer" class="org.springframework.data.redis.serializer.StringRedisSerializer" />
<bean id="valueSerializer" class="org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer" />
<!-- 缓存 -->
<bean id="redisTemplate" class="org.springframework.data.redis.core.RedisTemplate">
<property name="connectionFactory" ref="jedisConnectionFactory" />
<property name="keySerializer" ref="keySerializer" />
<property name="valueSerializer" ref="valueSerializer" />
<property name="hashKeySerializer" ref="keySerializer" />
<property name="hashValueSerializer" ref="valueSerializer" />
</bean>
<bean class="org.ibase4j.core.support.cache.RedisHelper" >
<property name="redisTemplate" ref="redisTemplate" />
</bean>
</beans>
1 change: 1 addition & 0 deletions iBase4J-Common/src/main/resources/spring/redisson.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<redisson:client id="redissonClient">
<redisson:single-server address="redis://${redis.host}:${redis.port}"
connect-timeout="${redis.timeout}" />
<!-- <redisson:cluster-servers /> -->
</redisson:client>
<bean class="org.ibase4j.core.support.cache.redisson.SpringCacheManager">
<property name="redisson" ref="redissonClient" />
Expand Down
29 changes: 1 addition & 28 deletions iBase4J-Common/src/main/resources/spring/session.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,33 +5,7 @@
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.0.xsd" default-autowire="byType">
<!-- jedis 配置-->
<bean id="jedisPoolConfig" class="redis.clients.jedis.JedisPoolConfig" >
<!--最小空闲数-->
<property name="minIdle" value="${redis.minIdle}" />
<!--最大空闲数-->
<property name="maxIdle" value="${redis.maxIdle}" />
<!--最大连接数-->
<property name="maxTotal" value="${redis.maxTotal}" />
<!--最大建立连接等待时间-->
<property name="maxWaitMillis" value="${redis.maxWaitMillis}" />
<!--是否在从池中取出连接前进行检验,如果检验失败,则从池中去除连接并尝试取出另一个-->
<property name="testOnBorrow" value="${redis.testOnBorrow}" />
</bean >
<!-- redisCluster配置 -->
<!-- <bean id="redisClusterConfiguration" class="org.springframework.data.redis.connection.RedisClusterConfiguration">
<constructor-arg name="propertySource">
<bean id="resourcePropertySource" class="org.springframework.core.io.support.ResourcePropertySource">
<constructor-arg name="name" value="redis.properties"/>
<constructor-arg name="resource" value="classpath:config/system.properties"/>
</bean>
</constructor-arg>
</bean> -->
<!-- redis服务器中心 -->
<bean id="jedisConnectionFactory" class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory"
p:host-name="${redis.host}" p:port="${redis.port}" p:password="${redis.password}"
p:pool-config-ref="jedisPoolConfig" p:timeout="${redis.timeout}" />
http://www.springframework.org/schema/context/spring-context-4.0.xsd">
<!-- SPRING-SESSION -->
<bean class="org.springframework.session.data.redis.config.annotation.web.http.RedisHttpSessionConfiguration">
<property name="maxInactiveIntervalInSeconds" value="${session.maxInactiveInterval}" />
Expand All @@ -52,5 +26,4 @@
<property name="cookiePath" value="/" />
<property name="domainNamePattern" value="^.+?\\.(\\w+\\.[a-z]+)$"/>
</bean>
<bean class="org.ibase4j.core.support.cache.RedisHelper" />
</beans>
8 changes: 2 additions & 6 deletions iBase4J-SYS-Service/src/main/resources/config/jdbc.properties
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,15 @@ db.writer.password=yYEtaRoo3QHpKaWpBJTW17==
db.initialSize=5
#\u5b9a\u4e49\u6700\u5927\u8fde\u63a5\u6570
db.maxActive=20
#\u5b9a\u4e49\u6700\u5927\u7a7a\u95f2
db.maxIdle=10
#\u5b9a\u4e49\u6700\u5c0f\u7a7a\u95f2
db.minIdle=1
db.minIdle=5
#\u5b9a\u4e49\u6700\u957f\u7b49\u5f85\u65f6\u95f4
db.maxWait=60000
#
db.timeBetweenEvictionRunsMillis=3000
db.timeBetweenEvictionRunsMillis=30000
#
db.minEvictableIdleTimeMillis=300000
#
db.maxPoolPreparedStatementPerConnectionSize=10
#
druid.filters=
#
db.reader.list.maxThread=5
1 change: 1 addition & 0 deletions iBase4J-SYS-Web/src/main/resources/Spring-config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
<!-- <import resource="spring/mq.xml"/> -->
<!-- <import resource="spring/dubbo.xml" /> -->
<import resource="spring/motan.xml" />
<import resource="spring/redis.xml" />
<import resource="spring/session.xml" />
<import resource="spring/shiro.xml" />
</beans>

0 comments on commit 6412513

Please sign in to comment.