欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

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

程序员文章站 2022-04-24 22:01:58
异常:Bean named 'org.springframework.transaction.interceptor.TransactionInterceptor#0' is expected to be of type 'org.aopalliance.aop.Advice' but was ac ......

异常: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 'öð¹ú±ê׼걼ä' 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

 


 

 

可以关注一下鄙人的公众号, 谢谢各位了!Java中遇到过的一些异常及处理