Java中遇到过的一些异常及处理

2019-01-01 23:18:39来源:博客园 阅读 ()

新老客户大回馈,云服务器低至5折

异常:Bean named 'org.springframework.transaction.interceptor.TransactionInterceptor#0' is expected to be of type 'org.aopalliance.aop.Advice' but was actually of type 'org.springframework.transaction.interceptor.TransactionInterceptor'
场景;在使用spring整合hibernate事务时报错
解决:spring-aop中已经包含aopaliance,删除多余的jar包

 

异常:getHibernateFlushMode is not valid without active transaction; nested exception is org.hibernate.HibernateException: getHibernateFlushMode is not valid without active transaction getHibernateFlushMode is not valid without active transaction
场景:在使用spring整合hibernate调用的HibernateTemplate时报错
解决: 在spring配置文件中添加事务的配置

    <bean id="hibernateTransactionManager" class="org.springframework.orm.hibernate5.HibernateTransactionManager">
        <!-- 注入sessionFactory,配置sessionFactory -->
        <property name="sessionFactory" ref="sessionFactory"></property>
    </bean>
    <tx:advice id="txAdvice" transaction-manager="hibernateTransactionManager">
           <tx:attributes>
            <tx:method name="get*" read-only="true" />
            <tx:method name="*" />
        </tx:attributes>
    </tx:advice>
    <aop:config>
           <aop:pointcut id="personServiceOperation" expression="execution(* user.service.UserServiceImpl.*(..))" />
        <aop:advisor advice-ref="txAdvice" pointcut-ref="personServiceOperation" />
    </aop:config>

 

异常:android.os.NetworkOnMainThreadException
场景:安卓开发时在主线程访问网络
解决:将访问网络的代码使用Thread操作

Handler handler = new Handler(){
    @Override
    public void handleMessage(Message msg){
        Bundle data = msg.getData();
        //从data中拿出存的数据
        String val = data.getString("value");
        //将数据进行显示到界面等操作
    }
};
Runnable runnable = new Runnable(){
    @Override
    public void run(){
        //进行访问网络操作
        Message msg = Message.obtain();
        Bundle data = new Bundle();
        data.putString("value", "存放数据");
        msg.setData(data);
        handler.sendMessage(msg);
    }
};

 


异常: Call From * 9000 failed on connection exception: java.net.ConnectException: Connection refused: no further information; For more details see: http://wiki.apache.org/hadoop/ConnectionRefused
场景: eclipse链接不上阿里云hadoop
解决: 将hadoop的配置文件中的ip改为内网IP即可

 

异常: Recieved SHUTDOWN signal from Resourcemanager ,Registration of NodeManager failed, Message from ResourceManager: NodeManager from localhost doesn't satisfy minimum allocations, Sending SHUTDOWN signal to the NodeManager.
场景: 在配置hadoop时,无法启动 NodeManager
解决: 本机配置不满足,修改yarn-siet.xml文件

<!-- 设置内存 -->
<property>
    <name>yarn.nodemanager.resource.memory-mb</name>
    <value>1600</value>
</property>
<!-- 设置cpu 核数 -->
<property>
    <name>yarn.nodemanager.resource.cpu-vcores</name>
    <value>1</value>
</property>

 


异常: The server time zone value '?D1ú±ê×?ê±??' 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.
场景: Java 连接 MySQL 时连接不上
解决: 修改数据库时区
1.在mysql中执行如下语句
set global time_zone='+8:00';
2.修改数据库连接的url,加上如下参数(指定时区):
serverTimezone=GMT

 


 

 

可以关注一下鄙人的公众号, 谢谢各位了!

标签:

版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有

上一篇:Spring Data JPA简单使用

下一篇:【原】无脑操作:ElasticSearch学习笔记(01)