• 日常遇到的小问题


    日常开发过程中,总会遇到各种小问题,特此记录下各种解决。

    1. eclipse中部署项目到tomcat,启动tomcat时报错: 

    Resource is out of sync with the file system: ................

    太长只截取前一段,解决办法:需要手动刷新一下资源管理器,eclipse中,工程目录右键,refresh。

    2.maven项目打包的时候,mybatis的*mapper.xml都没得打包,解决方法pom.xml中build节点中加入:

             <resources>
                <resource>
                    <directory>src/main/java</directory>
                    <includes>
                        <include>**/*.xml</include>
                    </includes>
                    <filtering>false</filtering>
                </resource>
            </resources>    

     3.mybatis的数据库连接配置信息写在properties配置文件中,然后做spring做单元测试的时候,总是报出

    Could not load driverClass ${jdbc.driverClass}

    错误的原因很明显,相关的连接参数信息并没有正确的去读取properties配置文件中的相关信息,本地项目使用的mybaits版本号3.1.1。网上查找解决办法,是由于

    <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
            <property name="basePackage" value="com.reserve.core.dao" />
            <property name="sqlSessionFactory" ref="sqlSessionFactory"></property>
    </bean>

    中的sqlSessionFactory注入问题,改用sqlSessionFactoryBeanName注入就没有问题(不要使用sqlSessionFactory属性注入,使用 sqlSessionFactoryBeanName注入),因为这时不会立即初始化sqlSessionFactory,传入的只是名字,非bean, 所以不会引发提前初始化问题。

    <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"></property>

     4.获取泛型T.class。最近最项目中,用到泛型设计,但是要获取T.class,方法如下:

    public abstract class DataSyncProService<T extends Data> implements DataSyncService{
        
        private Class<T> entityClass;//获取泛型T的T.class
        
        public DataSyncProService(){
            Type genType = getClass().getGenericSuperclass();
            Type[] params = ((ParameterizedType) genType).getActualTypeArguments(); 
            entityClass = (Class) params[0]; 
        }
        ....
    }

    截取部分代码,子类的构造函数会调用父类的构造函数,所以当子类实例化的时候,父类的entityClass 已经得到了T.class。

    本地代码其中一个子类定义:

    public class MerinfoImpl extends DataSyncProService<MerInfo>

    另外,照搬一段资料,虽然现在还不是很懂:

    这是泛型擦拭法使得Generic无法获取自己的Generic Type类型。实际上BadClass<String>()实例化以后Class里面就不包括T的信息了,
    对于Class而言T已经被擦拭为Object,而真正的T参数被转到使用T的方法(或者变量声明或者其它使用T的地方)里面(如果没有那就没有存根),
    所以无法反射到T的具体类别,也就无法得到T.class。而getGenericSuperclass()是Generic继承的特例,对于这种情况子类会保存父类的Generic参数类型,
    返回一个ParameterizedType,这时可以获取到父类的T.class了,这也正是子类确定应该继承什么T的方法

     5.jquery修改css中带有!important的样式属性

    html : <select class="select1" id="jq-sql-content"></select>
    外部样式为 .select1{color: #e3e3e3!important;}
    如果直接使用:$("#jq-sql-content").css("color","black")或者$("#jq-sql-content").css("color","black!important"),都是无效的
    正确用法$("#jq-sql-content").css("cssText","color:black!important"),多个属性的话$("#jq-sql-content").css("cssText","color:black!important;属性名:值!important;")

    6、linux安装activemq

      安装完毕之后,启动时候报错如下

      

    2018-06-05 11:26:06,750 | WARN  | Exception thrown from LifecycleProcessor on context close | org.apache.activemq.xbean.XBeanBrokerFactory$1 | main
    java.lang.IllegalStateException: LifecycleProcessor not initialized - call 'refresh' before invoking lifecycle methods via the context: org.apache.activemq.xbean.XBeanBrokerFactory$1@6bbee61a: startup date [Tue Jun 05 11:26:03 CST 2018]; root of context hierarchy
        at org.springframework.context.support.AbstractApplicationContext.getLifecycleProcessor(AbstractApplicationContext.java:360)
        at org.springframework.context.support.AbstractApplicationContext.doClose(AbstractApplicationContext.java:1057)
        at org.springframework.context.support.AbstractApplicationContext.close(AbstractApplicationContext.java:1010)
        at org.apache.activemq.hooks.SpringContextHook.run(SpringContextHook.java:30)
        at org.apache.activemq.broker.BrokerService.stop(BrokerService.java:809)
        at org.apache.activemq.xbean.XBeanBrokerService.stop(XBeanBrokerService.java:122)
        at org.apache.activemq.broker.BrokerService.start(BrokerService.java:601)
        at org.apache.activemq.xbean.XBeanBrokerService.afterPropertiesSet(XBeanBrokerService.java:73)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:606)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeCustomInitMethod(AbstractAutowireCapableBeanFactory.java:1638)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1579)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1509)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:521)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:458)
        at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:296)
        at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223)
        at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:293)
        at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
        at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:628)
        at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:932)
        at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:479)
        at org.apache.xbean.spring.context.ResourceXmlApplicationContext.<init>(ResourceXmlApplicationContext.java:64)
        at org.apache.xbean.spring.context.ResourceXmlApplicationContext.<init>(ResourceXmlApplicationContext.java:52)
        at org.apache.activemq.xbean.XBeanBrokerFactory$1.<init>(XBeanBrokerFactory.java:104)
        at org.apache.activemq.xbean.XBeanBrokerFactory.createApplicationContext(XBeanBrokerFactory.java:104)
        at org.apache.activemq.xbean.XBeanBrokerFactory.createBroker(XBeanBrokerFactory.java:67)
        at org.apache.activemq.broker.BrokerFactory.createBroker(BrokerFactory.java:71)
        at org.apache.activemq.broker.BrokerFactory.createBroker(BrokerFactory.java:54)
        at org.apache.activemq.console.command.StartCommand.runTask(StartCommand.java:87)
        at org.apache.activemq.console.command.AbstractCommand.execute(AbstractCommand.java:57)
        at org.apache.activemq.console.command.ShellCommand.runTask(ShellCommand.java:150)
        at org.apache.activemq.console.command.AbstractCommand.execute(AbstractCommand.java:57)
        at org.apache.activemq.console.command.ShellCommand.main(ShellCommand.java:104)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:606)
        at org.apache.activemq.console.Main.runTaskClass(Main.java:262)
        at org.apache.activemq.console.Main.main(Main.java:115)

    首先确定的是并不是权限问题,权限问题在./bin/activemq start启动是就会报出permission denied。查询资料,得知此根源为当前主机名,去除主机名中的下划线即可。永久生效的话,需修改/etc/sysconfig/network和/etc/hostname文件。临时生效直接命令hostname "你要定义的主机名",再下次重启之前都有效。


     7、VMware centos6.9选择链接克隆ip以及网络链接问题

        选择链接克隆,与原始虚拟机共享同一虚拟磁盘文件,不能脱离原始虚拟机独立运行。但采用共享磁盘文件却大大缩短了创建克隆虚拟机的时间,同时还节省了宝贵的物理磁盘空间。通过链接克隆,可以轻松的为不同的任务创建一个独立的虚拟机。 

        首先,打开/etc/udev/rules.d/70-persistent-net.rules内容如下面例子所示:

    记住eth1的网卡地址:000c:29:3d:83:b1

        接下来,编辑  vi   /etc/sysconfig/network-scripts/ifcfg-eth0

          将 DEVICE="eth0"  改成  DEVICE="eth1"  ,
          将 HWADDR="00:0c:29:46:62:f9" 改成上面的mac地址  HWADDR="00:0c:29:3d:83:b1"

    重启网络:service network restart    或者  /etc/init.d/network restart

  • 相关阅读:
    mysql索引最左匹配的理解(转载于知乎回答)
    mysql深度优化与理解(迄今为止读到最优秀的mysql博客)
    PHP数组函数总结与使用
    进程(process)和线程(thread)
    联合索引使用规则(转载)
    mysql优化大全(转自别人 )
    HTTP隧道解决的问题
    HTTP代理协议 HTTP/1.1的CONNECT方法
    vant弹窗提示
    vue获取验证码倒计时
  • 原文地址:https://www.cnblogs.com/eric-fang/p/5665871.html
Copyright © 2020-2023  润新知