2

我有一个 javamelody 的 spring maven 项目。

我在 spring 中使用 hibernate,没有任何 JNDI 数据源。

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" />

但如果我连接到 javamelody 监控页面显示:“sql Statistics sql - 1 day -None”

我试过了 :

  • 在 presistence.xml 中:

    net.bull.javamelody.JpaPersistence

  • 对数据源使用包装器

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

但还是一无所获。

4

1 回答 1

4

用户指南中所述,只需添加您的 spring 上下文配置:

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

或者如果你想使用

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

然后在你的 entityManagerFactory 和 transactionManager 中替换

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

<property name="dataSource" ref="wrappedDataSource" />
于 2014-11-30T11:36:36.623 回答