codingxiaxw / seckill Goto Github PK
View Code? Open in Web Editor NEWthe source code of `seckill` with development documentation :zap:
Home Page: http://codingxiaxw.cn
the source code of `seckill` with development documentation :zap:
Home Page: http://codingxiaxw.cn
希望大家在利用这两个项目做练习项目时,带着这两个问题进行思考,知道解决方案的人可以在底下留下自己的思路。
@codingXiaxw 导入之后再哪个文件里运行啊!
输入 http://localhost:8080/seckill/list 后,404
为什么seckill是null呢?
我用了阿里的链接池。应该没关系吧。
System.out.println(seckill.getName());
问题1:
java.sql.SQLException: The server time zone value '???ú±ê×??±??' is unrecognized or represents more than one time zone. You must configure either the server or JDBC driver (via the serverTimezone configuration property) to use a more specifc time zone value if you want to utilize time zone support.
解决办法:
修改数据库连接url,增加serverTimezone=UTC
jdbc.url=jdbc:mysql://localhost:3306/seckill?useUnicode=true&characterEncoding=utf-8&serverTimezone=UTC
解决方法:
修改数据库连接url,增加useSSL=true
jdbc.url=jdbc:mysql://localhost:3306/seckill?useUnicode=true&characterEncoding=utf-8&serverTimezone=UTC&useSSL=true
问题3:
23:00:20.370 [http-nio-8080-exec-4] DEBUG org.springframework.web.servlet.DispatcherServlet - Could not complete request
org.springframework.web.util.NestedServletException: Handler dispatch failed; nested exception is java.lang.AbstractMethodError: Method com/mchange/v2/c3p0/impl/NewProxyPreparedStatement.isClosed()Z is abstract
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1006)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:925)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:974)
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:866)
修改依赖。
原来为:
c3p0
c3p0
0.9.1.2
修改后为:
com.mchange
c3p0
0.9.5.2
25-Dec-2018 20:24:12.020 信息 [RMI TCP Connection(2)-127.0.0.1] org.apache.catalina.core.ApplicationContext.log No Spring WebApplicationInitializer types detected on classpath
25-Dec-2018 20:24:24.242 信息 [http-nio-8080-exec-5] org.apache.catalina.core.ApplicationContext.log Initializing Spring FrameworkServlet 'seckill-dispatcher'
25-Dec-2018 20:24:33.336 严重 [http-nio-8080-exec-6] org.apache.catalina.core.StandardWrapperValve.invoke Servlet.service() for servlet [seckill-dispatcher] in context with path [] threw exception [Request processing failed; nested exception is redis.clients.jedis.exceptions.JedisConnectionException: Could not get a resource from the pool] with root cause
java.net.ConnectException: Connection refused: connect
at java.net.DualStackPlainSocketImpl.waitForConnect(Native Method)
at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:85)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
at java.net.Socket.connect(Socket.java:589)
at redis.clients.jedis.Connection.connect(Connection.java:158)
at redis.clients.jedis.BinaryClient.connect(BinaryClient.java:82)
at redis.clients.jedis.BinaryJedis.connect(BinaryJedis.java:1641)
at redis.clients.jedis.JedisFactory.makeObject(JedisFactory.java:85)
at org.apache.commons.pool2.impl.GenericObjectPool.create(GenericObjectPool.java:861)
at org.apache.commons.pool2.impl.GenericObjectPool.borrowObject(GenericObjectPool.java:435)
at org.apache.commons.pool2.impl.GenericObjectPool.borrowObject(GenericObjectPool.java:363)
at redis.clients.util.Pool.getResource(Pool.java:48)
at redis.clients.jedis.JedisPool.getResource(JedisPool.java:99)
at cn.codingxiaxw.dao.cache.RedisDao.getOrPutSeckill(RedisDao.java:80)
at cn.codingxiaxw.service.impl.SeckillServiceImpl.getById(SeckillServiceImpl.java:55)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:317)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:201)
at com.sun.proxy.$Proxy19.getById(Unknown Source)
at cn.codingxiaxw.web.SeckillController.detail(SeckillController.java:48)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:221)
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:137)
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:110)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:776)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:705)
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:959)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:893)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:967)
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:858)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:635)
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:843)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:742)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:198)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:493)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:81)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:650)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:342)
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:800)
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:806)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1498)
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:748)
小伙伴们学完这个项目,目前对redis解决高并发是怎么想的?
getOrPutSeckill()方法中的
boolean getLock = JedisUtils.tryGetDistributedLock(jedis, lockKey, lockRequestId, 1000);
获取分布式锁的意义是什么?
一直存在一个疑问,在商城系统秒杀功能中。
1、假设库存只剩下1件了,A用户成功抢到并成功下单,但是A用户并没有支付
2、假设下单成功后15分钟内未支付,库存会回滚
3、A用户下单后,过了14分钟,发现订单未支付,于是发起微信支付,跳转到微信支付页面
4、进入支付页面后,输入支付密码,发现密码错误, A用户网络条件也不是很好,耽误了2分钟。最终输入正确的密码支付成功了。
5、而此时A的订单明显已经超时了,系统会把库存回滚。
6、回滚后,B用户看见有库存,马上下单,导致商品超卖
不知道我有没有描述清楚。这个问题一直困扰着我。
有想过在用户发起支付前给订单做个标识,让其晚点回滚,但是如果用户在支付页面耽误很久,也无济于事。
首先想诚心说声抱歉,因为觉得你的readme写的很棒,所以懒得写readme copy了一份,但是未征求你的同意对此我真诚的道歉。但是我的src源码并非copy你的,而且添加了一些aop日志,存储过程,redis,test目录也没有按照imooc的写法,最后还是想说十分抱歉,抱歉,抱歉,我会移除copy你的部分
群号: 659957958,赶快上车!
请问,按照您的ssm项目配置,为什么所有bean都不是默认启动的时候初始化呢,而是在第一次发请求的时候所有bean才初始化.在您的配置文件中,并没有发现什么延迟初始化相关的配置。但是spring项目本身默认是启动的时候就初始化所有bean,实在没找到原因,请老师指点。 @codingXiaxw
/*Protostuff 序列化泛型类*/
Page<User> pageUser = new Page<User>();
private RuntimeSchema<Item> schema = RuntimeSchema.createFrom(pageUser .class);//这里就不行了
byte[] array=ProtostuffIOUtil.toByteArray(item,schema,
LinkedBuffer.allocate(LinkedBuffer.DEFAULT_BUFFER_SIZE));
/*Protostuff 无法序列化泛型类*/
System.out.println("序列化数据为"+array);
/*异常信息*/
Exception in thread "main" java.lang.RuntimeException: Reading from a byte array threw an IOException (should never happen).
at com.dyuproject.protostuff.IOUtil.mergeFrom(IOUtil.java:52)
at com.dyuproject.protostuff.ProtobufIOUtil.mergeFrom(ProtobufIOUtil.java:95)
at com.cityline.shoe.common.utils.SerializationUtils.main(SerializationUtils.java:44)
Caused by: com.dyuproject.protostuff.ProtostuffException: Corrupt input.
at com.dyuproject.protostuff.runtime.ObjectSchema.readObjectFrom(ObjectSchema.java:641)
at com.dyuproject.protostuff.runtime.ObjectSchema.mergeFrom(ObjectSchema.java:312)
at com.dyuproject.protostuff.ByteArrayInput.mergeObject(ByteArrayInput.java:375)
at com.dyuproject.protostuff.runtime.RuntimeRepeatedFieldFactory$5.mergeFrom(RuntimeRepeatedFieldFactory.java:385)
at com.dyuproject.protostuff.runtime.MappedSchema.mergeFrom(MappedSchema.java:196)
at com.dyuproject.protostuff.IOUtil.mergeFrom(IOUtil.java:43)
... 2 more
非常期待这个项目的第四篇文章,作者还更新么?
CREATE TABLE seckill(
seckill_id
BIGINT NOT NUll AUTO_INCREMENT COMMENT '商品库存ID',
name
VARCHAR(120) NOT NULL COMMENT '商品名称',
number
int NOT NULL COMMENT '库存数量',
create_time
TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
start_time
TIMESTAMP NOT NULL COMMENT '秒杀开始时间',
end_time
TIMESTAMP NOT NULL COMMENT '秒杀结束时间',
PRIMARY KEY (seckill_id),
key idx_start_time(start_time),
key idx_end_time(end_time),
key idx_create_time(create_time)
)ENGINE=INNODB AUTO_INCREMENT=1000 DEFAULT CHARSET=utf8 COMMENT='秒杀库存表';
--把 create_time TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP 这条语句放在start_time 前面,
--原因是mysql会默认为表中的第一个timestamp字段(且设置了NOT NULL)隐式设置DEFAULAT CURRENT_TIMESTAMP。
-- 所以默认的顺序设置实际上等同于设置了两个CURRENT_TIMESTAMP,因此而报错,调整之后就可以了。
哥们能不能加个评论系统 或者有没有 QQ群之类的交流方式?
视频和代码里对于注解映射器和适配器的说好好像有误。
在spring3.1之前使用org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping注解映射器。
在spring3.1之后使用org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping注解映射器。
在spring3.1之前使用org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter注解适配器。
在spring3.1之后使用org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter注解适配器。
视频录制的时候应该指的是spring 3.1之后了
你好,初学Spring,在IDEA生成war后部署到了Tomcat上,localhost:8080/seckill显示Hello World但/seckill/list 404是为什么呢?
下面是log:
29-Nov-2017 19:50:08.875 INFO [http-nio-8080-exec-15] org.apache.catalina.core.StandardContext.reload Reloading Context with name [/seckill] has started
29-Nov-2017 19:50:08.877 INFO [http-nio-8080-exec-15] org.springframework.web.context.support.XmlWebApplicationContext.doClose Closing WebApplicationContext for namespace 'seckill-dispatcher-servlet': startup date [Wed Nov 29 18:12:49 EST 2017]; root of context hierarchy
29-Nov-2017 19:50:10.090 INFO [http-nio-8080-exec-15] org.apache.catalina.core.StandardContext.reload Reloading Context with name [/seckill] is completed
29-Nov-2017 19:50:27.670 INFO [http-nio-8080-exec-19] org.springframework.web.servlet.DispatcherServlet.initServletBean FrameworkServlet 'seckill-dispatcher': initialization started
29-Nov-2017 19:50:27.685 INFO [http-nio-8080-exec-19] org.springframework.web.context.support.XmlWebApplicationContext.prepareRefresh Refreshing WebApplicationContext for namespace 'seckill-dispatcher-servlet': startup date [Wed Nov 29 19:50:27 EST 2017]; root of context hierarchy
29-Nov-2017 19:50:27.720 INFO [http-nio-8080-exec-19] org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions Loading XML bean definitions from file [/usr/local/Cellar/tomcat/8.5.23/libexec/webapps/seckill/WEB-INF/classes/spring/spring-service.xml]
29-Nov-2017 19:50:27.824 INFO [http-nio-8080-exec-19] org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions Loading XML bean definitions from file [/usr/local/Cellar/tomcat/8.5.23/libexec/webapps/seckill/WEB-INF/classes/spring/spring-web.xml]
29-Nov-2017 19:50:27.885 INFO [http-nio-8080-exec-19] org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions Loading XML bean definitions from file [/usr/local/Cellar/tomcat/8.5.23/libexec/webapps/seckill/WEB-INF/classes/spring/spring-dao.xml]
29-Nov-2017 19:50:28.016 INFO [http-nio-8080-exec-19] org.springframework.context.support.PropertySourcesPlaceholderConfigurer.loadProperties Loading properties file from class path resource [jdbc.properties]
19:50:28.155 [http-nio-8080-exec-19] DEBUG org.apache.ibatis.logging.LogFactory - Logging initialized using 'class org.apache.ibatis.logging.slf4j.Slf4jImpl' adapter.
29-Nov-2017 19:50:28.185 INFO [http-nio-8080-exec-19] com.mchange.v2.log.MLog.<clinit> MLog clients using java 1.4+ standard logging.
29-Nov-2017 19:50:28.216 INFO [http-nio-8080-exec-19] com.mchange.v2.c3p0.C3P0Registry.banner Initializing c3p0-0.9.1.1 [built 15-March-2007 01:32:31; debug? true; trace: 10]
29-Nov-2017 19:50:28.217 WARNING [http-nio-8080-exec-19] com.mchange.v2.c3p0.management.ActiveManagementCoordinator.attemptManageC3P0Registry A C3P0Registry mbean is already registered. This probably means that an application using c3p0 was undeployed, but not all PooledDataSources were closed prior to undeployment. This may lead to resource leaks over time. Please take care to close all PooledDataSources.
19:50:28.349 [http-nio-8080-exec-19] DEBUG org.apache.ibatis.io.ResolverUtil - Class not found: org.jboss.vfs.VFS
19:50:28.349 [http-nio-8080-exec-19] DEBUG org.apache.ibatis.io.ResolverUtil - JBoss 6 VFS API is not available in this environment.
19:50:28.350 [http-nio-8080-exec-19] DEBUG org.apache.ibatis.io.ResolverUtil - Class not found: org.jboss.vfs.VirtualFile
19:50:28.351 [http-nio-8080-exec-19] DEBUG org.apache.ibatis.io.ResolverUtil - VFS implementation org.apache.ibatis.io.JBoss6VFS is not valid in this environment.
19:50:28.351 [http-nio-8080-exec-19] DEBUG org.apache.ibatis.io.ResolverUtil - Using VFS adapter org.apache.ibatis.io.DefaultVFS
19:50:28.352 [http-nio-8080-exec-19] DEBUG org.apache.ibatis.io.ResolverUtil - Find JAR URL: file:/usr/local/Cellar/tomcat/8.5.23/libexec/webapps/seckill/WEB-INF/classes/cn/codingxiaxw/entity/
19:50:28.352 [http-nio-8080-exec-19] DEBUG org.apache.ibatis.io.ResolverUtil - Not a JAR: file:/usr/local/Cellar/tomcat/8.5.23/libexec/webapps/seckill/WEB-INF/classes/cn/codingxiaxw/entity/
19:50:28.352 [http-nio-8080-exec-19] DEBUG org.apache.ibatis.io.ResolverUtil - Reader entry: Seckill.class
19:50:28.353 [http-nio-8080-exec-19] DEBUG org.apache.ibatis.io.ResolverUtil - Reader entry: SuccessKilled.class
19:50:28.353 [http-nio-8080-exec-19] DEBUG org.apache.ibatis.io.ResolverUtil - Listing file:/usr/local/Cellar/tomcat/8.5.23/libexec/webapps/seckill/WEB-INF/classes/cn/codingxiaxw/entity/
19:50:28.353 [http-nio-8080-exec-19] DEBUG org.apache.ibatis.io.ResolverUtil - Find JAR URL: file:/usr/local/Cellar/tomcat/8.5.23/libexec/webapps/seckill/WEB-INF/classes/cn/codingxiaxw/entity/Seckill.class
19:50:28.353 [http-nio-8080-exec-19] DEBUG org.apache.ibatis.io.ResolverUtil - Not a JAR: file:/usr/local/Cellar/tomcat/8.5.23/libexec/webapps/seckill/WEB-INF/classes/cn/codingxiaxw/entity/Seckill.class
19:50:28.354 [http-nio-8080-exec-19] DEBUG org.apache.ibatis.io.ResolverUtil - Reader entry: ����1\
19:50:28.354 [http-nio-8080-exec-19] DEBUG org.apache.ibatis.io.ResolverUtil - Find JAR URL: file:/usr/local/Cellar/tomcat/8.5.23/libexec/webapps/seckill/WEB-INF/classes/cn/codingxiaxw/entity/SuccessKilled.class
19:50:28.354 [http-nio-8080-exec-19] DEBUG org.apache.ibatis.io.ResolverUtil - Not a JAR: file:/usr/local/Cellar/tomcat/8.5.23/libexec/webapps/seckill/WEB-INF/classes/cn/codingxiaxw/entity/SuccessKilled.class
19:50:28.354 [http-nio-8080-exec-19] DEBUG org.apache.ibatis.io.ResolverUtil - Reader entry: ����1T
19:50:28.355 [http-nio-8080-exec-19] DEBUG org.apache.ibatis.io.ResolverUtil - Checking to see if class cn.codingxiaxw.entity.Seckill matches criteria [is assignable to Object]
19:50:28.355 [http-nio-8080-exec-19] DEBUG org.apache.ibatis.io.ResolverUtil - Checking to see if class cn.codingxiaxw.entity.SuccessKilled matches criteria [is assignable to Object]
19:50:28.355 [http-nio-8080-exec-19] DEBUG o.m.spring.SqlSessionFactoryBean - Scanned package: 'cn.codingxiaxw.entity' for aliases
19:50:28.377 [http-nio-8080-exec-19] DEBUG o.m.spring.SqlSessionFactoryBean - Parsed configuration file: 'class path resource [mybatis-config.xml]'
19:50:28.444 [http-nio-8080-exec-19] DEBUG o.m.spring.SqlSessionFactoryBean - Parsed mapper file: 'file [/usr/local/Cellar/tomcat/8.5.23/libexec/webapps/seckill/WEB-INF/classes/mapper/SuccessKilledDao.xml]'
19:50:28.451 [http-nio-8080-exec-19] DEBUG o.m.spring.SqlSessionFactoryBean - Parsed mapper file: 'file [/usr/local/Cellar/tomcat/8.5.23/libexec/webapps/seckill/WEB-INF/classes/mapper/SeckillDao.xml]'
29-Nov-2017 19:50:28.759 INFO [http-nio-8080-exec-19] org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping.registerHandlerMethod Mapped "{[/seckill/{seckillId}/{md5}/execution],methods=[POST],produces=[application/json;charset=UTF-8]}" onto public cn.codingxiaxw.dto.SeckillResult<cn.codingxiaxw.dto.SeckillExecution> cn.codingxiaxw.web.SeckillController.execute(java.lang.Long,java.lang.String,java.lang.Long)
29-Nov-2017 19:50:28.760 INFO [http-nio-8080-exec-19] org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping.registerHandlerMethod Mapped "{[/seckill/list],methods=[GET]}" onto public java.lang.String cn.codingxiaxw.web.SeckillController.list(org.springframework.ui.Model)
29-Nov-2017 19:50:28.760 INFO [http-nio-8080-exec-19] org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping.registerHandlerMethod Mapped "{[/seckill/{seckillId}/exposer],methods=[GET],produces=[application/json;charset=UTF-8]}" onto public cn.codingxiaxw.dto.SeckillResult<cn.codingxiaxw.dto.Exposer> cn.codingxiaxw.web.SeckillController.exposer(java.lang.Long)
29-Nov-2017 19:50:28.760 INFO [http-nio-8080-exec-19] org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping.registerHandlerMethod Mapped "{[/seckill/time/now],methods=[GET]}" onto public cn.codingxiaxw.dto.SeckillResult<java.lang.Long> cn.codingxiaxw.web.SeckillController.time()
29-Nov-2017 19:50:28.760 INFO [http-nio-8080-exec-19] org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping.registerHandlerMethod Mapped "{[/seckill/{seckillId}/detail],methods=[GET]}" onto public java.lang.String cn.codingxiaxw.web.SeckillController.detail(java.lang.Long,org.springframework.ui.Model)
29-Nov-2017 19:50:28.957 INFO [http-nio-8080-exec-19] org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.initControllerAdviceCache Looking for @ControllerAdvice: WebApplicationContext for namespace 'seckill-dispatcher-servlet': startup date [Wed Nov 29 19:50:27 EST 2017]; root of context hierarchy
29-Nov-2017 19:50:28.991 INFO [http-nio-8080-exec-19] org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.initControllerAdviceCache Looking for @ControllerAdvice: WebApplicationContext for namespace 'seckill-dispatcher-servlet': startup date [Wed Nov 29 19:50:27 EST 2017]; root of context hierarchy
29-Nov-2017 19:50:29.019 INFO [http-nio-8080-exec-19] org.springframework.web.servlet.handler.SimpleUrlHandlerMapping.registerHandler Mapped URL path [/**] onto handler 'org.springframework.web.servlet.resource.DefaultServletHttpRequestHandler#0'
29-Nov-2017 19:50:29.050 INFO [http-nio-8080-exec-19] org.springframework.web.servlet.DispatcherServlet.initServletBean FrameworkServlet 'seckill-dispatcher': initialization completed in 1380 ms
严重 [RMI TCP Connection(3)-127.0.0.1] org.apache.catalina.core.ContainerBase.addChildInternal ContainerBase.addChild: start:
org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[]]
出现了上面这个异常而且google了说是web.xml的问题?然而并没有问题啊web.xml
redis查不到的话直接查数据库,并发一来全部请求都会怼到数据库。
还有,SeckillServiceImpl.getById不加个缓存?
如题,前台写入cookie key为“userPhone”,但是在controller execute接口当中传入的却是“killPhone”,导致获取秒杀地址后点击按钮页面假死
还是controller的问题,exposer接口未绑定参数,导致页面返回错误不显示按钮
可以使用testng进行并发测试,发现错误
@Test(threadPoolSize = 5001, invocationCount = 5002, timeOut = 1000000)
public void testExecute() {
RestTemplate template = new RestTemplate();
HttpHeaders headers = new HttpHeaders();
List<String> cookies = new ArrayList<>();
cookies.add("userPhone=" + "1737467" + Phone++);
headers.put(HttpHeaders.COOKIE, cookies);
HttpEntity request = new HttpEntity(null, headers);
long start = System.currentTimeMillis();
String s = template.postForObject("http://localhost:8080/seckill/1000/bf204e2683e7452aa7db1a50b5713bae/execution", request, String.class);
long end = System.currentTimeMillis();
log.info("{}|{}ms ,res|{}",Thread.currentThread().getId(),(end - start),s);
}
org.springframework.transaction.CannotCreateTransactionException: Could not open JDBC Connection for transaction; nested exception is java.sql.SQLException: An attempt by a client to checkout a Connection has timed out.
存储过程seckill.sql有点问题,导致重复秒杀时仍然秒杀成功,改成下面就ok了。
`DELIMITER $$ -- console中 ; 转换为 $$
CREATE PROCEDURE seckill
.execute_seckill
(IN v_seckill_id BIGINT, IN v_phone BIGINT,
IN v_kill_time TIMESTAMP, OUT r_result int)
BEGIN
DECLARE insert_count INT DEFAULT 0;
START TRANSACTION ;
INSERT IGNORE INTO success_killed
(seckill_id, user_phone,create_time)
VALUES (v_seckill_id, v_phone,v_kill_time);
SELECT row_count() INTO insert_count;
IF (insert_count = 0) THEN
ROLLBACK ;
SET r_result = -1;
ELSEIF (insert_count < 0) THEN
ROLLBACK ;
SET r_result = -2;
ELSE
UPDATE seckill
SET number = number -1
WHERE seckill_id = v_seckill_id
AND end_time > v_kill_time
AND start_time < v_kill_time
AND number > 0;
SELECT row_count() into insert_count;
IF (insert_count = 0) THEN
ROLLBACK;
SET r_result = 0;
ELSEIF (insert_count < 0) THEN
ROLLBACK;
SET r_result = -2;
ELSE
COMMIT;
SET r_result = 1;
END IF;
END IF;
END;
$$`
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.