Java开发中遇到异常的解决办法

在这里插入图片描述
异常: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:
场景: 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文件

yarn.nodemanager.resource.memory-mb 1600 yarn.nodemanager.resource.cpu-vcores 1

异常: 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
文章来自:https://www.itjmd.com/news/show-5314.html