質問編集履歴

4

タグの変更

2020/10/15 06:45

投稿

kusogomitan
kusogomitan

スコア17

test CHANGED
File without changes
test CHANGED
File without changes

3

2020/10/15 06:44

投稿

kusogomitan
kusogomitan

スコア17

test CHANGED
File without changes
test 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

test CHANGED
File without changes
test 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

test CHANGED
File without changes
test CHANGED
@@ -100,6 +100,98 @@
100
100
 
101
101
  ```
102
102
 
103
+ AppConfig.java
104
+
105
+
106
+
107
+ package com.example;
108
+
109
+
110
+
111
+
112
+
113
+
114
+
115
+ import org.springframework.beans.factory.annotation.Autowired;
116
+
117
+ import org.springframework.boot.autoconfigure.jdbc.DataSourceProperties;
118
+
119
+ import org.springframework.boot.context.properties.ConfigurationProperties;
120
+
121
+ import org.springframework.boot.jdbc.DataSourceBuilder;
122
+
123
+ import org.springframework.context.annotation.Bean;
124
+
125
+ import org.springframework.context.annotation.Configuration;
126
+
127
+ import org.springframework.context.annotation.Primary;
128
+
129
+
130
+
131
+ import net.sf.log4jdbc.Log4jdbcProxyDataSource;
132
+
133
+
134
+
135
+ import javax.activation.DataSource;
136
+
137
+
138
+
139
+ @Configuration
140
+
141
+ public class AppConfig {
142
+
143
+ @Autowired
144
+
145
+ DataSourceProperties datasourceProperties;
146
+
147
+ javax.sql.DataSource datasource;
148
+
149
+
150
+
151
+ @ConfigurationProperties(prefix = "spring.datasource")
152
+
153
+ @Bean(destroyMethod = "close")
154
+
155
+ DataSource realDataSource() {
156
+
157
+ @SuppressWarnings("rawtypes")
158
+
159
+ DataSourceBuilder factory = DataSourceBuilder
160
+
161
+ .create(this.datasourceProperties.getClassLoader())
162
+
163
+ .url(this.datasourceProperties.getUrl())
164
+
165
+ .username(this.datasourceProperties.getUsername())
166
+
167
+ .password(this.datasourceProperties.getPassword());
168
+
169
+ this.datasource = factory.build();
170
+
171
+ return (DataSource) this.datasource;
172
+
173
+ }
174
+
175
+
176
+
177
+ @Primary
178
+
179
+ @Bean
180
+
181
+ Log4jdbcProxyDataSource datasource() {
182
+
183
+ return new Log4jdbcProxyDataSource(this.datasource);
184
+
185
+ }
186
+
187
+ }
188
+
189
+
190
+
191
+ ```
192
+
193
+ ```
194
+
103
195
  Pom.xml
104
196
 
105
197