2015-06-04 46 views

回答

1

如果您使用Spring並使用JpaVendorAdapter抽象,則可以創建自己的啓用了Java Melody的供應商適配器。這裏是我爲eclipselink創建的一個例子。注意:這表明可以在不使用persistence.xml文件的情況下配置java旋律。

/** 
* This is a copy of the 
* {@link org.springframework.orm.jpa.vendor.EclipseLinkJpaVendorAdapter} 
* but using the Java Melody PersistenceProvider. 
*/ 
public class MonitoringEclipseLinkJpaVendorAdapter 
     extends AbstractJpaVendorAdapter { 
    private final PersistenceProvider persistenceProvider; 
    try { 
     persistenceProvider = (PersistenceProvider) 
      Class.forName("net.bull.javamelody.JpaPersistence").newInstance(); 
    } catch(ClassNotFoundException|InstantiationException| 
      IllegalAccessException e) { 
     throw new RuntimeException(e); 
    } 
    //...snip - the rest is the same as the EclipseLinkJpaVendorAdapter class... 
} 
+0

注:我在這裏只使用反射來避免java旋律的編譯時間依賴性。否則沒有必要。 –

相關問題