• 1 未解决
    0
    swoole2010期 第二次课课堂笔记2 redis list 应用案例

    //链接Redis

    $redis = new Redis();

    $redis->connect("127.0.0.1", 6379);

     //基础操作

    if (0) {

    //进入队列 从右边进入

    $redis->rpush("books", "php", "java", "python");

    //进入队列 从左边进入

    // $redis->lpush("books", "php", "java", "python");

    //获取长度

    // $redis->llen("books");

    //左边出

    // $redis->lpop("books");

    //右边出

    // $redis->rpop("books");

    //指定10秒内返回,假如10秒没有可返回的数据,就返回nil

    $redis->blpop("books", 10);

    //在某一个元素前/后添加一个元素

    $redis->linsert("books", "before", "java", "c++");

    //通过索引获取一个元素

    dd($redis->lindex("books", 2), 'lindex');

    //通过索引获取list区间内多个元素

    dd($redis->lrange("books", 0, -1), 'lrange');

    //保留下标索引 1-3 的元素,其他去掉

    dd($redis->ltrim("books", 1, 3), 'ltrim');

    dd($redis->lrange("books", 0, 2), 'lrange');

    }

    /*

     *  消息队列

     *  //进入队列 从右边进入 右边出

     * */

    if(1){

        //专门接收数据存入list 中

       $redis->rpush("books", "php", "java", "python");


        //专门获取数据处理

    //    $text = $redis->blpop("books", 10);

        $text = $redis->lpop("books" );

        $len = $redis->lLen("books");

        dd($len,'length');

        if($text){

            dd($text,"to do some thing");

        }

        //to do some thing

    }

    /*

     * list 应用场景

     * page 分页查询

     * */

    if(0){

        //根据一定的排序获取主键ID

        //存入list中  1,2,3,4,5,6,7,8,9

        $ids_arr = [1, 2, 3, 4, 5, 6, 7, 8, 9];

        foreach ($ids_arr as $id){

            $redis->rpush("article_page_ids", $id);

        }

        //每页三个

        $size = 3;

        //第一页: 0,2

        //第二页: 3,5

        //第三页: 6,8

        //分页计算排序 ($page-1) * size ,($page) * size -1

        $ids = [];

        $len = $redis->lLen("article_page_ids");

        dd($len,'length');

        for ( $page = 1;$page<= ceil($len/$size);$page++ ){

            //返回分页数据的ID集合

            $ids = $redis->lrange("article_page_ids", ($page-1) * $size ,($page) * $size -1);

            // 根据主键查询数据 自定义字符串/数字来实现排序

            $sql[$page] = "select * from aritcle where id in(".implode(',',$ids).") order by field(id,".implode(',',$ids).")";

        }

        dd($sql,'sql');

    }


  • 1 未解决
    0
    swoole2010期 第二次课课堂笔记1 redis string 应用案例

    //链接Redis

    $redis = new Redis();

    $redis->connect("127.0.0.1", 6379);

    //基础操作

    if(0){   

         //清空库

        $redis->flushAll(); // 删除所有数据库

        $redis->flushDB(); //删除当前数据库

        $redis->set("name", "kongling");  //保存 K-V 键值对字符串   

        dd($redis->get("name"), "get key:name");  //获取 key:name 的value值  

        // $redis->Mget('name');   //批量读取keys    

        $redis->type("name");  //判断key 的类型 

        $redis->set("name", "sixstar");    //修改 value 值 /直接覆盖

        //修改/替换 value 部分 值

        $redis->setRange("name", 3, "fire"); //把 sixstar 修改为 sixfire

        dd($redis->get("name"), '把 sixstar 修改为 sixfire');

      

        $redis->getrange("name", 0, 5);   //截取字符串长度


        //判断key 是否存在,如果存在不修改,如果不存在新增  赋值判断原值是否存在,存在不赋值,返回0;不存在才赋值,返回1;命令setnx

        $redis->setnx("name", "hello world");

        //设置key 生存时间

        $redis->set("zoon", "dog");

        $redis->expire("zoon", 20); //单位 秒

        $redis->setex("botany", 50, "flower"); //单位 秒

        $redis->psetex("botany", 50000, "fruits"); //单位 毫秒

        //获取key 的生存时间

        $redis->ttl("zoon"); //单位 秒

        $redis->pttl("botany"); //单位 毫秒

        //mset 同时设置多个kv键值对

        $arr = [

            "dog_name" => "小花",

            "cat_name" => "小毛",

            "fish_name" => "小飞",

        ];

        $redis->mset($arr);

        $redis->msetnx($arr); // msetnx 为原子性,判断如果有一个存在,全部都不设置


        //给 key 尾部追加字符串

        $redis->append("name", "is veally good");


        // 获取原有value值的同时写入新的value值

        $redis->getset("name", "veally goods");


        // redis数据加法计算命令incr,incrby,数据加法运算,incr为+1内置运算,incrby为+n自设n运算

        $redis->incr("count");

        $redis->incrby("num", 10);


        //redis数据减法计算命令decr,decrby, 数据减法运算,decr为-1内置运算,decrby为减n自设n运算

        // $redis->set("count", 10);

        dd($redis->decr("count"), 'decr("count")');

        $redis->decrby("num", 5);


        //获取string长度的命令strlen

        $redis->strlen("name");


        //删除key

        $redis->del("name");

       

    }

    /*

     * string 应用场景

     * session 分布式集群服务器 登录同步

     * 配置服务器的 PHP 的session 存储到 Redis中去

     * 具体操作 :略

     * */


    /*

     * string 应用场景

     * Inc incrBy decr decrBy 计数器

     * */

    if(0){

        $redis->incr("count"); //每次自动加一

        $redis->incrBy("num",3);//每次自动加 自定义数值


        $redis->decr("count"); //每次自动减一

        $redis->decrBy("num",3);//每次自动减 自定义数值

    }

    /*

     * 请求拦截

     * 短信发送

     * 5分钟内最多发送5次

     * */

    if(1){

    //    $redis->flushAll();

        $phone = "130****1418";

        $key = "phone:".$phone;

        $redis->exists($key) ? $redis->incr($key) : $redis->setex($key,30,1)  ;

       /* if(!$redis->exists($key)  ){

            $redis->setex($key,30,1);

            dd($redis->get($key),"count ");

        }else{

            dd("count incr ");

            $redis->incr($key);

        }*/

        $count = $redis->get($key);

        if($count>5){

            exit("对不起,您发送次数太过频繁,请稍后再发送");

        }

        //to do send Phone Msg

        dd($count,"to do send Phone Msg");

    }



  • 1 已解决
    0
    rabbitmq中有没有类似redis中set类型的队列?

    如果没有,该如何确保队列中数据是不重复的呢呢

  • 1 已解决
    0
    Shiro 异步报错

    web.xml 关键配置, 可以确定的是配置顺序没有问题

    <!-- 安全过滤 -->
    	<filter>
    		<filter-name>shiroFilter</filter-name>
    		<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
    		<async-supported>true</async-supported>
    		<init-param>
    			<param-name>targetFilterLifecycle</param-name>
    			<param-value>true</param-value>
    		</init-param>
    	</filter>
    	<filter-mapping>
    		<filter-name>shiroFilter</filter-name>
    		<url-pattern>*.do</url-pattern>
    		<url-pattern>*.json</url-pattern>
    		<url-pattern>*.xhtml</url-pattern>
    	</filter-mapping>
    	
    	<!-- SpringMVC功能 -->
    	<servlet>
    		<servlet-name>dispatcher</servlet-name>
    		<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    		<init-param>
    			<param-name>contextConfigLocation</param-name>
    			<param-value>/META-INF/spring/appconf-*.xml</param-value>
    		</init-param>
    		<load-on-startup>1</load-on-startup>
    		<async-supported>true</async-supported>
    	</servlet>
    	<servlet-mapping>
    		<servlet-name>dispatcher</servlet-name>
    		<url-pattern>*.do</url-pattern>
    		<url-pattern>*.json</url-pattern>
    		<url-pattern>*.xhtml</url-pattern>
    	</servlet-mapping>

    控制器代码1, 像这样加入异步处理,正常响应,但是后台报错

    /**
    	 * 分页查询
    	 * 
    	 * @param queryVo
    	 * @return Pagination<DynamicformVo>
    	 */
    	@RequestMapping("queryPage")
    	@ResponseBody
    	public Callable<Pagination<DynamicformVo>> getGrid(@ModelAttribute("DynamicformQueryVo") final DynamicformQueryVo queryVo) {
    		return new Callable<Pagination<DynamicformVo>>() {
    			@Override
    			public Pagination<DynamicformVo> call() throws Exception {
    				return dynamicformService.queryForPage(queryVo);
    			}
    		};
    	}

     

    控制器代码2, 像这样写,正常处理没有报错,可惜不支持异步

    /**
    	 * 分页查询
    	 * 
    	 * @param queryVo
    	 * @return Pagination<DynamicformVo>
    	 */
    	@RequestMapping("queryPage")
    	@ResponseBody
    	public Pagination<DynamicformVo> getGrid(@ModelAttribute("DynamicformQueryVo") final DynamicformQueryVo queryVo) {
    		return dynamicformService.queryForPage(queryVo);
    	}

    报错如下:

    org.apache.shiro.UnavailableSecurityManagerException: No SecurityManager accessible to the calling code, either bound to the org.apache.shiro.util.ThreadContext or as a vm static singleton.  This is an invalid application configuration.
    	at org.apache.shiro.SecurityUtils.getSecurityManager(SecurityUtils.java:123)
    	at org.apache.shiro.subject.Subject$Builder.<init>(Subject.java:627)
    	at org.apache.shiro.SecurityUtils.getSubject(SecurityUtils.java:56)
    	at org.apache.shiro.web.servlet.ShiroHttpServletRequest.getSubject(ShiroHttpServletRequest.java:88)
    	at org.apache.shiro.web.servlet.ShiroHttpServletRequest.getSubjectPrincipal(ShiroHttpServletRequest.java:93)
    	at org.apache.shiro.web.servlet.ShiroHttpServletRequest.getUserPrincipal(ShiroHttpServletRequest.java:111)
    	at org.springframework.web.servlet.FrameworkServlet.getUsernameForRequest(FrameworkServlet.java:1079)
    	at org.springframework.web.servlet.FrameworkServlet.publishRequestHandledEvent(FrameworkServlet.java:1065)
    	at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:996)
    	at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:863)
    	at javax.servlet.http.HttpServlet.service(HttpServlet.java:646)
    	at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:837)
    	at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
    	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
    	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
    	at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:748)
    	at org.apache.catalina.core.ApplicationDispatcher.doDispatch(ApplicationDispatcher.java:659)
    	at org.apache.catalina.core.ApplicationDispatcher.dispatch(ApplicationDispatcher.java:625)
    	at org.apache.catalina.core.AsyncContextImpl$1.run(AsyncContextImpl.java:237)
    	at org.apache.catalina.core.AsyncContextImpl.doInternalDispatch(AsyncContextImpl.java:380)
    	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:215)
    	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
    	at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501)
    	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)
    	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
    	at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)
    	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
    	at org.apache.catalina.connector.CoyoteAdapter.asyncDispatch(CoyoteAdapter.java:299)
    	at org.apache.coyote.http11.AbstractHttp11Processor.asyncDispatch(AbstractHttp11Processor.java:1632)
    	at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:599)
    	at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.doRun(AprEndpoint.java:2441)
    	at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:2430)
    	at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
    	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
    	at java.lang.Thread.run(Thread.java:619)

     如上所述,Shiro 在处理Servlet3异步请求时会出现异常?要怎么处理呢?可以通过log4j配置把该错误屏蔽掉,但这不是我想要的效果!

  • 1 已解决
    0
    为啥redis的set类型存储超过一万条数据就会性能下降?

    为啥redis的set类型存储超过一万条数据就会性能下降?

  • 1 已解决
    0
    redis大量key怎么存比较省空间

    7000w+简单key(key产生规则是笛卡尔积),vlaue基本就是1、2、3这种简单数字,怎么存比较省空间

  • 1 已解决
    0
    两个并发同时请求,修改数据导致数据有一次修改相同的数据

    attachments-2020-03-8xwsbGrD5e6f1f434a35e.png

    加了悲观锁,

    加了泄洪队列,

    加了限流,

    还会出现

  • 1 已解决
    0
    mysql从5.6升级8.0后,sql查询变慢

    听说mysql8比mysql5要快很多,我们就尝试将mysql从5.6升级到8.0,然后有些sql就变慢了

    sql如下:

    SELECT
       a.id AS 'id',
       CONCAT(a.firstname,' ',a.lastname) AS 'name',
       a.name AS fullName,
       a.firstname AS 'firstname',
       a.lastname AS 'lastname',
       a.teaching_style as teachingStyle,
       a.type_of_english as typeOfEnglish,
       a.avatar AS 'avatar',
       a.avatar_url AS 'avatarurl',
       c.course_id AS courseId,
       CONCAT(
       IFNULL(a.favorable_rate, '100'),
       '%'
       ) AS rate,
       f.file_path AS path
      FROM
      busi_teacher a
      LEFT JOIN busi_tea_schedule b  ON a.id = b.tea_id
      LEFT JOIN busi_tea_course c ON (a.id = c.tea_id AND c.issys = 1)
      LEFT JOIN busi_stu_course d ON b.stu_course = d.id
      LEFT JOIN busi_file f ON f.id = a.avatar
      WHERE   b. STATUS = 1
      AND b.can_normal = 1
      AND ( (a.is_fulltime = 1 AND b.is_contracted = 1) OR a.is_fulltime != 1 )
      AND b.ex_schedule_date > DATE_ADD(NOW(), INTERVAL 24 HOUR)
      AND (b.ex_schedule_date < '2019-12-25 08:00:00' OR b.ex_schedule_date > '2019-12-27 07:59:00')
      AND (b.ex_schedule_date < '2020-01-01 08:00:00' OR b.ex_schedule_date > '2020-01-02 07:59:00')
       AND a. STATUS IN (3, 7)
      AND b.del_flag = 0
      AND a.del_flag = 0
      AND a.isuse = 1
      AND (b.stu_course IS NULL OR d.course_status = 3)
      AND  FIND_IN_SET('152',c.course_id)
        AND HOUR(b.ex_schedule_date) < 21
        GROUP BY a.id
      ORDER BY b.is_contracted DESC, a.promoted DESC,(CASE a.is_fulltime WHEN 1 THEN 1 WHEN 0 THEN 2 ELSE 3 END),a.firstname
      LIMIT  10;

    mysql版本5.6.16-log:执行0.157s,explain如下

    up-241e59b6556c3035de3c5b00420006376dd.png

    up-88b6df7fe9fd90c05c914e8763339cd2948.png

    mysql版本8.0.16:执行2.080s,explain如下

    up-06593bfbafd4c908443f2af7f60b1162a2a.png

    up-d0ef442beab9c7849e0f00b3c134489cb5b.png

    mysql8先执行a表,mysql5.6先执行b表。mysql8的Creating sort index花费了99%的时间,我将排序去掉后两个版本都执行一遍后,mysql8是要比mysql5.6要快,但是加上排序后mysql8就很慢了,感觉是在mysql8中排序并没有用到索引。有没有大神能看出来是哪儿出了问题吗,是mysql系统参数设置有问题吗?

  • 1 未解决
    0
    mysql 条件排序写法

    先显示50公里(后台可以设置多少公里)以内,3天(后台可以设置几天)以内发布的动态,要在线的,按距离排序,不按发布的时间,如果3天以内同一个人发布了多条,就只显示这个人最新的一条就可以了,多的就不用显示了, 显示完以后,再显示50公里以外的,1天(后台可以设置几天)以内发布的动态,要在线的,按距离排序,不按发布的时间,如果1天以内同一个人发布了多条,就只显示这个人最新的一条就可以了,多的就不用显示了,最后显示不在线的,按距离显示就行了。(后台要有个设置,男女一天可以查看多少条动态)

  • 1 未解决
    0
    redis 怎么实现分布式锁?

    分布式锁一般有三种实现方式:

    1. 数据库乐观锁;

    2. 基于Redis的分布式锁;

    3. 基于ZooKeeper的分布式锁。

  • 1 未解决
    0
    传统项目 连接mysql数据库,无法连接

    传统ssh项目,连接本地mysql数据库,eclipse中,tomcat启动,初始化数据库时无法连接,百思不得解,gogle、百度无解。

    尝试方法:

    1、设置MySQL最大等待时间。

    2、关闭防火墙

    3、重装mysql数据库

    4、…等能查到的都试过了


    原因分析

    项目只有在连接无线时无法连接报错,连接网线时可以启动并访问,排除项目中配置数据库文件的问题。

    把项目打成war包在别人的电脑上启动,无线或者网线均无问题,排除项目代码问题

    我的电脑是刚重装过系统,怀疑是跟电脑那里配置有问题,但是又不知从何查起,求教大家意见,积分不多,都给你们了


    [INFO ] [13:24:33] org.springframework.context.support.PostProcessorRegistrationDelegate$BeanPostProcessorChecker - Bean 'securityManager' of type [class org.apache.shiro.web.mgt.DefaultWebSecurityManager] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)

    [INFO ] [13:24:34] org.springframework.orm.hibernate5.HibernateTransactionManager - Using DataSource [org.apache.commons.dbcp.BasicDataSource@1687d553] of Hibernate SessionFactory for HibernateTransactionManager

    [ERROR] [13:24:55] org.activiti.engine.impl.cfg.ProcessEngineConfigurationImpl - Exception while initializing Database connection

    org.apache.commons.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (Communications link failure


    The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.)

    at org.apache.commons.dbcp.BasicDataSource.createPoolableConnectionFactory(BasicDataSource.java:1549)

    at org.apache.commons.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:1388)

    at org.apache.commons.dbcp.BasicDataSource.getConnection(BasicDataSource.java:1044)

    at org.springframework.jdbc.datasource.DataSourceUtils.doGetConnection(DataSourceUtils.java:111)

    at org.springframework.jdbc.datasource.TransactionAwareDataSourceProxy$TransactionAwareInvocationHandler.invoke(TransactionAwareDataSourceProxy.java:225)

    at com.sun.proxy.$Proxy59.getMetaData(Unknown Source)

    at org.activiti.engine.impl.cfg.ProcessEngineConfigurationImpl.initDatabaseType(ProcessEngineConfigurationImpl.java:686)

    at org.activiti.engine.impl.cfg.ProcessEngineConfigurationImpl.initDataSource(ProcessEngineConfigurationImpl.java:636)

    at org.activiti.engine.impl.cfg.ProcessEngineConfigurationImpl.init(ProcessEngineConfigurationImpl.java:452)

    at org.activiti.engine.impl.cfg.ProcessEngineConfigurationImpl.buildProcessEngine(ProcessEngineConfigurationImpl.java:440)

    at org.activiti.spring.SpringProcessEngineConfiguration.buildProcessEngine(SpringProcessEngineConfiguration.java:65)

    at org.activiti.spring.ProcessEngineFactoryBean.getObject(ProcessEngineFactoryBean.java:60)

    at org.activiti.spring.ProcessEngineFactoryBean.getObject(ProcessEngineFactoryBean.java:32)

    at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.doGetObjectFromFactoryBean(FactoryBeanRegistrySupport.java:168)

    at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.getObjectFromFactoryBean(FactoryBeanRegistrySupport.java:103)

    at org.springframework.beans.factory.support.AbstractBeanFactory.getObjectForBeanInstance(AbstractBeanFactory.java:1585)

    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:317)

    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)

    at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:368)

    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1123)

    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1018)

    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:510)

    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)

    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)

    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)

    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)

    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)

    at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:1192)

    at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1116)

    at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1014)

    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:545)

    at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88)

    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:331)

    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1214)

    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:543)

    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)

    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)

    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)

    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)

    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)

    at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:1192)

    at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1116)

    at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1014)

    at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.autowireResource(CommonAnnotationBeanPostProcessor.java:508)

    at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.getResource(CommonAnnotationBeanPostProcessor.java:486)

    at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor$ResourceElement.getResourceToInject(CommonAnnotationBeanPostProcessor.java:615)

    at org.springframework.beans.factory.annotation.InjectionMetadata$InjectedElement.inject(InjectionMetadata.java:169)

    at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88)

    at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.postProcessPropertyValues(CommonAnnotationBeanPostProcessor.java:308)

    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1214)

    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:543)

    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)

    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)

    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)

    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)

    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)

    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:772)

    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:838)

    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:537)

    at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)

    at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:93)

    at com.sinosoft.common.BeanFactory.<clinit>(BeanFactory.java:27)

    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)

    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)

    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)

    at java.lang.reflect.Constructor.newInstance(Constructor.java:526)

    at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:147)

    at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:89)

    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:1098)

    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1050)

    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:510)

    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)

    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)

    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)

    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)

    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)

    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:772)

    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:838)

    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:537)

    at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:446)

    at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:328)

    at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:107)

    at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:5099)

    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5615)

    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:147)

    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1571)

    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1561)

    at java.util.concurrent.FutureTask.run(FutureTask.java:262)

    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)

    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)

    at java.lang.Thread.run(Thread.java:745)

    Caused by: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure


    The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.

    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)

    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)

    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)

    at java.lang.reflect.Constructor.newInstance(Constructor.java:526)

    at com.mysql.jdbc.Util.handleNewInstance(Util.java:425)

    at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:990)

    at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:342)

  • 1 未解决
    0
    mysql查询太慢

    遇到一个mysql查询问题,两条一模一样的sql语句,在测试服务器执行sql语句用了4秒,在生产环境执行sql语句用了120秒,两张表数据基本相同,索引一模一样,请问是什么原因导致生成环境sql执行这么慢。。

    attachments-2020-03-VEpJcnt95e5f78622d5f9.pngattachments-2020-03-aesdhxrm5e5f78677d841.png

    explain

    attachments-2020-03-o6axDtnY5e5f786fd2f2c.png

    attachments-2020-03-HNu5UhNL5e5f78767e1be.png

  • 1 未解决
    0
    redis集群间如何同步

    有两个机房A和B,机房A部署有redisA集群,机房B部署有redisB集群。这俩redis集群互为备份,数据完全一致,redisA集群如何与redisB同步数据?### 问题描述

  • 1 未解决
    0
    RabbitMQ异常:inequivalent arg 'x-message-ttl' for queue和Failed to check/redeclare auto-delete queue(s)

    SpringMVC项目集成RabbitMQ


    当新增了queue的x-message-ttl属性后,项目重启时报如下异常。我尝试着手动在RabbitMQ后台管理界面去重新创建这个queue,错误依旧如下。

    这个异常目前不影响运行,请问什么原因导致,怎么解决?


    | ERROR | 2020-02-04 21:25:08 | CachingConnectionFactory.java | shutdownCompleted | 292 | Channel shutdown: channel error; protocol method: #method<channel.close>(reply-code=406, reply-text=PRECONDITION_FAILED - inequivalent arg ‘x-message-ttl’ for queue ‘ca_auth’ in vhost ‘/ca-auth’: received ‘30000’ but current is ‘30000’, class-id=50, method-id=10) |

    | ERROR | 2020-02-04 21:25:08 | SimpleMessageListenerContainer.java | redeclareElementsIfNecessary | 975 | Failed to check/redeclare auto-delete queue(s). |

    attachments-2020-03-PPoIKAzC5e5f774182374.png

    attachments-2020-03-SiDnbmyM5e5f774aee215.png


    spring版本:3.2.11.RELEASE

    spring-rabbit版本:1.4.6.RELEASE


    rabbitMQ配置文件如下


    <?xml version="1.0" encoding="UTF-8"?>

    <beans xmlns="http://www.springframework.org/schema/beans"

           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:rabbit="http://www.springframework.org/schema/rabbit"

           xsi:schemaLocation="http://www.springframework.org/schema/beans

         http://www.springframework.org/schema/beans/spring-beans-3.0.xsd

         http://www.springframework.org/schema/rabbit

         http://www.springframework.org/schema/rabbit/spring-rabbit-1.4.xsd">

         

        <rabbit:connection-factory id="connectionFactory" virtual-host="/ca-auth" username="guest" password="guest" host="127.0.0.1" port="5672" publisher-confirms="true" publisher-returns="true"/>

        <!-- 通过指定下面的admin信息 -->

        <rabbit:admin id="connectAdmin" connection-factory="connectionFactory" />


        <!--定义queue -->

        <rabbit:queue name="ca_auth" durable="true" exclusive="false" declared-by="connectAdmin">

        <rabbit:queue-arguments>

      <entry key="x-message-ttl">

      <value>30000</value>

      </entry>

    <entry key="x-dead-letter-exchange">

    <value>dlx.file_to_file</value>

    </entry>

    <entry key="x-dead-letter-routing-key">

    <value>ca</value>

    </entry>

      </rabbit:queue-arguments>

        </rabbit:queue>

        <rabbit:queue name="dlx.ca_auth" durable="true" exclusive="false" declared-by="connectAdmin">

        <rabbit:queue-arguments>

      <entry key="x-message-ttl">

      <value>30000</value>

      </entry>

        </rabbit:queue-arguments>

        </rabbit:queue>


        <!--定义direct exchange -->

        <rabbit:direct-exchange name="file_to_file" durable="true" declared-by="connectAdmin">

            <rabbit:bindings>

                <rabbit:binding queue="ca_auth" key="ca"/>

            </rabbit:bindings>

        </rabbit:direct-exchange>

        

        <rabbit:direct-exchange name="dlx.file_to_file" durable="true" declared-by="connectAdmin">

            <rabbit:bindings>

                <rabbit:binding queue="dlx.ca_auth" key="ca"/>

            </rabbit:bindings>

        </rabbit:direct-exchange>

        

        <!--定义rabbit template -->

        <rabbit:template id="amqpTemplate" connection-factory="connectionFactory" exchange="file_to_file" confirm-callback="confirmCallBackListener" mandatory="true" return-callback="returnCallBackListener" retry-template="retryTemplate"/>


        <!--定义receiver -->

        <bean id="messageReceiver" class="com.cnpany.common.fadada.service.impl.AsynHandler"></bean>

        <!--定义listener -->

        <rabbit:listener-container connection-factory="connectionFactory" requeue-rejected="false">

            <rabbit:listener queues="ca_auth" ref="messageReceiver" />

        </rabbit:listener-container>

        

        <bean id="retryTemplate" class="org.springframework.retry.support.RetryTemplate">

          <property name="retryPolicy">

             <bean class="org.springframework.retry.policy.SimpleRetryPolicy">

                <property name="maxAttempts" value="3"/>

             </bean>

          </property>

       </bean>

    </beans>

    最终解决

    根据青山老师给出的提示,具体解决如下

    1、当在RabbitMQ后台管理界面去对Queue新增x-message-ttl时需要选择取值类型,此时取值不能选择String,否则提示属性可接受类型异常。注意:必须选择Number。

    attachments-2020-03-rNIJCa0W5e5f7756196a2.png

    attachments-2020-03-5i4BHmjI5e5f775d8e383.png

    2、由此可以想到,xml配置文件中的x-message-ttl必须是数值类型。再由xsd配置规则,value标签默认取值类型为String,需要指定类型完成类型转换。

    配置文件中关于x-message-ttl的配置需要增加type=“java.lang.Long”


    <rabbit:queue-arguments>

    <entry key="x-message-ttl">

    <value type="java.lang.Long">30000</value>

    </entry>

    </rabbit:queue-arguments>

  • 1 未解决
    0
    有谁做过 给word模板的 复选框自动填充数据

    attachments-2020-03-bsvwca7d5e5e2ad88674f.png

    有谁做过 给word模板的 复选框自动填充数据?这个点击勾选怎么做的

  • 1 未解决
    0
    java web项目(基于servlet原生web项目),怎么集成rocketMQ消息中间件!

    1.集成rocketMQ,引入哪些jar包
    2.web项目创建producer者类和消费者类
    3.web项目启动了,生产者和消费者如何启动,是不是在web容器初始化启动生产者和消费者,还是在调用的时候?
    4.如果在web容器初始化,如何弄?
    5.希望有代码解决?

  • 1 未解决
    0
    从REDIS和数据库一致性,更新原则的一点困惑?

    从REDIS和数据库一致性参考资料中,https://www.lagou.com/lgeduarticle/28616.html

    有这样一个规则:

    更新缓存时,先更新数据库,再将缓存的设置过期(建议不要去更新缓存内容,直接设置缓存过期)。

    其中,“建议不要去更新缓存内容”, 这个是为什么? 没怎么理解?

  • 1 未解决
    0
    MySQL可重复读RR,解决了幻读了么?

    RR本事是没有解决幻读的?

    但MySQL解决了幻读问题了么? 怎么解决的?还是接受了幻读问题。

    这块有点晕。

    希望各位大侠能给些点拨。

  • 1 未解决
    0
    如何保证队列的消息不被重复消费,用redis是怎么搞的?

    下面的第二点,没怎么理解。有劳,有大侠能解释一下么。


    【另外,还有什么别的方案么。 总觉按照参考的这几点得这么搞,吞吐量会下降。】


    7、如何保证队列的消息不被重复消费?

    这个需要灵活作答,考察的是思考力,因为消费的场景有很多,有数据库、有缓存、有第三方接口


    1.比如针对数据库,你拿到这个消息做数据库的insert操作。那就容易了,给这个消息做一个唯一主键(或者UUID),那么就算出现重复消费的情况,就会导致主键冲突,避免数据库出现脏数据。

    2.再比如redis缓存,你拿到这个消息做redis的set的操作,那就容易了,不用解决,因为你无论set几次结果都是一样的,set操作本来就算幂等操作。

    3.再比如第三方接口,需要确定两点,第三方接口程序是有去重能力的,那么脏一点直接丢数据过去,如果没有去重能力,还是需要我们来写程序去重,就是第2点的办法。


  • 1 未解决
    0
    数据库已存在的大数据量的表如何进行分表

    由于历史原因,系统中有一张表数据量逐年变大,变到了几千万甚至上亿,这些数据不能像日志一样定时归档和删除,求问怎么做分表?