Affichage des articles dont le libellé est spring. Afficher tous les articles
Affichage des articles dont le libellé est spring. Afficher tous les articles

mercredi 15 juin 2011

Configuration d'une application Java/Spring/Hibernate pour utiliser JavaMelody

Ceci est un petit résumé...
  • Monitoring SQL, sans Datasource :
- modifier le driver :
hibernate.connection.driver_class : net.bull.javamelody.JdbcDriver
hibernate.connection.driver : oracle.jdbc.driver.OracleDriver
  • Monitoring des Services (les @Service) :
- rajouter l'interface Monitored dans le package com.toto

- rajouter "implements Monitored" sur les classes des services que l'on souhaite monitorer

- rajouter dans applicationContext.xml :

<bean id="facadeMonitoringAdvisor" class="net.bull.javamelody.MonitoringSpringAdvisor">
    <property name="pointcut">
            <bean class="net.bull.javamelody.MonitoredWithInterfacePointcut">
                 <property name="interfaceName" value="com.toto.Monitored" />
            </bean>
        </property>
</bean>



PS : on peut aussi le faire avec @net.bull.javamelody.MonitoredWithSpring à la place de l'interface... 
pour plus d'infos : doc de JavaMelody


  • Configuration diverse:
- rajouter dans web.xml :

<context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>
            classpath:net/bull/javamelody/monitoring-spring.xml
            classpath:applicationContext*.xml
        </param-value>
</context-param>

<filter>
         <filter-name>monitoring</filter-name>
         <filter-class>net.bull.javamelody.MonitoringFilter</filter-class>
</filter>
<filter-mapping>
         <filter-name>monitoring</filter-name>
         <url-pattern>/monitoring</url-pattern>
</filter-mapping>
 
<listener>
         <listener-class>net.bull.javamelody.SessionListener</listener-class>
</listener>


- rajouter dans pom.xml :

<dependency>
            <groupId>net.bull</groupId>
            <artifactId>javamelody</artifactId>
            <version>1.29.0</version>
</dependency>
<dependency>
            <groupId>org</groupId>
            <artifactId>jrobin</artifactId>
            <version>1.5.9.1</version>
</dependency>  



  • Si jamais vous avez un message du genre "dépendance cyclique" (en gros un service A fait référence à un service B qui fait référence au A) :
- créer la classe AllowRawInjectionDespiteWrappingXMLWebApplicationContext :

package com.toto.utils.spring;

import java.io.IOException;

import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.web.context.support.XmlWebApplicationContext;

public class AllowRawInjectionDespiteWrappingXMLWebApplicationContext extends XmlWebApplicationContext {

  @Override
  protected void loadBeanDefinitions(DefaultListableBeanFactory beanFactory) throws IOException {
    beanFactory.setAllowRawInjectionDespiteWrapping(true);
    super.loadBeanDefinitions(beanFactory);
  }
}


- rajouter dans web.xml :
<context-param>
        <param-name>contextClass</param-name>
        <param-value>com.toto.utils.spring.AllowRawInjectionDespiteWrappingXMLWebApplicationContext</param-value>
    </context-param>


    

Categories