1616
1717package org .springframework .boot .autoconfigure .data .jdbc ;
1818
19+ import java .lang .reflect .InvocationTargetException ;
1920import java .util .Optional ;
2021import java .util .Set ;
2122
23+ import org .springframework .beans .factory .BeanCreationException ;
2224import org .springframework .boot .autoconfigure .AutoConfiguration ;
2325import org .springframework .boot .autoconfigure .EnableAutoConfiguration ;
2426import org .springframework .boot .autoconfigure .condition .ConditionalOnBean ;
2830import org .springframework .boot .autoconfigure .domain .EntityScanner ;
2931import org .springframework .boot .autoconfigure .jdbc .DataSourceTransactionManagerAutoConfiguration ;
3032import org .springframework .boot .autoconfigure .jdbc .JdbcTemplateAutoConfiguration ;
33+ import org .springframework .boot .context .properties .EnableConfigurationProperties ;
3134import org .springframework .context .ApplicationContext ;
3235import org .springframework .context .annotation .Bean ;
3336import org .springframework .context .annotation .Configuration ;
5962 * @author Andy Wilkinson
6063 * @author Stephane Nicoll
6164 * @author Mark Paluch
65+ * @author Jens Schauder
6266 * @since 2.1.0
6367 * @see EnableJdbcRepositories
6468 */
6771@ ConditionalOnClass ({ NamedParameterJdbcOperations .class , AbstractJdbcConfiguration .class })
6872@ ConditionalOnProperty (prefix = "spring.data.jdbc.repositories" , name = "enabled" , havingValue = "true" ,
6973 matchIfMissing = true )
74+ @ EnableConfigurationProperties (JdbcDataProperties .class )
7075public class JdbcRepositoriesAutoConfiguration {
7176
7277 @ Configuration (proxyBeanMethods = false )
@@ -82,8 +87,11 @@ static class SpringBootJdbcConfiguration extends AbstractJdbcConfiguration {
8287
8388 private final ApplicationContext applicationContext ;
8489
85- SpringBootJdbcConfiguration (ApplicationContext applicationContext ) {
90+ private final JdbcDataProperties properties ;
91+
92+ SpringBootJdbcConfiguration (ApplicationContext applicationContext , JdbcDataProperties properties ) {
8693 this .applicationContext = applicationContext ;
94+ this .properties = properties ;
8795 }
8896
8997 @ Override
@@ -141,6 +149,17 @@ public DataAccessStrategy dataAccessStrategyBean(NamedParameterJdbcOperations op
141149 @ Bean
142150 @ ConditionalOnMissingBean
143151 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+ }
144163 return super .jdbcDialect (operations );
145164 }
146165
0 commit comments