跳到主要內容

發表文章

目前顯示的是有「spring」標籤的文章

BeanDefinitionStoreException with ClassFormatError

使用Spring過程中突然發生application server啟動即出現bean definition file parsing的以下錯誤: BeanDefinitionStoreException: Unexpected exception parsing XML doc ument from class path resource.. nested exception java.lang.ClassFormatError: Unknown constant tag 0 in class file com/sun/org/apache/xerces/internal.. 詳細檢查了數次都找不到xml哪裡有錯。 ClassFormatError這個錯誤很少見,似乎是JVM內Hotspot相關的錯誤,而且同時其他所有舊的project使用Spring原本可以正常執行的,現在都會產生這個錯誤。 研判可能是JVM出了什麼問題,重裝JDK1.5這個問題就消失了。

使用Spring的HibernateDAOSupport可能遇到的Lazy initialization問題

在專案中我們使用DAO這個pattern來封裝資料庫存取層,Hibernate Quickly (Manning)中建議我們可以繼承Spring所提供的HibernateDAOSupport來簡化DAO程式碼,這是很常見的作法。 原本method重複性很高的部份: public void create(Event event) throws DataAccessLayerException { try { startOperation(); session.save(event); tx.commit(); } catch (HibernateException e) { handleException(e); } finally { HibernateFactory.close(session); } } 可以被簡化為: public abstract class AbstractSpringDao extends HibernateDaoSupport{ public AbstractSpringDao() { } protected void saveOrUpdate(Object obj) { getHibernateTemplate().saveOrUpdate(obj); } protected void delete(Object obj) { getHibernateTemplate().delete(obj); } ... } 都透過Sprgin提供的HibernateTemplate幫我們作掉那些重複的開、關session, transaction動作。 以下擷取自Spring原始碼 package org.springframework.orm.hibernate3; ... public class HibernateTemplate extends HibernateAccessor implements HibernateOperations { ... public Object execute(HibernateCallback action) throws DataAccessException { Session session = (!this.a...

一個Web Application系統架構 (Spring + Struts + Hibernate)

近期使用這三套framework作系統,系統架構如下: 其中使用的Design Pattern: MVC: To separate core business model functionality from the presentation and control logic that uses this functionality. Such separation allows multiple views to share the same enterprise data model, which makes supporting multiple clients easier to implement, test, and maintain. Front Controller Use a controller as the initial point of contact for handling a request. The controller manages the handling of the request, including invoking security services such as authentication and authorization, delegating business processing, managing the choice of an appropriate view, handling errors, and managing the selection of content creation strategies. DAO(Data Access object) To abstract and encapsulate all access to the data source. The DAO manages the connection with the data source to obtain and store data. 如果同時運用這三個application framework,這樣的架構算是很常見。 Pros: 運用struts前端控制器(front controller)來集中管理頁面導引 Struts custom tag來強化 JSP的不足 用Sp...