提交修改 token 重新生成问题

This commit is contained in:
qiurunze 2018-12-05 11:48:02 +08:00
parent a07f9a4cba
commit c700c1a307
40 changed files with 999 additions and 1054 deletions

View File

@ -1,13 +0,0 @@
<component name="libraryTable">
<library name="Maven: org.apache.tomcat.embed:tomcat-embed-core:8.5.23">
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/org/apache/tomcat/embed/tomcat-embed-core/8.5.23/tomcat-embed-core-8.5.23.jar!/" />
</CLASSES>
<JAVADOC>
<root url="jar://$MAVEN_REPOSITORY$/org/apache/tomcat/embed/tomcat-embed-core/8.5.23/tomcat-embed-core-8.5.23-javadoc.jar!/" />
</JAVADOC>
<SOURCES>
<root url="jar://$MAVEN_REPOSITORY$/org/apache/tomcat/embed/tomcat-embed-core/8.5.23/tomcat-embed-core-8.5.23-sources.jar!/" />
</SOURCES>
</library>
</component>

View File

@ -1,13 +0,0 @@
<component name="libraryTable">
<library name="Maven: org.apache.tomcat.embed:tomcat-embed-websocket:8.5.23">
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/org/apache/tomcat/embed/tomcat-embed-websocket/8.5.23/tomcat-embed-websocket-8.5.23.jar!/" />
</CLASSES>
<JAVADOC>
<root url="jar://$MAVEN_REPOSITORY$/org/apache/tomcat/embed/tomcat-embed-websocket/8.5.23/tomcat-embed-websocket-8.5.23-javadoc.jar!/" />
</JAVADOC>
<SOURCES>
<root url="jar://$MAVEN_REPOSITORY$/org/apache/tomcat/embed/tomcat-embed-websocket/8.5.23/tomcat-embed-websocket-8.5.23-sources.jar!/" />
</SOURCES>
</library>
</component>

View File

@ -1,13 +0,0 @@
<component name="libraryTable">
<library name="Maven: org.apache.tomcat:tomcat-annotations-api:8.5.23">
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/org/apache/tomcat/tomcat-annotations-api/8.5.23/tomcat-annotations-api-8.5.23.jar!/" />
</CLASSES>
<JAVADOC>
<root url="jar://$MAVEN_REPOSITORY$/org/apache/tomcat/tomcat-annotations-api/8.5.23/tomcat-annotations-api-8.5.23-javadoc.jar!/" />
</JAVADOC>
<SOURCES>
<root url="jar://$MAVEN_REPOSITORY$/org/apache/tomcat/tomcat-annotations-api/8.5.23/tomcat-annotations-api-8.5.23-sources.jar!/" />
</SOURCES>
</library>
</component>

View File

@ -1,13 +0,0 @@
<component name="libraryTable">
<library name="Maven: org.springframework.boot:spring-boot-starter-tomcat:1.5.8.RELEASE">
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/org/springframework/boot/spring-boot-starter-tomcat/1.5.8.RELEASE/spring-boot-starter-tomcat-1.5.8.RELEASE.jar!/" />
</CLASSES>
<JAVADOC>
<root url="jar://$MAVEN_REPOSITORY$/org/springframework/boot/spring-boot-starter-tomcat/1.5.8.RELEASE/spring-boot-starter-tomcat-1.5.8.RELEASE-javadoc.jar!/" />
</JAVADOC>
<SOURCES>
<root url="jar://$MAVEN_REPOSITORY$/org/springframework/boot/spring-boot-starter-tomcat/1.5.8.RELEASE/spring-boot-starter-tomcat-1.5.8.RELEASE-sources.jar!/" />
</SOURCES>
</library>
</component>

View File

@ -7,7 +7,7 @@
</list>
</option>
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" project-jdk-name="1.7" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/classes" />
</component>
</project>

File diff suppressed because it is too large Load Diff

View File

