teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

4

タグの変更

2020/10/15 06:45

投稿

kusogomitan
kusogomitan

スコア17

title CHANGED
File without changes
body CHANGED
File without changes

3

2020/10/15 06:44

投稿

kusogomitan
kusogomitan

スコア17

title CHANGED
File without changes
body CHANGED
@@ -1,4 +1,4 @@
1
- ~~打ち消し線~~SpringbootでSQLログを出したいのですが、
1
+ SpringbootでSQLログを出したいのですが、
2
2
  ```
3
3
  エラーメッセージ
4
4
 

2

2020/10/15 06:34

投稿

kusogomitan
kusogomitan

スコア17

title CHANGED
File without changes
body CHANGED
@@ -1,4 +1,4 @@
1
- SpringbootでSQLログを出したいのですが、
1
+ ~~打ち消し線~~SpringbootでSQLログを出したいのですが、
2
2
  ```
3
3
  エラーメッセージ
4
4
 

1

ソースの追加

2020/10/15 06:34

投稿

kusogomitan
kusogomitan

スコア17

title CHANGED
File without changes
body CHANGED
@@ -49,6 +49,52 @@
49
49
 
50
50
  ```
51
51
  ```
52
+ AppConfig.java
53
+
54
+ package com.example;
55
+
56
+
57
+
58
+ import org.springframework.beans.factory.annotation.Autowired;
59
+ import org.springframework.boot.autoconfigure.jdbc.DataSourceProperties;
60
+ import org.springframework.boot.context.properties.ConfigurationProperties;
61
+ import org.springframework.boot.jdbc.DataSourceBuilder;
62
+ import org.springframework.context.annotation.Bean;
63
+ import org.springframework.context.annotation.Configuration;
64
+ import org.springframework.context.annotation.Primary;
65
+
66
+ import net.sf.log4jdbc.Log4jdbcProxyDataSource;
67
+
68
+ import javax.activation.DataSource;
69
+
70
+ @Configuration
71
+ public class AppConfig {
72
+ @Autowired
73
+ DataSourceProperties datasourceProperties;
74
+ javax.sql.DataSource datasource;
75
+
76
+ @ConfigurationProperties(prefix = "spring.datasource")
77
+ @Bean(destroyMethod = "close")
78
+ DataSource realDataSource() {
79
+ @SuppressWarnings("rawtypes")
80
+ DataSourceBuilder factory = DataSourceBuilder
81
+ .create(this.datasourceProperties.getClassLoader())
82
+ .url(this.datasourceProperties.getUrl())
83
+ .username(this.datasourceProperties.getUsername())
84
+ .password(this.datasourceProperties.getPassword());
85
+ this.datasource = factory.build();
86
+ return (DataSource) this.datasource;
87
+ }
88
+
89
+ @Primary
90
+ @Bean
91
+ Log4jdbcProxyDataSource datasource() {
92
+ return new Log4jdbcProxyDataSource(this.datasource);
93
+ }
94
+ }
95
+
96
+ ```
97
+ ```
52
98
  Pom.xml
53
99
 
54
100
  <?xml version="1.0" encoding="UTF-8"?>