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檔案
異常: 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