@ -52,7 +52,7 @@
监控工具:1.nginx_status并发统计,Ngxtop缓存统计
### nginx负载均衡
![整体流程](http://i2.bvimg.com/601558/23f54a389b2b23e8.png)
![整体流程](https://raw.githubusercontent.com/qiurunze123/imageall/master/miaosha2.png)
### <font color=#0099ff size=3 >8.服务降级--服务熔断(过载保护)</font><br>
@ -97,7 +97,7 @@ redis的数量不是库存,他的作用仅仅只是为了阻挡多余的请求
### <font color=#0099ff size=3 >15.为什么threadlocal存储user对象原理</font><br>
![整体流程](http://i2.bvimg.com/601558/3293e36cc2c7e303.png)
![整体流程](https://raw.githubusercontent.com/qiurunze123/imageall/master/miaosha1.png)
1.并发编程中重要的问题就是数据共享,当你在一个线程中改变任意属性时,所有的线程都会因此受到影响,同时会看到第一个线程修改后的值<br>
有时我们希望如此,比如:多个线程增大或减小同一个计数器变量<br>

View File

@ -40,23 +40,25 @@
<orderEntry type="library" name="Maven: org.slf4j:jul-to-slf4j:1.7.25" level="project" />
<orderEntry type="library" name="Maven: org.slf4j:log4j-over-slf4j:1.7.25" level="project" />
<orderEntry type="library" name="Maven: org.springframework:spring-core:4.3.12.RELEASE" level="project" />
<orderEntry type="library" name="Maven: org.yaml:snakeyaml:1.17" level="project" />
<orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-starter-tomcat:1.5.8.RELEASE" level="project" />
<orderEntry type="library" name="Maven: org.apache.tomcat.embed:tomcat-embed-core:8.5.23" level="project" />
<orderEntry type="library" name="Maven: org.apache.tomcat:tomcat-annotations-api:8.5.23" level="project" />
<orderEntry type="library" name="Maven: org.apache.tomcat.embed:tomcat-embed-websocket:8.5.23" level="project" />
<orderEntry type="library" scope="RUNTIME" name="Maven: org.yaml:snakeyaml:1.17" level="project" />
<orderEntry type="library" name="Maven: org.hibernate:hibernate-validator:5.3.5.Final" level="project" />
<orderEntry type="library" name="Maven: javax.validation:validation-api:1.1.0.Final" level="project" />
<orderEntry type="library" name="Maven: org.jboss.logging:jboss-logging:3.3.1.Final" level="project" />
<orderEntry type="library" name="Maven: com.fasterxml:classmate:1.3.4" level="project" />
<orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-databind:2.8.10" level="project" />
<orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-annotations:2.8.0" level="project" />
<orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-core:2.8.10" level="project" />
<orderEntry type="library" name="Maven: org.springframework:spring-web:4.3.12.RELEASE" level="project" />
<orderEntry type="library" name="Maven: org.springframework:spring-aop:4.3.12.RELEASE" level="project" />
<orderEntry type="library" name="Maven: org.springframework:spring-beans:4.3.12.RELEASE" level="project" />
<orderEntry type="library" name="Maven: org.springframework:spring-context:4.3.12.RELEASE" level="project" />
<orderEntry type="library" name="Maven: org.springframework:spring-webmvc:4.3.12.RELEASE" level="project" />
<orderEntry type="library" name="Maven: org.springframework:spring-expression:4.3.12.RELEASE" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: org.springframework.boot:spring-boot-starter-tomcat:1.5.8.RELEASE" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: org.apache.tomcat.embed:tomcat-embed-core:8.5.23" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: org.apache.tomcat:tomcat-annotations-api:8.5.23" level="project" />
<orderEntry type="library" name="Maven: org.apache.tomcat.embed:tomcat-embed-el:8.5.23" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: org.apache.tomcat.embed:tomcat-embed-websocket:8.5.23" level="project" />
<orderEntry type="library" name="Maven: com.google.guava:guava:18.0" level="project" />
<orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-starter-thymeleaf:1.5.8.RELEASE" level="project" />
<orderEntry type="library" name="Maven: org.thymeleaf:thymeleaf-spring4:2.1.5.RELEASE" level="project" />
@ -81,7 +83,6 @@
<orderEntry type="library" name="Maven: commons-codec:commons-codec:1.10" level="project" />
<orderEntry type="library" name="Maven: org.apache.commons:commons-lang3:3.6" level="project" />
<orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-starter-validation:1.5.8.RELEASE" level="project" />
<orderEntry type="library" name="Maven: org.apache.tomcat.embed:tomcat-embed-el:8.5.23" level="project" />
<orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-starter-amqp:1.5.8.RELEASE" level="project" />
<orderEntry type="library" name="Maven: org.springframework:spring-messaging:4.3.12.RELEASE" level="project" />
<orderEntry type="library" name="Maven: org.springframework.amqp:spring-rabbit:1.7.4.RELEASE" level="project" />
@ -93,25 +94,6 @@
<orderEntry type="library" name="Maven: org.springframework.amqp:spring-amqp:1.7.4.RELEASE" level="project" />
<orderEntry type="library" name="Maven: org.springframework:spring-tx:4.3.12.RELEASE" level="project" />
<orderEntry type="library" name="Maven: joda-time:joda-time:2.3" level="project" />
<orderEntry type="library" name="Maven: org.redisson:redisson:2.14.0" level="project" />
<orderEntry type="library" name="Maven: io.netty:netty-common:4.1.30.Final" level="project" />
<orderEntry type="library" name="Maven: io.netty:netty-codec:4.1.30.Final" level="project" />
<orderEntry type="library" name="Maven: io.netty:netty-buffer:4.1.30.Final" level="project" />
<orderEntry type="library" name="Maven: io.netty:netty-transport:4.1.30.Final" level="project" />
<orderEntry type="library" name="Maven: io.netty:netty-resolver:4.1.30.Final" level="project" />
<orderEntry type="library" name="Maven: io.netty:netty-resolver-dns:4.1.30.Final" level="project" />
<orderEntry type="library" name="Maven: io.netty:netty-codec-dns:4.1.30.Final" level="project" />
<orderEntry type="library" name="Maven: io.netty:netty-handler:4.1.30.Final" level="project" />
<orderEntry type="library" name="Maven: javax.cache:cache-api:1.0.0" level="project" />
<orderEntry type="library" name="Maven: io.projectreactor:reactor-stream:2.0.8.RELEASE" level="project" />
<orderEntry type="library" name="Maven: io.projectreactor:reactor-core:2.0.8.RELEASE" level="project" />
<orderEntry type="library" name="Maven: io.reactivex.rxjava2:rxjava:2.1.13" level="project" />
<orderEntry type="library" name="Maven: org.reactivestreams:reactive-streams:1.0.2" level="project" />
<orderEntry type="library" name="Maven: com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:2.8.10" level="project" />
<orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-core:2.8.10" level="project" />
<orderEntry type="library" name="Maven: net.bytebuddy:byte-buddy:1.8.17" level="project" />
<orderEntry type="library" name="Maven: org.jodd:jodd-bean:3.7.1" level="project" />
<orderEntry type="library" name="Maven: org.jodd:jodd-core:3.7.1" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: org.projectlombok:lombok:1.18.2" level="project" />
</component>
</module>

26
pom.xml
View File

@ -46,10 +46,26 @@
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<!--打包的时候可以不用包进去,别的设施会提供。事实上该依赖理论上可以参与编译,测试,运行等周期。
相当于compile但是打包阶段做了exclude操作-->
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
@ -123,11 +139,11 @@
<version>2.3</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.redisson/redisson -->
<dependency>
<groupId>org.redisson</groupId>
<artifactId>redisson</artifactId>
<version>2.14.0</version>
</dependency>
<!--<dependency>-->
<!--<groupId>org.redisson</groupId>-->
<!--<artifactId>redisson</artifactId>-->
<!--<version>2.14.0</version>-->
<!--</dependency>-->
<dependency>
<groupId>org.springframework.boot</groupId>

View File

@ -11,9 +11,6 @@ import org.springframework.web.context.request.NativeWebRequest;
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
import org.springframework.web.method.support.ModelAndViewContainer;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
@Service
public class UserArgumentResolver implements HandlerMethodArgumentResolver {
@ -41,13 +38,4 @@ public class UserArgumentResolver implements HandlerMethodArgumentResolver {
return UserContext.getUser();
}
private String getCookieValue(HttpServletRequest request, String cookiName) {
Cookie[] cookies = request.getCookies();
for(Cookie cookie : cookies) {
if(cookie.getName().equals(cookiName)) {
return cookie.getValue();
}
}
return null;
}
}

View File

@ -93,7 +93,7 @@ public class MiaoshaController implements InitializingBean {
return Result.error(CodeMsg.MIAO_SHA_OVER);
}
//预见库存
long stock = redisService.decr(GoodsKey.getMiaoshaGoodsStock,""+goodsId) ;
Long stock = redisService.decr(GoodsKey.getMiaoshaGoodsStock,""+goodsId) ;
if(stock <0){
localOverMap.put(goodsId, true);
return Result.error(CodeMsg.MIAO_SHA_OVER);
@ -162,6 +162,10 @@ public class MiaoshaController implements InitializingBean {
}
}
/**
* 系统初始化
* @throws Exception
*/
@Override
public void afterPropertiesSet() throws Exception {
List<GoodsVo> goodsList= goodsService.listGoodsVo();

View File

@ -1,76 +1,76 @@
package com.geekq.miaosha.redis;
import org.apache.commons.lang3.StringUtils;
import org.redisson.Redisson;
import org.redisson.api.RedissonClient;
import org.redisson.config.Config;
import org.redisson.config.SentinelServersConfig;
import org.redisson.config.SingleServerConfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
@ConditionalOnClass(Config.class)
@EnableConfigurationProperties(RedissonProperties.class)
public class RedissonAutoConfiguration {
@Autowired
private RedissonProperties redssionProperties;
/**
* 哨兵模式自动装配
* @return
*/
@Bean
@ConditionalOnProperty(name="redisson.master-name")
RedissonClient redissonSentinel() {
Config config = new Config();
SentinelServersConfig serverConfig = config.useSentinelServers().addSentinelAddress(redssionProperties.getSentinelAddresses())
.setMasterName(redssionProperties.getMasterName())
.setTimeout(redssionProperties.getTimeout())
.setMasterConnectionPoolSize(redssionProperties.getMasterConnectionPoolSize())
.setSlaveConnectionPoolSize(redssionProperties.getSlaveConnectionPoolSize());
if(StringUtils.isNotBlank(redssionProperties.getPassword())) {
serverConfig.setPassword(redssionProperties.getPassword());
}
return Redisson.create(config);
}
/**
* 单机模式自动装配
* @return
*/
@Bean
@ConditionalOnProperty(name="redisson.address")
RedissonClient redissonSingle() {
Config config = new Config();
SingleServerConfig serverConfig = config.useSingleServer()
.setAddress(redssionProperties.getAddress())
.setTimeout(redssionProperties.getTimeout())
.setConnectionPoolSize(redssionProperties.getConnectionPoolSize())
.setConnectionMinimumIdleSize(redssionProperties.getConnectionMinimumIdleSize());
if(StringUtils.isNotBlank(redssionProperties.getPassword())) {
serverConfig.setPassword(redssionProperties.getPassword());
}
return Redisson.create(config);
}
/**
* 装配locker类并将实例注入到RedissLockUtil中
* @return
*/
@Bean
DistributedLocker distributedLocker(RedissonClient redissonSingle) {
RedissonDistributedLocker locker = new RedissonDistributedLocker();
locker.setRedissonClient(redissonSingle);
RedissLockUtil.setLocker(locker);
return locker;
}
}
//package com.geekq.miaosha.redis;
//
//import org.apache.commons.lang3.StringUtils;
//import org.redisson.Redisson;
//import org.redisson.api.RedissonClient;
//import org.redisson.config.Config;
//import org.redisson.config.SentinelServersConfig;
//import org.redisson.config.SingleServerConfig;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
//import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
//import org.springframework.boot.context.properties.EnableConfigurationProperties;
//import org.springframework.context.annotation.Bean;
//import org.springframework.context.annotation.Configuration;
//
//@Configuration
//@ConditionalOnClass(Config.class)
//@EnableConfigurationProperties(RedissonProperties.class)
//public class RedissonAutoConfiguration {
//
// @Autowired
// private RedissonProperties redssionProperties;
//
// /**
// * 哨兵模式自动装配
// * @return
// */
// @Bean
// @ConditionalOnProperty(name="redisson.master-name")
// RedissonClient redissonSentinel() {
// Config config = new Config();
// SentinelServersConfig serverConfig = config.useSentinelServers().addSentinelAddress(redssionProperties.getSentinelAddresses())
// .setMasterName(redssionProperties.getMasterName())
// .setTimeout(redssionProperties.getTimeout())
// .setMasterConnectionPoolSize(redssionProperties.getMasterConnectionPoolSize())
// .setSlaveConnectionPoolSize(redssionProperties.getSlaveConnectionPoolSize());
//
// if(StringUtils.isNotBlank(redssionProperties.getPassword())) {
// serverConfig.setPassword(redssionProperties.getPassword());
// }
// return Redisson.create(config);
// }
//
// /**
// * 单机模式自动装配
// * @return
// */
// @Bean
// @ConditionalOnProperty(name="redisson.address")
// RedissonClient redissonSingle() {
// Config config = new Config();
// SingleServerConfig serverConfig = config.useSingleServer()
// .setAddress(redssionProperties.getAddress())
// .setTimeout(redssionProperties.getTimeout())
// .setConnectionPoolSize(redssionProperties.getConnectionPoolSize())
// .setConnectionMinimumIdleSize(redssionProperties.getConnectionMinimumIdleSize());
//
// if(StringUtils.isNotBlank(redssionProperties.getPassword())) {
// serverConfig.setPassword(redssionProperties.getPassword());
// }
//
// return Redisson.create(config);
// }
//
// /**
// * 装配locker类并将实例注入到RedissLockUtil中
// * @return
// */
// @Bean
// DistributedLocker distributedLocker(RedissonClient redissonSingle) {
// RedissonDistributedLocker locker = new RedissonDistributedLocker();
// locker.setRedissonClient(redissonSingle);
// RedissLockUtil.setLocker(locker);
// return locker;
// }
//}

View File

@ -1,39 +1,39 @@
package com.geekq.miaosha.redis;
import org.redisson.api.RLock;
import org.redisson.api.RedissonClient;
import java.util.concurrent.TimeUnit;
public class RedissonDistributedLocker implements DistributedLocker {
private RedissonClient redissonClient;
@Override
public void lock(String lockKey) {
RLock lock = redissonClient.getLock(lockKey);
lock.lock();
}
@Override
public void unlock(String lockKey) {
RLock lock = redissonClient.getLock(lockKey);
lock.unlock();
}
@Override
public void lock(String lockKey, int leaseTime) {
RLock lock = redissonClient.getLock(lockKey);
lock.lock(leaseTime, TimeUnit.SECONDS);
}
@Override
public void lock(String lockKey, TimeUnit unit ,int timeout) {
RLock lock = redissonClient.getLock(lockKey);
lock.lock(timeout, unit);
}
public void setRedissonClient(RedissonClient redissonClient) {
this.redissonClient = redissonClient;
}
}
//package com.geekq.miaosha.redis;
//
//import org.redisson.api.RLock;
//import org.redisson.api.RedissonClient;
//
//import java.util.concurrent.TimeUnit;
//
//public class RedissonDistributedLocker implements DistributedLocker {
//
// private RedissonClient redissonClient;
//
// @Override
// public void lock(String lockKey) {
// RLock lock = redissonClient.getLock(lockKey);
// lock.lock();
// }
//
// @Override
// public void unlock(String lockKey) {
// RLock lock = redissonClient.getLock(lockKey);
// lock.unlock();
// }
//
// @Override
// public void lock(String lockKey, int leaseTime) {
// RLock lock = redissonClient.getLock(lockKey);
// lock.lock(leaseTime, TimeUnit.SECONDS);
// }
//
// @Override
// public void lock(String lockKey, TimeUnit unit ,int timeout) {
// RLock lock = redissonClient.getLock(lockKey);
// lock.lock(timeout, unit);
// }
//
// public void setRedissonClient(RedissonClient redissonClient) {
// this.redissonClient = redissonClient;
// }
//}

View File

@ -1,98 +1,98 @@
package com.geekq.miaosha.redis;
import org.springframework.boot.context.properties.ConfigurationProperties;
@ConfigurationProperties(prefix = "redisson")
public class RedissonProperties {
private int timeout = 3000;
private String address;
private String password;
private int connectionPoolSize = 64;
private int connectionMinimumIdleSize=10;
private int slaveConnectionPoolSize = 250;
private int masterConnectionPoolSize = 250;
private String[] sentinelAddresses;
private String masterName;
public int getTimeout() {
return timeout;
}
public void setTimeout(int timeout) {
this.timeout = timeout;
}
public int getSlaveConnectionPoolSize() {
return slaveConnectionPoolSize;
}
public void setSlaveConnectionPoolSize(int slaveConnectionPoolSize) {
this.slaveConnectionPoolSize = slaveConnectionPoolSize;
}
public int getMasterConnectionPoolSize() {
return masterConnectionPoolSize;
}
public void setMasterConnectionPoolSize(int masterConnectionPoolSize) {
this.masterConnectionPoolSize = masterConnectionPoolSize;
}
public String[] getSentinelAddresses() {
return sentinelAddresses;
}
public void setSentinelAddresses(String sentinelAddresses) {
this.sentinelAddresses = sentinelAddresses.split(",");
}
public String getMasterName() {
return masterName;
}
public void setMasterName(String masterName) {
this.masterName = masterName;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
public int getConnectionPoolSize() {
return connectionPoolSize;
}
public void setConnectionPoolSize(int connectionPoolSize) {
this.connectionPoolSize = connectionPoolSize;
}
public int getConnectionMinimumIdleSize() {
return connectionMinimumIdleSize;
}
public void setConnectionMinimumIdleSize(int connectionMinimumIdleSize) {
this.connectionMinimumIdleSize = connectionMinimumIdleSize;
}
}
//package com.geekq.miaosha.redis;
//
//import org.springframework.boot.context.properties.ConfigurationProperties;
//
//@ConfigurationProperties(prefix = "redisson")
//public class RedissonProperties {
//
// private int timeout = 3000;
//
// private String address;
//
// private String password;
//
// private int connectionPoolSize = 64;
//
// private int connectionMinimumIdleSize=10;
//
// private int slaveConnectionPoolSize = 250;
//
// private int masterConnectionPoolSize = 250;
//
// private String[] sentinelAddresses;
//
// private String masterName;
//
// public int getTimeout() {
// return timeout;
// }
//
// public void setTimeout(int timeout) {
// this.timeout = timeout;
// }
//
// public int getSlaveConnectionPoolSize() {
// return slaveConnectionPoolSize;
// }
//
// public void setSlaveConnectionPoolSize(int slaveConnectionPoolSize) {
// this.slaveConnectionPoolSize = slaveConnectionPoolSize;
// }
//
// public int getMasterConnectionPoolSize() {
// return masterConnectionPoolSize;
// }
//
// public void setMasterConnectionPoolSize(int masterConnectionPoolSize) {
// this.masterConnectionPoolSize = masterConnectionPoolSize;
// }
//
// public String[] getSentinelAddresses() {
// return sentinelAddresses;
// }
//
// public void setSentinelAddresses(String sentinelAddresses) {
// this.sentinelAddresses = sentinelAddresses.split(",");
// }
//
// public String getMasterName() {
// return masterName;
// }
//
// public void setMasterName(String masterName) {
// this.masterName = masterName;
// }
//
// public String getPassword() {
// return password;
// }
//
// public void setPassword(String password) {
// this.password = password;
// }
//
// public String getAddress() {
// return address;
// }
//
// public void setAddress(String address) {
// this.address = address;
// }
//
// public int getConnectionPoolSize() {
// return connectionPoolSize;
// }
//
// public void setConnectionPoolSize(int connectionPoolSize) {
// this.connectionPoolSize = connectionPoolSize;
// }
//
// public int getConnectionMinimumIdleSize() {
// return connectionMinimumIdleSize;
// }
//
// public void setConnectionMinimumIdleSize(int connectionMinimumIdleSize) {
// this.connectionMinimumIdleSize = connectionMinimumIdleSize;
// }
//}
//

View File

@ -1,146 +1,146 @@
package com.geekq.miaosha.redis;
import org.redisson.api.*;
import org.redisson.config.Config;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.io.IOException;
/**
* redisson操作类
*/
@Service("redissonService")
public class RedissonService {
@Autowired
private RedissonClient redissonClient;
public void getRedissonClient() throws IOException {
Config config = redissonClient.getConfig();
System.out.println(config.toJSON().toString());
}
/**`
* 获取字符串对象
*
* @param objectName
* @return
*/
public <T> RBucket<T> getRBucket(String objectName) {
RBucket<T> bucket = redissonClient.getBucket(objectName);
return bucket;
}
/**
* 获取Map对象
*
* @param objectName
* @return
*/
public <K, V> RMap<K, V> getRMap(String objectName) {
RMap<K, V> map = redissonClient.getMap(objectName);
return map;
}
/**
* 获取有序集合
*
* @param objectName
* @return
*/
public <V> RSortedSet<V> getRSortedSet(String objectName) {
RSortedSet<V> sortedSet = redissonClient.getSortedSet(objectName);
return sortedSet;
}
/**
* 获取集合
*
* @param objectName
* @return
*/
public <V> RSet<V> getRSet(String objectName) {
RSet<V> rSet = redissonClient.getSet(objectName);
return rSet;
}
/**
* 获取列表
*
* @param objectName
* @return
*/
public <V> RList<V> getRList(String objectName) {
RList<V> rList = redissonClient.getList(objectName);
return rList;
}
/**
* 获取队列
*
* @param objectName
* @return
*/
public <V> RQueue<V> getRQueue(String objectName) {
RQueue<V> rQueue = redissonClient.getQueue(objectName);
return rQueue;
}
/**
* 获取双端队列
*
* @param objectName
* @return
*/
public <V> RDeque<V> getRDeque(String objectName) {
RDeque<V> rDeque = redissonClient.getDeque(objectName);
return rDeque;
}
/**
* 获取锁
*
* @param objectName
* @return
*/
public RLock getRLock(String objectName) {
RLock rLock = redissonClient.getLock(objectName);
return rLock;
}
/**
* 获取读取锁
*
* @param objectName
* @return
*/
public RReadWriteLock getRWLock(String objectName) {
RReadWriteLock rwlock = redissonClient.getReadWriteLock(objectName);
return rwlock;
}
/**
* 获取原子数
*
* @param objectName
* @return
*/
public RAtomicLong getRAtomicLong(String objectName) {
RAtomicLong rAtomicLong = redissonClient.getAtomicLong(objectName);
return rAtomicLong;
}
/**
* 获取记数锁
*
* @param objectName
* @return
*/
public RCountDownLatch getRCountDownLatch(String objectName) {
RCountDownLatch rCountDownLatch = redissonClient.getCountDownLatch(objectName);
return rCountDownLatch;
}
}
//package com.geekq.miaosha.redis;
//
//import org.redisson.api.*;
//import org.redisson.config.Config;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.stereotype.Service;
//
//import java.io.IOException;
//
///**
// * redisson操作类
// */
//@Service("redissonService")
//public class RedissonService {
//
// @Autowired
// private RedissonClient redissonClient;
//
// public void getRedissonClient() throws IOException {
// Config config = redissonClient.getConfig();
// System.out.println(config.toJSON().toString());
// }
//
// /**`
// * 获取字符串对象
// *
// * @param objectName
// * @return
// */
// public <T> RBucket<T> getRBucket(String objectName) {
// RBucket<T> bucket = redissonClient.getBucket(objectName);
// return bucket;
// }
//
// /**
// * 获取Map对象
// *
// * @param objectName
// * @return
// */
// public <K, V> RMap<K, V> getRMap(String objectName) {
// RMap<K, V> map = redissonClient.getMap(objectName);
// return map;
// }
//
// /**
// * 获取有序集合
// *
// * @param objectName
// * @return
// */
// public <V> RSortedSet<V> getRSortedSet(String objectName) {
// RSortedSet<V> sortedSet = redissonClient.getSortedSet(objectName);
// return sortedSet;
// }
//
// /**
// * 获取集合
// *
// * @param objectName
// * @return
// */
// public <V> RSet<V> getRSet(String objectName) {
// RSet<V> rSet = redissonClient.getSet(objectName);
// return rSet;
// }
//
// /**
// * 获取列表
// *
// * @param objectName
// * @return
// */
// public <V> RList<V> getRList(String objectName) {
// RList<V> rList = redissonClient.getList(objectName);
// return rList;
// }
//
// /**
// * 获取队列
// *
// * @param objectName
// * @return
// */
// public <V> RQueue<V> getRQueue(String objectName) {
// RQueue<V> rQueue = redissonClient.getQueue(objectName);
// return rQueue;
// }
//
// /**
// * 获取双端队列
// *
// * @param objectName
// * @return
// */
// public <V> RDeque<V> getRDeque(String objectName) {
// RDeque<V> rDeque = redissonClient.getDeque(objectName);
// return rDeque;
// }
//
//
// /**
// * 获取锁
// *
// * @param objectName
// * @return
// */
// public RLock getRLock(String objectName) {
// RLock rLock = redissonClient.getLock(objectName);
// return rLock;
// }
//
// /**
// * 获取读取锁
// *
// * @param objectName
// * @return
// */
// public RReadWriteLock getRWLock(String objectName) {
// RReadWriteLock rwlock = redissonClient.getReadWriteLock(objectName);
// return rwlock;
// }
//
// /**
// * 获取原子数
// *
// * @param objectName
// * @return
// */
// public RAtomicLong getRAtomicLong(String objectName) {
// RAtomicLong rAtomicLong = redissonClient.getAtomicLong(objectName);
// return rAtomicLong;
// }
//
// /**
// * 获取记数锁
// *
// * @param objectName
// * @return
// */
// public RCountDownLatch getRCountDownLatch(String objectName) {
// RCountDownLatch rCountDownLatch = redissonClient.getCountDownLatch(objectName);
// return rCountDownLatch;
// }
//
//}

View File

@ -37,7 +37,7 @@ public class MiaoShaUserService {
}
MiaoshaUser user =redisService.get(MiaoShaUserKey.token,token,MiaoshaUser.class) ;
if(user!=null) {
addCookie(response, user);
addCookie(response, token, user);
}
return user ;
@ -105,17 +105,25 @@ public class MiaoShaUserService {
if(!calcPass.equals(dbPass)){
throw new GlobleException(CodeMsg.PASSWORD_ERROR);
}
//生成cookie
addCookie(response,user);
//生成cookie
String token= UUIDUtil.uuid();
addCookie(response, token, user);
return true ;
}
private void addCookie(HttpServletResponse response ,MiaoshaUser user){
String token = UUIDUtil.uuid();
redisService.set(MiaoShaUserKey.token,token,user) ;
Cookie cookie = new Cookie(COOKIE_NAME_TOKEN , token) ;
private void addCookie(HttpServletResponse response, String token, MiaoshaUser user) {
redisService.set(MiaoShaUserKey.token, token, user);
Cookie cookie = new Cookie(COOKIE_NAME_TOKEN, token);
cookie.setMaxAge(MiaoShaUserKey.token.expireSeconds());
cookie.setPath("/");
response.addCookie(cookie);
}
// private void addCookie(HttpServletResponse response ,MiaoshaUser user){
// String token = UUIDUtil.uuid();
// redisService.set(MiaoShaUserKey.token,token,user) ;
// Cookie cookie = new Cookie(COOKIE_NAME_TOKEN , token) ;
// cookie.setMaxAge(MiaoShaUserKey.token.expireSeconds());
// cookie.setPath("/");
// response.addCookie(cookie);
// }
}

View File

@ -1,114 +1,114 @@
package com.geekq.miaosha.timeTask;
import com.geekq.miaosha.dao.OrderDao;
import com.geekq.miaosha.redis.RedisService;
import com.geekq.miaosha.redis.RedissonService;
import com.geekq.miaosha.service.OrderService;
import jodd.util.PropertiesUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.redisson.api.RLock;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import java.util.concurrent.TimeUnit;
import static com.geekq.miaosha.common.Constanst.CLOSE_ORDER_INFO_TASK_LOCK;
@Component
@Slf4j
public class OrderCloseTask {
@Autowired
private OrderDao orderDao ;
@Autowired
private RedisService redisService;
@Autowired
private OrderService orderService;
@Autowired
private RedissonService redissonService;
// @Scheduled(cron = "0/1 * * * * ?")
private void closeOrderTaskv1(){
int hour = 2;
orderService.closeOrder(hour);
log.info("关闭订单定时任务结束");
}
// @Scheduled(cron = "0/1 * * * * ?")
// public void closeOrderTaskV2(){
// log.info("关闭订单定时任务启动");
// long lockTime = 5000;
// Long setnxResult = redisService.setnx(CLOSE_ORDER_INFO_TASK_LOCK,String.valueOf(System.currentTimeMillis()+lockTime));
// //代表获取了锁
// if(setnxResult !=null && setnxResult ==1){
// closeOrder(CLOSE_ORDER_INFO_TASK_LOCK);
// }else {
// log.info("没有获得分布式锁:{}",CLOSE_ORDER_INFO_TASK_LOCK);
// }
// log.info("关闭订单定时任务结束");
// }
// @Scheduled(cron = "0/1 * * * * ?")
// public void closeOrderTaskV3(){
// log.info("关闭订单定时任务启动");
// long lockTime = 5000;
// Long setnxResult = redisService.setnx(CLOSE_ORDER_INFO_TASK_LOCK,String.valueOf(System.currentTimeMillis()+lockTime));
// //代表获取了锁
// if(setnxResult !=null && setnxResult ==1){
// closeOrder(CLOSE_ORDER_INFO_TASK_LOCK);
// }else {
// log.info("没有获得分布式锁:{}",CLOSE_ORDER_INFO_TASK_LOCK);
// String lockValueStr = redisService.get(CLOSE_ORDER_INFO_TASK_LOCK);
// if(lockValueStr!=null&&System.currentTimeMillis() > Long.parseLong(lockValueStr)){
// //把之前的释放在新加入锁
// String getSetResult = redisService.getset(CLOSE_ORDER_INFO_TASK_LOCK,String.valueOf(System.currentTimeMillis()+lockTime));
//package com.geekq.miaosha.timeTask;
//
// if(getSetResult == null || (getSetResult != null && StringUtils.equals(lockValueStr,getSetResult))){
// closeOrder(CLOSE_ORDER_INFO_TASK_LOCK);
// }else {
// log.info("没有获取到分布式锁:{}",CLOSE_ORDER_INFO_TASK_LOCK);
// }
// }else {
// log.info("没有获取到分布式锁:{}",CLOSE_ORDER_INFO_TASK_LOCK);
// }
// }
//import com.geekq.miaosha.dao.OrderDao;
//import com.geekq.miaosha.redis.RedisService;
//import com.geekq.miaosha.redis.RedissonService;
//import com.geekq.miaosha.service.OrderService;
//import jodd.util.PropertiesUtil;
//import lombok.extern.slf4j.Slf4j;
//import org.apache.commons.lang3.StringUtils;
//import org.redisson.api.RLock;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.scheduling.annotation.Scheduled;
//import org.springframework.stereotype.Component;
//
//import java.util.concurrent.TimeUnit;
//
//import static com.geekq.miaosha.common.Constanst.CLOSE_ORDER_INFO_TASK_LOCK;
//
//@Component
//@Slf4j
//public class OrderCloseTask {
//
// @Autowired
// private OrderDao orderDao ;
// @Autowired
// private RedisService redisService;
//
// @Autowired
// private OrderService orderService;
// @Autowired
// private RedissonService redissonService;
//
//
//// @Scheduled(cron = "0/1 * * * * ?")
// private void closeOrderTaskv1(){
// int hour = 2;
// orderService.closeOrder(hour);
// log.info("关闭订单定时任务结束");
// }
@Scheduled(cron="0 */1 * * * ?")
public void closeOrderTaskV4(){
RLock lock = redissonService.getRLock(CLOSE_ORDER_INFO_TASK_LOCK);
boolean getLock = false;
try {
if(getLock = lock.tryLock(0,50, TimeUnit.SECONDS)){
log.info("Redisson获取到分布式锁:{},ThreadName:{}",CLOSE_ORDER_INFO_TASK_LOCK,Thread.currentThread().getName());
int hour = 2;
// iOrderService.closeOrder(hour);
}else{
log.info("Redisson没有获取到分布式锁:{},ThreadName:{}",CLOSE_ORDER_INFO_TASK_LOCK,Thread.currentThread().getName());
}
} catch (InterruptedException e) {
log.error("Redisson分布式锁获取异常",e);
} finally {
if(!getLock){
return;
}
lock.unlock();
log.info("Redisson分布式锁释放锁");
}
}
private void closeOrder(String lockName){
redisService.expire(lockName,5);
log.info("获取{},当前线程名称!" ,lockName,Thread.currentThread().getName());
int hour = 2;
orderService.closeOrder(hour);
redisService.del(CLOSE_ORDER_INFO_TASK_LOCK);
log.info("===============================");
}
}
//// @Scheduled(cron = "0/1 * * * * ?")
//// public void closeOrderTaskV2(){
//// log.info("关闭订单定时任务启动");
//// long lockTime = 5000;
//// Long setnxResult = redisService.setnx(CLOSE_ORDER_INFO_TASK_LOCK,String.valueOf(System.currentTimeMillis()+lockTime));
//// //代表获取了锁
//// if(setnxResult !=null && setnxResult ==1){
//// closeOrder(CLOSE_ORDER_INFO_TASK_LOCK);
//// }else {
//// log.info("没有获得分布式锁:{}",CLOSE_ORDER_INFO_TASK_LOCK);
//// }
//// log.info("关闭订单定时任务结束");
//// }
//
//// @Scheduled(cron = "0/1 * * * * ?")
//// public void closeOrderTaskV3(){
//// log.info("关闭订单定时任务启动");
//// long lockTime = 5000;
//// Long setnxResult = redisService.setnx(CLOSE_ORDER_INFO_TASK_LOCK,String.valueOf(System.currentTimeMillis()+lockTime));
//// //代表获取了锁
//// if(setnxResult !=null && setnxResult ==1){
//// closeOrder(CLOSE_ORDER_INFO_TASK_LOCK);
//// }else {
//// log.info("没有获得分布式锁:{}",CLOSE_ORDER_INFO_TASK_LOCK);
//// String lockValueStr = redisService.get(CLOSE_ORDER_INFO_TASK_LOCK);
//// if(lockValueStr!=null&&System.currentTimeMillis() > Long.parseLong(lockValueStr)){
//// //把之前的释放在新加入锁
//// String getSetResult = redisService.getset(CLOSE_ORDER_INFO_TASK_LOCK,String.valueOf(System.currentTimeMillis()+lockTime));
////
//// if(getSetResult == null || (getSetResult != null && StringUtils.equals(lockValueStr,getSetResult))){
//// closeOrder(CLOSE_ORDER_INFO_TASK_LOCK);
//// }else {
//// log.info("没有获取到分布式锁:{}",CLOSE_ORDER_INFO_TASK_LOCK);
//// }
//// }else {
//// log.info("没有获取到分布式锁:{}",CLOSE_ORDER_INFO_TASK_LOCK);
//// }
//// }
//// log.info("关闭订单定时任务结束");
//// }
//// @Scheduled(cron="0 */1 * * * ?")
//// public void closeOrderTaskV4(){
//// RLock lock = redissonService.getRLock(CLOSE_ORDER_INFO_TASK_LOCK);
//// boolean getLock = false;
//// try {
//// if(getLock = lock.tryLock(0,50, TimeUnit.SECONDS)){
//// log.info("Redisson获取到分布式锁:{},ThreadName:{}",CLOSE_ORDER_INFO_TASK_LOCK,Thread.currentThread().getName());
//// int hour = 2;
////// iOrderService.closeOrder(hour);
//// }else{
//// log.info("Redisson没有获取到分布式锁:{},ThreadName:{}",CLOSE_ORDER_INFO_TASK_LOCK,Thread.currentThread().getName());
//// }
//// } catch (InterruptedException e) {
//// log.error("Redisson分布式锁获取异常",e);
//// } finally {
//// if(!getLock){
//// return;
//// }
//// lock.unlock();
//// log.info("Redisson分布式锁释放锁");
//// }
//// }
//
//
//
// private void closeOrder(String lockName){
// redisService.expire(lockName,5);
// log.info("获取{},当前线程名称!" ,lockName,Thread.currentThread().getName());
// int hour = 2;
// orderService.closeOrder(hour);
// redisService.del(CLOSE_ORDER_INFO_TASK_LOCK);
// log.info("===============================");
//
// }
//}

View File

@ -16,9 +16,9 @@ mybatis.mapperLocations=classpath:mybatis/mapper/*.xml
#add mybatis
mybatis.config-locations=classpath:mybatis/config.xml
#datasource
spring.datasource.url=jdbc:mysql://localhost:3306/miaosha?useUnicode=true&characterEncoding=utf-8&allowMultiQueries=true&useSSL=false
spring.datasource.url=jdbc:mysql://39.107.245.253:3306/miaosha?useUnicode=true&characterEncoding=utf-8&allowMultiQueries=true&useSSL=false
spring.datasource.username=root
spring.datasource.password=aixiyue11
spring.datasource.password=root
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
#druid
spring.datasource.type=com.alibaba.druid.pool.DruidDataSource
@ -44,7 +44,7 @@ spring.resources.chain.gzipped=true
spring.resources.chain.html-application-cache=true
spring.resources.static-locations=classpath:/static/
#redis
redis.host=192.168.1.116
redis.host=39.107.245.253
redis.port=6379
redis.timeout=100
redis.password=123456
@ -54,10 +54,10 @@ redis.poolMaxWait=500
#server.port=8003
#rabbitmq
spring.rabbitmq.host=localhost
spring.rabbitmq.host=39.107.245.253
spring.rabbitmq.port=5672
spring.rabbitmq.username=guest
spring.rabbitmq.password=guest
spring.rabbitmq.username=mqadmin
spring.rabbitmq.password=mqadmin
spring.rabbitmq.virtual-host=/
spring.rabbitmq.listener.simple.concurrency= 10
spring.rabbitmq.listener.simple.max-concurrency= 10
@ -71,4 +71,4 @@ spring.rabbitmq.template.retry.max-interval=10000
spring.rabbitmq.template.retry.multiplier=1.0
## maven隔离
spring.profiles.active=dev
#spring.profiles.active=dev

View File

@ -16,9 +16,9 @@ mybatis.mapperLocations=classpath:mybatis/mapper/*.xml
#add mybatis
mybatis.config-locations=classpath:mybatis/config.xml
#datasource
spring.datasource.url=jdbc:mysql://localhost:3306/miaosha?useUnicode=true&characterEncoding=utf-8&allowMultiQueries=true&useSSL=false
spring.datasource.url=jdbc:mysql://39.107.245.253:3306/miaosha?useUnicode=true&characterEncoding=utf-8&allowMultiQueries=true&useSSL=false
spring.datasource.username=root
spring.datasource.password=aixiyue11
spring.datasource.password=root
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
#druid
spring.datasource.type=com.alibaba.druid.pool.DruidDataSource
@ -44,7 +44,7 @@ spring.resources.chain.gzipped=true
spring.resources.chain.html-application-cache=true
spring.resources.static-locations=classpath:/static/
#redis
redis.host=192.168.1.116
redis.host=39.107.245.253
redis.port=6379
redis.timeout=100
redis.password=123456
@ -54,10 +54,10 @@ redis.poolMaxWait=500
#server.port=8003
#rabbitmq
spring.rabbitmq.host=localhost
spring.rabbitmq.host=39.107.245.253
spring.rabbitmq.port=5672
spring.rabbitmq.username=guest
spring.rabbitmq.password=guest
spring.rabbitmq.username=mqadmin
spring.rabbitmq.password=mqadmin
spring.rabbitmq.virtual-host=/
spring.rabbitmq.listener.simple.concurrency= 10
spring.rabbitmq.listener.simple.max-concurrency= 10
@ -71,4 +71,4 @@ spring.rabbitmq.template.retry.max-interval=10000
spring.rabbitmq.template.retry.multiplier=1.0
## maven隔离
spring.profiles.active=dev
#spring.profiles.active=dev