How can I configure Java Melody with JPA configured in Spring but not using a persistence.xml file. Note: I am specifically using eclipselink. The java melody instructions only show configuring with a persistence.xml file: https://code.google.com/p/javamelody/wiki/UserGuideAdvanced#JPA_monitoring
Asked
Active
Viewed 633 times
1 Answers
1
If you are using Spring with the JpaVendorAdapter abstraction you can create your own Java Melody enabled Vendor Adapter. Here is an example of one I created for eclipselink. Note: this shows that java melody can be configured without using a persistence.xml file.
/**
* 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...
}

bunyaCloven
- 313
- 1
- 4
- 14

Travis Schneeberger
- 2,010
- 20
- 23
-
Note: I am using reflection here only to avoid compile time dependencies on java melody. It is otherwise not necessary. – Travis Schneeberger Jul 17 '15 at 14:05