springboot集成jooq(二)

通过继承DefaultExecuteListener创建慢查询监听

一、创建监听类

package com.zsx.listener;

import org.jooq.ExecuteContext;
import org.jooq.ExecuteType;
import org.jooq.impl.DefaultExecuteListener;
import org.jooq.tools.StopWatch;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Arrays;
import java.util.Optional;

public class SlowQueryListener extends DefaultExecuteListener {

    private static final Logger LOGGER = LoggerFactory.getLogger(SlowQueryListener.class);

    private StopWatch watch;

    @Override
    public void executeStart(ExecuteContext ctx) {
        super.executeStart(ctx);
        watch = new StopWatch();
    }

    @Override
    public void executeEnd(ExecuteContext ctx) {
        try {
            super.executeEnd(ctx);
            //记录执行时间大于1ms(1s:1_000_000_000L)的操作
            if (watch.split() <= 1_000_000L) {
                return;
            }
            ExecuteType type = ctx.type();
            StringBuffer sqlBuffer = new StringBuffer();
            if (type == ExecuteType.BATCH) {
                Arrays.stream(ctx.batchQueries()).forEach(query->sqlBuffer.append(query.toString()));
            } else {
                sqlBuffer.append(Optional.ofNullable(type).map(ExecuteType :: toString).orElse("ExecuteType is null"));
            }
            watch.splitInfo(String.format("The type of database interaction that is being executed with this context : { %s }", sqlBuffer.toString()));
        } catch (Exception e) {
            LOGGER.error(" SlowQueryListener.executeEnd.Exception ", e);
        }
    }
}

二、 测试类

package com.zsx.test.listener;

import com.zsx.entity.Accounts;
import com.zsx.listener.SlowQueryListener;
import org.jooq.Configuration;
import org.jooq.DSLContext;
import org.jooq.SQLDialect;
import org.jooq.impl.DSL;
import org.jooq.impl.DefaultConfiguration;
import org.jooq.impl.DefaultExecuteListenerProvider;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.test.context.junit.jupiter.SpringExtension;

import java.util.List;

import static com.zsx.generator.jooq.tables.Accounts.ACCOUNTS;

@SpringBootTest
@ExtendWith(SpringExtension.class)
public class SlowQueryListenerTest {

    @Autowired
    private JdbcTemplate jdbcTemplate;

    @Test
    void testQuery() {
        Configuration configuration = new DefaultConfiguration().set(SQLDialect.POSTGRES).set(jdbcTemplate.getDataSource());
        DSLContext dslContext = DSL.using(configuration.derive(DefaultExecuteListenerProvider.providers(new SlowQueryListener())));
        com.zsx.generator.jooq.tables.Accounts a = ACCOUNTS.as("a");
        List<Accounts> accountsList = dslContext.selectFrom(a).where(a.ID.eq(1L)).fetchInto(Accounts.class);
        Assertions.assertEquals(1, accountsList.size());
    }
}

三、测试结果

