0

如何使用 Spring 中配置的 JPA 配置 Java Melody,但不使用 persistence.xml 文件。注意:我专门使用eclipselink。java melody 指令仅显示使用 persistence.xml 文件进行配置: https ://code.google.com/p/javamelody/wiki/UserGuideAdvanced#JPA_monitoring

4

1 回答 1

1

如果您使用带有 JpaVendorAdapter 抽象的 Spring,您可以创建自己的启用 Java Melody 的供应商适配器。这是我为 eclipselink 创建的一个示例。注意:这表明可以在不使用 persistence.xml 文件的情况下配置 java melody。

/**
 * 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...
}
于 2015-06-04T20:17:24.533 回答