2

i've got a spring maven project with javamelody.

I use hibernate with spring, don't have any JNDI data scource.

the datasource in xml conf:

    <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
        <property name="driverClassName" value="com.mysql.jdbc.Driver"/>
        <property name="url" value="jdbc:mysql://${database.location}:${database.port}/${database.dbname}?zeroDateTimeBehavior=convertToNull&amp;characterEncoding=utf8"/>
        <property name="username" value="${database.username}"/>
        <property name="password" value="${database.password}"/>
    </bean> 

 <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
        <property name="persistenceXmlLocation" value="classpath:META-INF/persistence.xml" />
        <property name="persistenceUnitName" value="rtt-backend" />
        <property name="dataSource" ref="dataSource" />
        <property name="jpaVendorAdapter" ref="jpaVendorAdapter" />
        <property name="jpaDialect" ref="jpaDialect" />
    </bean>

    <bean id="jpaVendorAdapter" class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
        <property name="databasePlatform" value="org.hibernate.dialect.MySQL5Dialect" />
        <property name="database" value="MYSQL" />
        <property name="showSql" value="false" />
    </bean>

    <bean id="jpaDialect" class="org.springframework.orm.jpa.vendor.HibernateJpaDialect" />

    <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
        <property name="entityManagerFactory" ref="entityManagerFactory" />
        <property name="dataSource" ref="dataSource" />
        <property name="jpaDialect" ref="jpaDialect" />
    </bean>

    <tx:annotation-driven transaction-manager="transactionManager" />

but if i connect to javamelody monitor page says: "sql Statistics sql - 1 day -None"

I tried :

  • in presistence.xml :

    net.bull.javamelody.JpaPersistence

  • use wrapper for data source

<bean id="wrappedDataSource" class="net.bull.javamelody.SpringDataSourceFactoryBean">
<property name="targetName" value="dataSource" />   </bean>

But still nothing.

Joseph
  • 145
  • 4
  • 16

1 Answers1

5

As said in the user guide, simply add in your spring context configuration:

classpath:net/bull/javamelody/monitoring-spring.xml

Or if you want to use

<bean id="wrappedDataSource" class="net.bull.javamelody.SpringDataSourceFactoryBean">
    <property name="targetName" value="dataSource" />
</bean>

then replace in your entityManagerFactory and transactionManager

<property name="dataSource" ref="dataSource" />

with

<property name="dataSource" ref="wrappedDataSource" />
evernat
  • 1,713
  • 13
  • 18