E:\jdk\jdk-13.0.1\bin\java.exe -ea -Didea.test.cyclic.buffer.size=1048576 "-javaagent:E:\JetBrains\IntelliJ IDEA 2019.2.3\lib\idea_rt.jar=62948:E:\JetBrains\IntelliJ IDEA 2019.2.3\bin" -Dfile.encoding=UTF-8 -classpath "E:\JetBrains\IntelliJ IDEA 2019.2.3\lib\idea_rt.jar;E:\JetBrains\IntelliJ IDEA 2019.2.3\plugins\junit\lib\junit-rt.jar;E:\JetBrains\IntelliJ IDEA 2019.2.3\plugins\junit\lib\junit5-rt.jar;F:\IdeaProjects\jooq\target\test-classes;F:\IdeaProjects\jooq\target\classes;E:\maven\repository\org\springframework\boot\spring-boot-starter-web\2.2.0.RELEASE\spring-boot-starter-web-2.2.0.RELEASE.jar;E:\maven\repository\org\springframework\boot\spring-boot-starter\2.2.0.RELEASE\spring-boot-starter-2.2.0.RELEASE.jar;E:\maven\repository\org\springframework\boot\spring-boot-starter-logging\2.2.0.RELEASE\spring-boot-starter-logging-2.2.0.RELEASE.jar;E:\maven\repository\ch\qos\logback\logback-classic\1.2.3\logback-classic-1.2.3.jar;E:\maven\repository\ch\qos\logback\logback-core\1.2.3\logback-core-1.2.3.jar;E:\maven\repository\org\apache\logging\log4j\log4j-to-slf4j\2.12.1\log4j-to-slf4j-2.12.1.jar;E:\maven\repository\org\apache\logging\log4j\log4j-api\2.12.1\log4j-api-2.12.1.jar;E:\maven\repository\org\slf4j\jul-to-slf4j\1.7.28\jul-to-slf4j-1.7.28.jar;E:\maven\repository\jakarta\annotation\jakarta.annotation-api\1.3.5\jakarta.annotation-api-1.3.5.jar;E:\maven\repository\org\yaml\snakeyaml\1.25\snakeyaml-1.25.jar;E:\maven\repository\org\springframework\boot\spring-boot-starter-json\2.2.0.RELEASE\spring-boot-starter-json-2.2.0.RELEASE.jar;E:\maven\repository\com\fasterxml\jackson\core\jackson-databind\2.10.0\jackson-databind-2.10.0.jar;E:\maven\repository\com\fasterxml\jackson\core\jackson-annotations\2.10.0\jackson-annotations-2.10.0.jar;E:\maven\repository\com\fasterxml\jackson\core\jackson-core\2.10.0\jackson-core-2.10.0.jar;E:\maven\repository\com\fasterxml\jackson\datatype\jackson-datatype-jdk8\2.10.0\jackson-datatype-jdk8-2.10.0.jar;E:\maven\repository\com\fasterxml\jackson\datatype\jackson-datatype-jsr310\2.10.0\jackson-datatype-jsr310-2.10.0.jar;E:\maven\repository\com\fasterxml\jackson\module\jackson-module-parameter-names\2.10.0\jackson-module-parameter-names-2.10.0.jar;E:\maven\repository\org\springframework\boot\spring-boot-starter-tomcat\2.2.0.RELEASE\spring-boot-starter-tomcat-2.2.0.RELEASE.jar;E:\maven\repository\org\apache\tomcat\embed\tomcat-embed-core\9.0.27\tomcat-embed-core-9.0.27.jar;E:\maven\repository\org\apache\tomcat\embed\tomcat-embed-el\9.0.27\tomcat-embed-el-9.0.27.jar;E:\maven\repository\org\apache\tomcat\embed\tomcat-embed-websocket\9.0.27\tomcat-embed-websocket-9.0.27.jar;E:\maven\repository\org\springframework\boot\spring-boot-starter-validation\2.2.0.RELEASE\spring-boot-starter-validation-2.2.0.RELEASE.jar;E:\maven\repository\jakarta\validation\jakarta.validation-api\2.0.1\jakarta.validation-api-2.0.1.jar;E:\maven\repository\org\hibernate\validator\hibernate-validator\6.0.17.Final\hibernate-validator-6.0.17.Final.jar;E:\maven\repository\org\springframework\spring-web\5.2.0.RELEASE\spring-web-5.2.0.RELEASE.jar;E:\maven\repository\org\springframework\spring-beans\5.2.0.RELEASE\spring-beans-5.2.0.RELEASE.jar;E:\maven\repository\org\springframework\spring-webmvc\5.2.0.RELEASE\spring-webmvc-5.2.0.RELEASE.jar;E:\maven\repository\org\springframework\spring-aop\5.2.0.RELEASE\spring-aop-5.2.0.RELEASE.jar;E:\maven\repository\org\springframework\spring-context\5.2.0.RELEASE\spring-context-5.2.0.RELEASE.jar;E:\maven\repository\org\springframework\spring-expression\5.2.0.RELEASE\spring-expression-5.2.0.RELEASE.jar;E:\maven\repository\org\springframework\boot\spring-boot-starter-test\2.2.0.RELEASE\spring-boot-starter-test-2.2.0.RELEASE.jar;E:\maven\repository\org\springframework\boot\spring-boot-test\2.2.0.RELEASE\spring-boot-test-2.2.0.RELEASE.jar;E:\maven\repository\org\springframework\boot\spring-boot-test-autoconfigure\2.2.0.RELEASE\spring-boot-test-autoconfigure-2.2.0.RELEASE.jar;E:\maven\repository\com\jayway\jsonpath\json-path\2.4.0\json-path-2.4.0.jar;E:\maven\repository\net\minidev\json-smart\2.3\json-smart-2.3.jar;E:\maven\repository\net\minidev\accessors-smart\1.2\accessors-smart-1.2.jar;E:\maven\repository\org\ow2\asm\asm\5.0.4\asm-5.0.4.jar;E:\maven\repository\org\slf4j\slf4j-api\1.7.28\slf4j-api-1.7.28.jar;E:\maven\repository\jakarta\xml\bind\jakarta.xml.bind-api\2.3.2\jakarta.xml.bind-api-2.3.2.jar;E:\maven\repository\org\junit\jupiter\junit-jupiter\5.5.2\junit-jupiter-5.5.2.jar;E:\maven\repository\org\junit\jupiter\junit-jupiter-params\5.5.2\junit-jupiter-params-5.5.2.jar;E:\maven\repository\org\junit\vintage\junit-vintage-engine\5.5.2\junit-vintage-engine-5.5.2.jar;E:\maven\repository\junit\junit\4.12\junit-4.12.jar;E:\maven\repository\org\mockito\mockito-junit-jupiter\3.1.0\mockito-junit-jupiter-3.1.0.jar;E:\maven\repository\org\assertj\assertj-core\3.13.2\assertj-core-3.13.2.jar;E:\maven\repository\org\hamcrest\hamcrest\2.1\hamcrest-2.1.jar;E:\maven\repository\org\mockito\mockito-core\3.1.0\mockito-core-3.1.0.jar;E:\maven\repository\net\bytebuddy\byte-buddy\1.10.1\byte-buddy-1.10.1.jar;E:\maven\repository\net\bytebuddy\byte-buddy-agent\1.10.1\byte-buddy-agent-1.10.1.jar;E:\maven\repository\org\objenesis\objenesis\2.6\objenesis-2.6.jar;E:\maven\repository\org\skyscreamer\jsonassert\1.5.0\jsonassert-1.5.0.jar;E:\maven\repository\com\vaadin\external\google\android-json\0.0.20131108.vaadin1\android-json-0.0.20131108.vaadin1.jar;E:\maven\repository\org\springframework\spring-core\5.2.0.RELEASE\spring-core-5.2.0.RELEASE.jar;E:\maven\repository\org\springframework\spring-jcl\5.2.0.RELEASE\spring-jcl-5.2.0.RELEASE.jar;E:\maven\repository\org\springframework\spring-test\5.2.0.RELEASE\spring-test-5.2.0.RELEASE.jar;E:\maven\repository\org\xmlunit\xmlunit-core\2.6.3\xmlunit-core-2.6.3.jar;E:\maven\repository\org\springframework\boot\spring-boot-starter-jooq\2.2.0.RELEASE\spring-boot-starter-jooq-2.2.0.RELEASE.jar;E:\maven\repository\org\springframework\boot\spring-boot-starter-jdbc\2.2.0.RELEASE\spring-boot-starter-jdbc-2.2.0.RELEASE.jar;E:\maven\repository\com\zaxxer\HikariCP\3.4.1\HikariCP-3.4.1.jar;E:\maven\repository\org\springframework\spring-jdbc\5.2.0.RELEASE\spring-jdbc-5.2.0.RELEASE.jar;E:\maven\repository\jakarta\activation\jakarta.activation-api\1.2.1\jakarta.activation-api-1.2.1.jar;E:\maven\repository\org\springframework\spring-tx\5.2.0.RELEASE\spring-tx-5.2.0.RELEASE.jar;E:\maven\repository\org\jooq\jooq\3.12.2\jooq-3.12.2.jar;E:\maven\repository\org\reactivestreams\reactive-streams\1.0.3\reactive-streams-1.0.3.jar;E:\maven\repository\org\springframework\boot\spring-boot-starter-data-jpa\2.2.0.RELEASE\spring-boot-starter-data-jpa-2.2.0.RELEASE.jar;E:\maven\repository\org\springframework\boot\spring-boot-starter-aop\2.2.0.RELEASE\spring-boot-starter-aop-2.2.0.RELEASE.jar;E:\maven\repository\org\aspectj\aspectjweaver\1.9.4\aspectjweaver-1.9.4.jar;E:\maven\repository\jakarta\persistence\jakarta.persistence-api\2.2.3\jakarta.persistence-api-2.2.3.jar;E:\maven\repository\jakarta\transaction\jakarta.transaction-api\1.3.3\jakarta.transaction-api-1.3.3.jar;E:\maven\repository\org\hibernate\hibernate-core\5.4.6.Final\hibernate-core-5.4.6.Final.jar;E:\maven\repository\org\jboss\logging\jboss-logging\3.4.1.Final\jboss-logging-3.4.1.Final.jar;E:\maven\repository\org\javassist\javassist\3.24.0-GA\javassist-3.24.0-GA.jar;E:\maven\repository\antlr\antlr\2.7.7\antlr-2.7.7.jar;E:\maven\repository\org\jboss\jandex\2.0.5.Final\jandex-2.0.5.Final.jar;E:\maven\repository\com\fasterxml\classmate\1.5.0\classmate-1.5.0.jar;E:\maven\repository\org\dom4j\dom4j\2.1.1\dom4j-2.1.1.jar;E:\maven\repository\org\hibernate\common\hibernate-commons-annotations\5.1.0.Final\hibernate-commons-annotations-5.1.0.Final.jar;E:\maven\repository\org\glassfish\jaxb\jaxb-runtime\2.3.2\jaxb-runtime-2.3.2.jar;E:\maven\repository\org\jvnet\staxex\stax-ex\1.8.1\stax-ex-1.8.1.jar;E:\maven\repository\com\sun\xml\fastinfoset\FastInfoset\1.2.16\FastInfoset-1.2.16.jar;E:\maven\repository\org\springframework\data\spring-data-jpa\2.2.0.RELEASE\spring-data-jpa-2.2.0.RELEASE.jar;E:\maven\repository\org\springframework\data\spring-data-commons\2.2.0.RELEASE\spring-data-commons-2.2.0.RELEASE.jar;E:\maven\repository\org\springframework\spring-orm\5.2.0.RELEASE\spring-orm-5.2.0.RELEASE.jar;E:\maven\repository\org\springframework\spring-aspects\5.2.0.RELEASE\spring-aspects-5.2.0.RELEASE.jar;E:\maven\repository\org\jooq\jooq-meta\3.12.2\jooq-meta-3.12.2.jar;E:\maven\repository\org\jooq\jooq-codegen\3.12.2\jooq-codegen-3.12.2.jar;E:\maven\repository\org\flywaydb\flyway-core\6.0.7\flyway-core-6.0.7.jar;E:\maven\repository\org\postgresql\postgresql\42.2.8\postgresql-42.2.8.jar;E:\maven\repository\org\glassfish\jaxb\jaxb-core\2.3.0.1\jaxb-core-2.3.0.1.jar;E:\maven\repository\javax\xml\bind\jaxb-api\2.3.1\jaxb-api-2.3.1.jar;E:\maven\repository\javax\activation\javax.activation-api\1.2.0\javax.activation-api-1.2.0.jar;E:\maven\repository\org\glassfish\jaxb\txw2\2.3.2\txw2-2.3.2.jar;E:\maven\repository\com\sun\istack\istack-commons-runtime\3.0.5\istack-commons-runtime-3.0.5.jar;E:\maven\repository\com\sun\xml\bind\jaxb-impl\2.3.2\jaxb-impl-2.3.2.jar;E:\maven\repository\org\projectlombok\lombok\1.18.10\lombok-1.18.10.jar;E:\maven\repository\org\junit\platform\junit-platform-launcher\1.5.2\junit-platform-launcher-1.5.2.jar;E:\maven\repository\org\apiguardian\apiguardian-api\1.1.0\apiguardian-api-1.1.0.jar;E:\maven\repository\org\junit\platform\junit-platform-engine\1.5.2\junit-platform-engine-1.5.2.jar;E:\maven\repository\org\opentest4j\opentest4j\1.2.0\opentest4j-1.2.0.jar;E:\maven\repository\org\junit\platform\junit-platform-commons\1.5.2\junit-platform-commons-1.5.2.jar;E:\maven\repository\org\junit\jupiter\junit-jupiter-engine\5.5.2\junit-jupiter-engine-5.5.2.jar;E:\maven\repository\org\junit\jupiter\junit-jupiter-api\5.5.2\junit-jupiter-api-5.5.2.jar;E:\maven\repository\org\springframework\boot\spring-boot-devtools\2.2.0.RELEASE\spring-boot-devtools-2.2.0.RELEASE.jar;E:\maven\repository\org\springframework\boot\spring-boot\2.2.0.RELEASE\spring-boot-2.2.0.RELEASE.jar;E:\maven\repository\org\springframework\boot\spring-boot-autoconfigure\2.2.0.RELEASE\spring-boot-autoconfigure-2.2.0.RELEASE.jar" com.intellij.rt.execution.junit.JUnitStarter -ideVersion5 -junit5 com.zsx.test.listener.SlowQueryListenerTest,testQuery
18:22:49.388 [main] DEBUG org.springframework.test.context.BootstrapUtils - Instantiating CacheAwareContextLoaderDelegate from class [org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate]
18:22:49.403 [main] DEBUG org.springframework.test.context.BootstrapUtils - Instantiating BootstrapContext using constructor [public org.springframework.test.context.support.DefaultBootstrapContext(java.lang.Class,org.springframework.test.context.CacheAwareContextLoaderDelegate)]
18:22:49.423 [main] DEBUG org.springframework.test.context.BootstrapUtils - Instantiating TestContextBootstrapper for test class [com.zsx.test.listener.SlowQueryListenerTest] from class [org.springframework.boot.test.context.SpringBootTestContextBootstrapper]
18:22:49.434 [main] INFO org.springframework.boot.test.context.SpringBootTestContextBootstrapper - Neither @ContextConfiguration nor @ContextHierarchy found for test class [com.zsx.test.listener.SlowQueryListenerTest], using SpringBootContextLoader
18:22:49.438 [main] DEBUG org.springframework.test.context.support.AbstractContextLoader - Did not detect default resource location for test class [com.zsx.test.listener.SlowQueryListenerTest]: class path resource [com/zsx/test/listener/SlowQueryListenerTest-context.xml] does not exist
18:22:49.439 [main] DEBUG org.springframework.test.context.support.AbstractContextLoader - Did not detect default resource location for test class [com.zsx.test.listener.SlowQueryListenerTest]: class path resource [com/zsx/test/listener/SlowQueryListenerTestContext.groovy] does not exist
18:22:49.439 [main] INFO org.springframework.test.context.support.AbstractContextLoader - Could not detect default resource locations for test class [com.zsx.test.listener.SlowQueryListenerTest]: no resource found for suffixes {-context.xml, Context.groovy}.
18:22:49.439 [main] INFO org.springframework.test.context.support.AnnotationConfigContextLoaderUtils - Could not detect default configuration classes for test class [com.zsx.test.listener.SlowQueryListenerTest]: SlowQueryListenerTest does not declare any static, non-private, non-final, nested classes annotated with @Configuration.
18:22:49.465 [main] DEBUG org.springframework.test.context.support.ActiveProfilesUtils - Could not find an 'annotation declaring class' for annotation type [org.springframework.test.context.ActiveProfiles] and class [com.zsx.test.listener.SlowQueryListenerTest]
18:22:49.512 [main] DEBUG org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider - Identified candidate component class: file [F:\IdeaProjects\jooq\target\classes\com\zsx\JooqApplication.class]
18:22:49.513 [main] INFO org.springframework.boot.test.context.SpringBootTestContextBootstrapper - Found @SpringBootConfiguration com.zsx.JooqApplication for test class com.zsx.test.listener.SlowQueryListenerTest
18:22:49.574 [main] DEBUG org.springframework.boot.test.context.SpringBootTestContextBootstrapper - @TestExecutionListeners is not present for class [com.zsx.test.listener.SlowQueryListenerTest]: using defaults.
18:22:49.575 [main] INFO org.springframework.boot.test.context.SpringBootTestContextBootstrapper - Loaded default TestExecutionListener class names from location [META-INF/spring.factories]: [org.springframework.boot.test.mock.mockito.MockitoTestExecutionListener, org.springframework.boot.test.mock.mockito.ResetMocksTestExecutionListener, org.springframework.boot.test.autoconfigure.restdocs.RestDocsTestExecutionListener, org.springframework.boot.test.autoconfigure.web.client.MockRestServiceServerResetTestExecutionListener, org.springframework.boot.test.autoconfigure.web.servlet.MockMvcPrintOnlyOnFailureTestExecutionListener, org.springframework.boot.test.autoconfigure.web.servlet.WebDriverTestExecutionListener, org.springframework.test.context.web.ServletTestExecutionListener, org.springframework.test.context.support.DirtiesContextBeforeModesTestExecutionListener, org.springframework.test.context.support.DependencyInjectionTestExecutionListener, org.springframework.test.context.support.DirtiesContextTestExecutionListener, org.springframework.test.context.transaction.TransactionalTestExecutionListener, org.springframework.test.context.jdbc.SqlScriptsTestExecutionListener, org.springframework.test.context.event.EventPublishingTestExecutionListener]
18:22:49.586 [main] INFO org.springframework.boot.test.context.SpringBootTestContextBootstrapper - Using TestExecutionListeners: [org.springframework.test.context.web.ServletTestExecutionListener@2931522b, org.springframework.test.context.support.DirtiesContextBeforeModesTestExecutionListener@7674b62c, org.springframework.boot.test.mock.mockito.MockitoTestExecutionListener@19e7a160, org.springframework.boot.test.autoconfigure.SpringBootDependencyInjectionTestExecutionListener@662706a7, org.springframework.test.context.support.DirtiesContextTestExecutionListener@45a4b042, org.springframework.test.context.transaction.TransactionalTestExecutionListener@16b2bb0c, org.springframework.test.context.jdbc.SqlScriptsTestExecutionListener@327af41b, org.springframework.test.context.event.EventPublishingTestExecutionListener@6cb6decd, org.springframework.boot.test.mock.mockito.ResetMocksTestExecutionListener@c7045b9, org.springframework.boot.test.autoconfigure.restdocs.RestDocsTestExecutionListener@f99f5e0, org.springframework.boot.test.autoconfigure.web.client.MockRestServiceServerResetTestExecutionListener@6aa61224, org.springframework.boot.test.autoconfigure.web.servlet.MockMvcPrintOnlyOnFailureTestExecutionListener@30bce90b, org.springframework.boot.test.autoconfigure.web.servlet.WebDriverTestExecutionListener@3e6f3f28]
18:22:49.589 [main] DEBUG org.springframework.test.context.support.AbstractDirtiesContextTestExecutionListener - Before test class: context [DefaultTestContext@11f0a5a1 testClass = SlowQueryListenerTest, testInstance = [null], testMethod = [null], testException = [null], mergedContextConfiguration = [WebMergedContextConfiguration@10f7f7de testClass = SlowQueryListenerTest, locations = '{}', classes = '{class com.zsx.JooqApplication}', contextInitializerClasses = '[]', activeProfiles = '{}', propertySourceLocations = '{}', propertySourceProperties = '{org.springframework.boot.test.context.SpringBootTestContextBootstrapper=true}', contextCustomizers = set[org.springframework.boot.test.context.filter.ExcludeFilterContextCustomizer@306cf3ea, org.springframework.boot.test.json.DuplicateJsonObjectContextCustomizerFactory$DuplicateJsonObjectContextCustomizer@5939a379, org.springframework.boot.test.mock.mockito.MockitoContextCustomizer@0, org.springframework.boot.test.web.client.TestRestTemplateContextCustomizer@140c9f39, org.springframework.boot.test.autoconfigure.properties.PropertyMappingContextCustomizer@0, org.springframework.boot.test.autoconfigure.web.servlet.WebDriverContextCustomizerFactory$Customizer@4944252c], resourceBasePath = 'src/main/webapp', contextLoader = 'org.springframework.boot.test.context.SpringBootContextLoader', parent = [null]], attributes = map['org.springframework.test.context.web.ServletTestExecutionListener.activateListener' -> true]], class annotated with @DirtiesContext [false] with mode [null].
18:22:49.616 [main] DEBUG org.springframework.test.context.support.TestPropertySourceUtils - Adding inlined properties to environment: {spring.jmx.enabled=false, org.springframework.boot.test.context.SpringBootTestContextBootstrapper=true, server.port=-1}

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::        (v2.2.0.RELEASE)

