Request MongoDB Queries Using Spring Boot

Is it possible to register all MongoDB requests in my Spring boot application? I tried this:

logging.level.org.springframework.data.document.mongodb=INFO
log4j.category.org.springframework.data.document.mongodb=INFO

But that did not work.

+4
source share
3 answers

This method is a little longer, but it solves a lot more . We will use the Spring Boot Admin Server tool .

  • First you need to enable some dependencies

    <!--Dependency for registering your app as a Spring Boot Admin Server-->
    <dependency>
        <groupId>de.codecentric</groupId>
        <artifactId>spring-boot-admin-server</artifactId>
        <version>1.3.3</version>
    </dependency>
    
    <!--Provide a nice looking ui-->
    <dependency>
        <groupId>de.codecentric</groupId>
        <artifactId>spring-boot-admin-server-ui</artifactId>
        <version>1.3.3</version>
    </dependency>
    
    <!--Dependency for registering your app as a Spring Boot Admin Client-->
    <dependency>
        <groupId>de.codecentric</groupId>
        <artifactId>spring-boot-admin-starter-client</artifactId>
        <version>1.3.0</version>
    </dependency>
    <dependency>
            <groupId>org.jolokia</groupId>
            <artifactId>jolokia-core</artifactId>
    </dependency>
    
  • Enable your application as a Spring boot server using annotation @EnableAdminServer.

    @SpringBootApplication
    @EnableAdminServer
    public class Application {
       public static void main(String[] args) {
          // ... your code as before ...
       }
    }
    
  • In application.propertiesadd the following:

    Register your application with Spring Boot Admin Server, which is still your application

    spring.boot.admin.url=http://localhost:8031
    

    Spring ,

    spring.boot.admin.client.service-url=http://localhost:8031
    spring.boot.admin.client.management-url=http://localhost:8031
    spring.boot.admin.client.health-url=http://localhost:8031/health
    
  • logback.xml <jmxConfigurator/>. JMX.

... voila, . .

. URL- Spring Boot Admin Server - (http:/localhost:8031).

II. () .

III. Details , .

IV. Logging, , .

v. , . ,

Change runtime logging levels

, MongoDB, MongoTemplate DEBUG.

+6

:

application.propertiese MongoRepository.

logging.level.org.springframework.data.mongodb.core.MongoTemplate=DEBUG
+1

If you are using spring boot reactive mongodb, install org.springframework.data.mongodb.core.ReactiveMongoTemplate=DEBUG

0
source

Source: https://habr.com/ru/post/1652932/


All Articles