0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

SpringBoot 2.1 TomcatとHikariCP設定値を確認するテストクラス

Posted at

デフォルトの設定値の確認をしたかったので、テストクラスを実行して確認する方法を調べました。

ConfigInspection.java
package com.example.demo.config;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.web.ServerProperties;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.context.ApplicationContext;
import org.springframework.test.context.junit4.SpringRunner;

import com.zaxxer.hikari.HikariConfig;

@RunWith(SpringRunner.class)
@SpringBootTest
public class ConfigInspection {

    private Logger log = LoggerFactory.getLogger(getClass());

    @Autowired
    private ApplicationContext ctx;

    @Test
    public void test() throws Exception {
        ServerProperties serverProperties = ctx.getBean(ServerProperties.class);

        ServerProperties.Tomcat tomcat = serverProperties.getTomcat();

        log.debug("tomcat.maxThreads: {}", tomcat.getMaxThreads());
        log.debug("tomcat.maxConnections: {}", tomcat.getMaxConnections());
        log.debug("tomcat.acceptCount: {}", tomcat.getAcceptCount());

        ServerProperties.Servlet servlet = serverProperties.getServlet();

        log.debug("servlet.contextPath: {}", servlet.getContextPath());

        HikariConfig hikariConfig = ctx.getBean(HikariConfig.class);

        log.debug("dataSource: {}", hikariConfig.getDataSource());
        log.debug("dataSourceProperties: {}", hikariConfig.getDataSourceProperties());
        log.debug("jdbcUrl: {}", hikariConfig.getJdbcUrl());
        log.debug("maximumPoolSize: {}", hikariConfig.getMaximumPoolSize());
    }
}

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?