16
16
17
17
package org .springframework .boot .autoconfigure .data .jdbc ;
18
18
19
+ import java .lang .reflect .InvocationTargetException ;
19
20
import java .util .Optional ;
20
21
import java .util .Set ;
21
22
23
+ import org .springframework .beans .factory .BeanCreationException ;
22
24
import org .springframework .boot .autoconfigure .AutoConfiguration ;
23
25
import org .springframework .boot .autoconfigure .EnableAutoConfiguration ;
24
26
import org .springframework .boot .autoconfigure .condition .ConditionalOnBean ;
28
30
import org .springframework .boot .autoconfigure .domain .EntityScanner ;
29
31
import org .springframework .boot .autoconfigure .jdbc .DataSourceTransactionManagerAutoConfiguration ;
30
32
import org .springframework .boot .autoconfigure .jdbc .JdbcTemplateAutoConfiguration ;
33
+ import org .springframework .boot .context .properties .EnableConfigurationProperties ;
31
34
import org .springframework .context .ApplicationContext ;
32
35
import org .springframework .context .annotation .Bean ;
33
36
import org .springframework .context .annotation .Configuration ;
59
62
* @author Andy Wilkinson
60
63
* @author Stephane Nicoll
61
64
* @author Mark Paluch
65
+ * @author Jens Schauder
62
66
* @since 2.1.0
63
67
* @see EnableJdbcRepositories
64
68
*/
67
71
@ ConditionalOnClass ({ NamedParameterJdbcOperations .class , AbstractJdbcConfiguration .class })
68
72
@ ConditionalOnProperty (prefix = "spring.data.jdbc.repositories" , name = "enabled" , havingValue = "true" ,
69
73
matchIfMissing = true )
74
+ @ EnableConfigurationProperties (JdbcDataProperties .class )
70
75
public class JdbcRepositoriesAutoConfiguration {
71
76
72
77
@ Configuration (proxyBeanMethods = false )
@@ -82,8 +87,11 @@ static class SpringBootJdbcConfiguration extends AbstractJdbcConfiguration {
82
87
83
88
private final ApplicationContext applicationContext ;
84
89
85
- SpringBootJdbcConfiguration (ApplicationContext applicationContext ) {
90
+ private final JdbcDataProperties properties ;
91
+
92
+ SpringBootJdbcConfiguration (ApplicationContext applicationContext , JdbcDataProperties properties ) {
86
93
this .applicationContext = applicationContext ;
94
+ this .properties = properties ;
87
95
}
88
96
89
97
@ Override
@@ -141,6 +149,17 @@ public DataAccessStrategy dataAccessStrategyBean(NamedParameterJdbcOperations op
141
149
@ Bean
142
150
@ ConditionalOnMissingBean
143
151
public Dialect jdbcDialect (NamedParameterJdbcOperations operations ) {
152
+ if (this .properties .getDialect () != null
153
+ ) {
154
+ Class <?> dialectType = this .properties .getDialect ();
155
+ try {
156
+ return (Dialect )dialectType .getDeclaredConstructor ().newInstance ();
157
+ }
158
+ catch (InstantiationException | IllegalAccessException |
159
+ InvocationTargetException | NoSuchMethodException e ) {
160
+ throw new BeanCreationException ("Couldn't create instance of type " + dialectType , e );
161
+ }
162
+ }
144
163
return super .jdbcDialect (operations );
145
164
}
146
165
0 commit comments