2019-11-20 18:22:49.908  INFO 14088 --- [           main] c.z.test.listener.SlowQueryListenerTest  : Starting SlowQueryListenerTest on DESKTOP-I29QKRP with PID 14088 (started by 18273 in F:\IdeaProjects\jooq)
2019-11-20 18:22:49.909  INFO 14088 --- [           main] c.z.test.listener.SlowQueryListenerTest  : No active profile set, falling back to default profiles: default
2019-11-20 18:22:50.349  INFO 14088 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data repositories in DEFAULT mode.
2019-11-20 18:22:50.375  INFO 14088 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 20ms. Found 0 repository interfaces.
2019-11-20 18:22:50.671  INFO 14088 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration' of type [org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2019-11-20 18:22:50.795  INFO 14088 --- [           main] o.f.c.internal.license.VersionPrinter    : Flyway Community Edition 6.0.7 by Redgate
2019-11-20 18:22:50.799  WARN 14088 --- [           main] com.zaxxer.hikari.HikariConfig           : HikariPool-1 - idleTimeout has been set but has no effect because the pool is operating as a fixed size pool.
2019-11-20 18:22:50.799  INFO 14088 --- [           main] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Starting...
2019-11-20 18:22:50.873  INFO 14088 --- [           main] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Start completed.
2019-11-20 18:22:50.892  INFO 14088 --- [           main] o.f.c.internal.database.DatabaseFactory  : Database: jdbc:postgresql://127.0.0.1:5432/mydb11 (PostgreSQL 12.0)
2019-11-20 18:22:50.912  INFO 14088 --- [           main] o.f.core.internal.command.DbValidate     : Successfully validated 2 migrations (execution time 00:00.011s)
2019-11-20 18:22:50.917  INFO 14088 --- [           main] o.f.core.internal.command.DbMigrate      : Current version of schema "jooq": 1
2019-11-20 18:22:50.917  INFO 14088 --- [           main] o.f.core.internal.command.DbMigrate      : Schema "jooq" is up to date. No migration necessary.
2019-11-20 18:22:51.020  INFO 14088 --- [           main] o.hibernate.jpa.internal.util.LogHelper  : HHH000204: Processing PersistenceUnitInfo [name: default]
2019-11-20 18:22:51.071  INFO 14088 --- [           main] org.hibernate.Version                    : HHH000412: Hibernate Core {5.4.6.Final}
2019-11-20 18:22:51.170  INFO 14088 --- [           main] o.hibernate.annotations.common.Version   : HCANN000001: Hibernate Commons Annotations {5.1.0.Final}
2019-11-20 18:22:51.403  INFO 14088 --- [           main] org.hibernate.dialect.Dialect            : HHH000400: Using dialect: org.hibernate.dialect.PostgreSQL10Dialect
2019-11-20 18:22:51.545  INFO 14088 --- [           main] o.h.e.t.j.p.i.JtaPlatformInitiator       : HHH000490: Using JtaPlatform implementation: [org.hibernate.engine.transaction.jta.platform.internal.NoJtaPlatform]
2019-11-20 18:22:51.554  INFO 14088 --- [           main] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'
2019-11-20 18:22:51.703  WARN 14088 --- [           main] JpaBaseConfiguration$JpaWebConfiguration : spring.jpa.open-in-view is enabled by default. Therefore, database queries may be performed during view rendering. Explicitly configure spring.jpa.open-in-view to disable this warning
2019-11-20 18:22:51.852  INFO 14088 --- [           main] o.s.s.concurrent.ThreadPoolTaskExecutor  : Initializing ExecutorService 'applicationTaskExecutor'
2019-11-20 18:22:52.283  INFO 14088 --- [           main] c.z.test.listener.SlowQueryListenerTest  : Started SlowQueryListenerTest in 2.66 seconds (JVM running for 3.308)

WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by org.jooq.tools.reflect.Reflect (file:/E:/maven/repository/org/jooq/jooq/3.12.2/jooq-3.12.2.jar) to constructor java.lang.invoke.MethodHandles$Lookup(java.lang.Class)
WARNING: Please consider reporting this to the maintainers of org.jooq.tools.reflect.Reflect
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
2019-11-20 18:22:52.669 DEBUG 14088 --- [           main] org.jooq.tools.LoggerListener            : Executing query          : select "a"."id", "a"."account_owner", "a"."account_name", "a"."amount", "a"."deleted" from "jooq"."accounts" as "a" where "a"."id" = ?
2019-11-20 18:22:52.670 DEBUG 14088 --- [           main] org.jooq.tools.LoggerListener            : -> with bind values      : select "a"."id", "a"."account_owner", "a"."account_name", "a"."amount", "a"."deleted" from "jooq"."accounts" as "a" where "a"."id" = 1
2019-11-20 18:22:52.676  INFO 14088 --- [           main] org.jooq.tools.StopWatch                 : The type of database interaction that is being executed with this context : { READ }: Total: 2.096ms
2019-11-20 18:22:52.694 DEBUG 14088 --- [           main] org.jooq.tools.LoggerListener            : Fetched result           : +----+-------------+------------+------+-------+
2019-11-20 18:22:52.695 DEBUG 14088 --- [           main] org.jooq.tools.LoggerListener            :                          : |  id|account_owner|account_name|amount|deleted|
2019-11-20 18:22:52.695 DEBUG 14088 --- [           main] org.jooq.tools.LoggerListener            :                          : +----+-------------+------------+------+-------+
2019-11-20 18:22:52.695 DEBUG 14088 --- [           main] org.jooq.tools.LoggerListener            :                          : |   1|John         |savings     |500.00|false  |
2019-11-20 18:22:52.695 DEBUG 14088 --- [           main] org.jooq.tools.LoggerListener            :                          : +----+-------------+------------+------+-------+
2019-11-20 18:22:52.695 DEBUG 14088 --- [           main] org.jooq.tools.LoggerListener            : Fetched row(s)           : 1

2019-11-20 18:22:52.720  INFO 14088 --- [extShutdownHook] o.s.s.concurrent.ThreadPoolTaskExecutor  : Shutting down ExecutorService 'applicationTaskExecutor'
2019-11-20 18:22:52.721  INFO 14088 --- [extShutdownHook] j.LocalContainerEntityManagerFactoryBean : Closing JPA EntityManagerFactory for persistence unit 'default'
2019-11-20 18:22:52.723  INFO 14088 --- [extShutdownHook] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Shutdown initiated...
2019-11-20 18:22:52.733  INFO 14088 --- [extShutdownHook] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Shutdown completed.

Process finished with exit code 0

 

到此慢查询监听成功

发布了129 篇原创文章 · 获赞 14 · 访问量 4万+

猜你喜欢

转载自blog.csdn.net/zsx18273117003/article/details/103168218