{"id":1064,"date":"2019-07-08T21:22:24","date_gmt":"2019-07-08T12:22:24","guid":{"rendered":"https:\/\/ito-u-oti.com\/?p=1064"},"modified":"2019-07-08T21:22:26","modified_gmt":"2019-07-08T12:22:26","slug":"post-1064","status":"publish","type":"post","link":"https:\/\/ito-u-oti.com\/?p=1064","title":{"rendered":"\u3010Spring Boot\u3011\u3010MyBatis\u3011SQL\u5b9f\u884c\u6642\u306elogging\u51fa\u529b\u8a2d\u5b9a\uff08\u4e00\u756a\u304a\u624b\u8efd\u306a\u3084\u3064\uff09"},"content":{"rendered":"\n<p>spring framework\u3067mybatis\u3092\u4f7f\u3063\u3066\u3044\u305f\u6642\u306flog4j\u3084\u3089logback\u306e\u8a2d\u5b9a\u3084\u3089\u3092\u30b4\u30ea\u30b4\u30ea\u8a18\u8ff0\u3057\u3066\u30ed\u30b0\u3092\u51fa\u3057\u3066\u3044\u305f\u3051\u3069\u3001<br>Spring boot\u3067mybatis\u3092\u4f7f\u7528\u3059\u308b\u6642\u306f\u30c7\u30d5\u30a9\u30eb\u30c8\u3067logging\u6a5f\u80fd\u304c\u3064\u3044\u3066\u3044\u308b\u3089\u3057\u304f\u3001\u3068\u3066\u3082\u304a\u624b\u8efd\u306bSQL\u306e\u30ed\u30b0\u3092\u51fa\u529b\u3059\u308b\u3053\u3068\u304c\u51fa\u6765\u307e\u3057\u305f\u3002<br>\u7d50\u8ad6\u306f\u3001application.properties\u307e\u305f\u306fapplication.yml\u306blogging\u8a2d\u5b9a\u3092\u8ffd\u8a18\u3059\u308b\u3060\u3051\u3067\u3059\u3002<\/p>\n\n\n\n<h2 id=\"outline__1\" class=\"wp-block-heading\">\u5b9f\u9a13\u5bfe\u8c61\u306eAP<\/h2>\n\n\n\n<h3 id=\"outline__1_1\" class=\"wp-block-heading\">\u8a2d\u5b9a<\/h3>\n\n\n\n<h4 id=\"outline__1_1_1\" class=\"wp-block-heading\">pom.xml<\/h4>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: xml; title: ; notranslate\" title=\"\">\n&lt;dependency&gt;\n    &lt;groupId&gt;org.mybatis.spring.boot&lt;\/groupId&gt;\n    &lt;artifactId&gt;mybatis-spring-boot-starter&lt;\/artifactId&gt;\n&lt;\/dependency&gt;\n<\/pre><\/div>\n\n\n<p>springBoot\u3067mybatis\u3092\u4f7f\u7528\u3059\u308b\u30d7\u30e9\u30b0\u30a4\u30f3\u3092\u4f7f\u3044\u307e\u3059\u3002<br>\u3053\u3053\u306b\u30c7\u30d5\u30a9\u30eb\u30c8\u3067logging\u6a5f\u80fd\u304c\u5099\u308f\u3063\u3066\u3044\u307e\u3059\u3002<br>\u306a\u306e\u3067\u3001\u300c\u3068\u306b\u304b\u304fSQL\u30ed\u30b0\u3092\u51fa\u3057\u305f\u3044\u300d\u3068\u3044\u3046\u5206\u306b\u306f<br>sl4j\u3084\u3089log4j\u3084\u3089logback\u306e\u8a2d\u5b9a\u306f\u884c\u308f\u306a\u304f\u3066\u3044\u3044\u3067\u3059\u3002<\/p>\n\n\n\n<h4 id=\"outline__1_1_2\" class=\"wp-block-heading\">application.yml(logging\u9069\u7528\u524d)<\/h4>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nspring:\n  datasource:\n    url: jdbc:postgresql:\/\/XXX.XXX.X.X:5432\/databaseName\n    username: postgres\n    password: postgres\n    driver-class-name: org.postgresql.Driver\n<\/pre><\/div>\n\n\n<p>datasource\u8a2d\u5b9a\u3057\u304b\u3057\u3066\u307e\u305b\u3093\u3002<\/p>\n\n\n\n<h3 id=\"outline__1_2\" class=\"wp-block-heading\">AP<\/h3>\n\n\n\n<p>SQL\u3092\u4f7f\u3046\u30e1\u30a4\u30f3\u306eMapper\u8a2d\u5b9a\u3067\u3059\u3002<\/p>\n\n\n\n<h4 id=\"outline__1_2_1\" class=\"wp-block-heading\">DemoMapperXml.java<\/h4>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: java; title: ; notranslate\" title=\"\">\npackage com.example.demo.repository;\n\nimport org.apache.ibatis.annotations.Mapper;\nimport org.apache.ibatis.annotations.Param;\n\nimport com.example.demo.entity.Country;\n\n@Mapper\npublic interface DemoMapperXml {\n\n    Country selectCountry(@Param(&quot;id&quot;) Integer id);\n\n}\n<\/pre><\/div>\n\n\n<p>\u5b9f\u969b\u306eSQL\u306fxml\u306b\u8a18\u8f09\u3057\u3066\u3042\u308a\u307e\u3059\u3002<\/p>\n\n\n\n<h4 id=\"outline__1_2_2\" class=\"wp-block-heading\">DemoMapperXmlTest.java<\/h4>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: java; title: ; notranslate\" title=\"\">\npackage com.example.demo.repository;\n\nimport static org.assertj.core.api.Assertions.assertThat;\n\nimport org.junit.jupiter.api.AfterEach;\nimport org.junit.jupiter.api.BeforeEach;\nimport org.junit.jupiter.api.Test;\nimport org.springframework.beans.factory.annotation.Autowired;\nimport org.springframework.boot.test.context.SpringBootTest;\n\nimport com.example.demo.entity.Country;\n\n@SpringBootTest\npublic class DemoMapperXmlTest {\n\n    @Autowired\n    DemoMapperXml target;\n    \n    @Test\n    void wiringCountryXmlTest() {\n\n        \/\/ action\n        Country act = target.selectCountry(87);\n\n        \/\/ assert\n        assertThat(act).isNotNull();\n\n    }\n}\n<\/pre><\/div>\n\n\n<h3 id=\"outline__1_3\" class=\"wp-block-heading\">\u30c6\u30b9\u30c8\u5b9f\u884c\u7d50\u679c<\/h3>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n21:12:16.383 &#x5B;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}\n\n  .   ____          _            __ _ _\n \/\\\\ \/ ___'_ __ _ _(_)_ __  __ _ \\ \\ \\ \\\n( ( )\\___ | '_ | '_| | '_ \\\/ _` | \\ \\ \\ \\\n \\\\\/  ___)| |_)| | | | | || (_| |  ) ) ) )\n  '  |____| .__|_| |_|_| |_\\__, | \/ \/ \/ \/\n =========|_|==============|___\/=\/_\/_\/_\/\n :: Spring Boot ::        (v2.1.3.RELEASE)\n\n2019-07-08 21:12:16.596  INFO 11512 --- &#x5B;           main] c.e.demo.repository.DemoMapperXmlTest    : Starting DemoMapperXmlTest on DESKTOP-V67CH51 with PID 11512 (started by white sleipnir in F:\\github\\itouoti\\Spring_Boot\\mybatis_nestMapper)\n2019-07-08 21:12:16.597  INFO 11512 --- &#x5B;           main] c.e.demo.repository.DemoMapperXmlTest    : No active profile set, falling back to default profiles: default\n2019-07-08 21:12:17.699  INFO 11512 --- &#x5B;           main] o.s.s.concurrent.ThreadPoolTaskExecutor  : Initializing ExecutorService 'applicationTaskExecutor'\n2019-07-08 21:12:17.916  INFO 11512 --- &#x5B;           main] o.s.b.a.w.s.WelcomePageHandlerMapping    : Adding welcome page template: index\n2019-07-08 21:12:18.279  INFO 11512 --- &#x5B;           main] c.e.demo.repository.DemoMapperXmlTest    : Started DemoMapperXmlTest in 1.888 seconds (JVM running for 2.675)\n2019-07-08 21:12:18.479  INFO 11512 --- &#x5B;           main] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Starting...\n2019-07-08 21:12:18.604  INFO 11512 --- &#x5B;           main] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Start completed.\n2019-07-08 21:12:18.689  INFO 11512 --- &#x5B;       Thread-2] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Shutdown initiated...\n2019-07-08 21:12:18.690  INFO 11512 --- &#x5B;       Thread-2] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Shutdown completed.\n2019-07-08 21:12:18.690  INFO 11512 --- &#x5B;       Thread-2] o.s.s.concurrent.ThreadPoolTaskExecutor  : Shutting down ExecutorService 'applicationTaskExecutor'\n\nProcess finished with exit code 0\n<\/pre><\/div>\n\n\n<p>\u3053\u3093\u306a\u611f\u3058\u3067SQL\u306e\u7d50\u679c\u306f\u51fa\u307e\u305b\u3093\u3002<\/p>\n\n\n\n<h2 id=\"outline__2\" class=\"wp-block-heading\">SQL\u3092\u30b3\u30f3\u30bd\u30fc\u30eb\u306b\u51fa\u529b\u3059\u308b\u8a2d\u5b9a<\/h2>\n\n\n\n<h3 id=\"outline__2_1\" class=\"wp-block-heading\">application.yml(\u4fee\u6b63\u5f8c)<\/h3>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nspring:\n  datasource:\n    url: jdbc:postgresql:\/\/xxx.xxx.x.x:5432\/databaseName\n    username: postgres\n    password: postgres\n    driver-class-name: org.postgresql.Driver\n\nlogging:\n  level:\n    org:\n      springframework: WARN\n    com:\n      example:\n        demo:\n          repository:\n            DemoMapperXml: DEBUG\n<\/pre><\/div>\n\n\n<p>DemoMapperXml.java\u306e\u5b9f\u884c\u6642\u306bSQL\u3092\u51fa\u529b\u3055\u305b\u308b\u3088\u3046\u306b\u8a2d\u5b9a\u3092\u5909\u66f4\u3057\u307e\u3057\u305f\u3002<br>\u307e\u305f\u3001\u30d1\u30c3\u30b1\u30fc\u30b8\u5358\u4f4d\u3067SQL\u3092\u51fa\u529b\u3055\u305b\u305f\u3044\u3068\u304d\u306f\u3001\u30d1\u30c3\u30b1\u30fc\u30b8\u306b\u5bfe\u3057\u3066\u30ed\u30b0\u51fa\u529b\u306e\u8a2d\u5b9a\u3092\u884c\u3048\u3070OK\u3067\u3059\u3002<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nlogging:\n  level:\n    org:\n      springframework: WARN\n    com:\n      example:\n        demo:\n          repository: DEBUG\n<\/pre><\/div>\n\n\n<h3 id=\"outline__2_2\" class=\"wp-block-heading\">\u5b9f\u884c\u7d50\u679c<\/h3>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n21:17:54.075 &#x5B;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}\n\n  .   ____          _            __ _ _\n \/\\\\ \/ ___'_ __ _ _(_)_ __  __ _ \\ \\ \\ \\\n( ( )\\___ | '_ | '_| | '_ \\\/ _` | \\ \\ \\ \\\n \\\\\/  ___)| |_)| | | | | || (_| |  ) ) ) )\n  '  |____| .__|_| |_|_| |_\\__, | \/ \/ \/ \/\n =========|_|==============|___\/=\/_\/_\/_\/\n :: Spring Boot ::        (v2.1.3.RELEASE)\n\n2019-07-08 21:17:54.351  INFO 7840 --- &#x5B;           main] c.e.demo.repository.DemoMapperXmlTest    : Starting DemoMapperXmlTest on DESKTOP-V67CH51 with PID 7840 (started by white sleipnir in F:\\github\\itouoti\\Spring_Boot\\mybatis_nestMapper)\n2019-07-08 21:17:54.352 DEBUG 7840 --- &#x5B;           main] c.e.demo.repository.DemoMapperXmlTest    : Running with Spring Boot v2.1.3.RELEASE, Spring v5.1.5.RELEASE\n2019-07-08 21:17:54.352  INFO 7840 --- &#x5B;           main] c.e.demo.repository.DemoMapperXmlTest    : No active profile set, falling back to default profiles: default\n2019-07-08 21:17:56.082  INFO 7840 --- &#x5B;           main] c.e.demo.repository.DemoMapperXmlTest    : Started DemoMapperXmlTest in 1.997 seconds (JVM running for 2.817)\n2019-07-08 21:17:56.237  INFO 7840 --- &#x5B;           main] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Starting...\n2019-07-08 21:17:56.371  INFO 7840 --- &#x5B;           main] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Start completed.\n2019-07-08 21:17:56.377 DEBUG 7840 --- &#x5B;           main] c.e.d.r.DemoMapperXml.selectCountry      : ==&gt;  Preparing: SELECT * FROM country, city, address WHERE country.country_id = ? AND country.country_id = city.country_id AND city.city_id = address.city_id \n2019-07-08 21:17:56.387 DEBUG 7840 --- &#x5B;           main] c.e.d.r.DemoMapperXml.selectCountry      : ==&gt; Parameters: 87(Integer)\n2019-07-08 21:17:56.408 DEBUG 7840 --- &#x5B;           main] c.e.d.r.DemoMapperXml.selectCountry      : &amp;lt;==      Total: 5\n2019-07-08 21:17:56.468  INFO 7840 --- &#x5B;       Thread-2] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Shutdown initiated...\n2019-07-08 21:17:56.470  INFO 7840 --- &#x5B;       Thread-2] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Shutdown completed.\n\nProcess finished with exit code 0\n<\/pre><\/div>\n\n\n<p>\u51e6\u7406\u5b9f\u884c\u6642\u306eSQL\u304c\u30b3\u30f3\u30bd\u30fc\u30eb\u306b\u51fa\u529b\u3055\u308c\u307e\u3057\u305f\u3002<\/p>\n\n\n\n<h2 id=\"outline__3\" class=\"wp-block-heading\">\u30bd\u30fc\u30b9<\/h2>\n\n\n\n<p>github\u306b\u3042\u3052\u3066\u307e\u3059\u3002 <br><a href=\"https:\/\/github.com\/itouoti12\/mybatis_nestMapper\">https:\/\/github.com\/itouoti12\/mybatis_nestMapper<\/a> <\/p>\n","protected":false},"excerpt":{"rendered":"<p>spring framework\u3067mybatis\u3092\u4f7f\u3063\u3066\u3044\u305f\u6642\u306flog4j\u3084\u3089logback\u306e\u8a2d\u5b9a\u3084 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":273,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[28,24],"tags":[248,249,13,10],"class_list":["post-1064","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-mybatis","category-spring","tag-boot","tag-logging","tag-mybatis","tag-spring"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/ito-u-oti.com\/index.php?rest_route=\/wp\/v2\/posts\/1064","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ito-u-oti.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ito-u-oti.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ito-u-oti.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ito-u-oti.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1064"}],"version-history":[{"count":1,"href":"https:\/\/ito-u-oti.com\/index.php?rest_route=\/wp\/v2\/posts\/1064\/revisions"}],"predecessor-version":[{"id":1065,"href":"https:\/\/ito-u-oti.com\/index.php?rest_route=\/wp\/v2\/posts\/1064\/revisions\/1065"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/ito-u-oti.com\/index.php?rest_route=\/wp\/v2\/media\/273"}],"wp:attachment":[{"href":"https:\/\/ito-u-oti.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1064"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ito-u-oti.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1064"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ito-u-oti.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1064"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}