SpringBootStarter

evernat edited this page Sep 4, 2018 · 36 revisions

The JavaMelody Spring Boot Starter facilitates the integration of JavaMelody in Spring Boot web applications.

Integration

See the example project for a demonstration.

To integrate JavaMelody in a Spring Boot app, simply add the following dependency to your Maven pom.xml:

<dependency>
	<groupId>net.bull.javamelody</groupId>
	<artifactId>javamelody-spring-boot-starter</artifactId>
	<version>1.74.0</version>
</dependency>

Then you can run your spring-boot application and open http://localhost:8080/monitoring to browse the monitoring reports.

Optionally, add the iText 2.1.7 dependency in your pom.xml if you want to use PDF exports.

Spring beans having an annotation @Controller, @RestController, @Service, and RestTemplate defined as bean, and since v1.68, beans and methods having an annotation @Async are automatically monitored. Otherwise, if you want to monitor method calls on some Spring beans, you can add @MonitoredWithSpring on those classes or methods.

If your application can't start because of auto-proxy issues, such as The bean could not be injected as ..., add the following in your application.xml:

javamelody:
  advisor-auto-proxy-creator-enabled: false

and add the following dependency in your pom.xml:

<dependency>
	<groupId>org.springframework.boot</groupId>
	<artifactId>spring-boot-starter-aop</artifactId>
</dependency>

Configuration

If you want, you can configure other settings by using configuration properties prefixed with javamelody in your application.yml or application.properties.

Example for application.yml:

javamelody:
  # Enable JavaMelody auto-configuration (optional, default: true)
  enabled: true
  # Data source names to exclude from monitoring (optional, comma-separated)
  excluded-datasources: secretSource,topSecretSource
  # Enable monitoring of Spring services and controllers (optional, default: true)
  spring-monitoring-enabled: true
  # Initialization parameters for JavaMelody (optional)
  # See: https://github.com/javamelody/javamelody/wiki/UserGuide#6-optional-parameters
  init-parameters:
    # log http requests:
    log: true
    # to exclude images, css, fonts and js urls from the monitoring:
    #url-exclude-pattern: (/webjars/.*|/css/.*|/images/.*|/fonts/.*|/js/.*)
    # to aggregate digits in http requests:
    #http-transform-pattern: \d+
    # to add basic auth:
    #authorized-users: admin:pwd
    # to change the default storage directory:
    #storage-directory: /tmp/javamelody
    # to change the default "/monitoring" path:
    #monitoring-path: /admin/performance

Example for application.properties:

# Enable JavaMelody auto-configuration (optional, default: true)
javamelody.enabled=true
# Data source names to exclude from monitoring (optional, comma-separated)
javamelody.excluded-datasources=secretSource,topSecretSource
# Enable monitoring of Spring services and controllers (optional, default: true)
javamelody.spring-monitoring-enabled=true
# Initialization parameters for JavaMelody (optional)
# See: https://github.com/javamelody/javamelody/wiki/UserGuide#6-optional-parameters
#    log http requests:
javamelody.init-parameters.log=true
#    to exclude images, css, fonts and js urls from the monitoring:
# javamelody.init-parameters.url-exclude-pattern=(/webjars/.*|/css/.*|/images/.*|/fonts/.*|/js/.*)
#    to aggregate digits in http requests:
# javamelody.init-parameters.http-transform-pattern: \d+
#    to add basic auth:
# javamelody.init-parameters.authorized-users=admin:pwd
#    to change the default storage directory:
# javamelody.init-parameters.storage-directory=/tmp/javamelody
#    to change the default "/monitoring" path:
# javamelody.init-parameters.monitoring-path=/admin/performance

To enable the monitoring of methods annotated with @Scheduled or @Schedules:

  1. add the following in your application.yml:
javamelody:
  advisor-auto-proxy-creator-enabled: false
  scheduled-monitoring-enabled: true
  1. add a dependency on aop in your pom.xml:
<dependency>
	<groupId>org.springframework.boot</groupId>
	<artifactId>spring-boot-starter-aop</artifactId>
</dependency>

Or integration without the Spring Boot Starter

You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.