Polish "Add property spring.data.jdbc.dialect"
See gh-39941
This commit is contained in:
parent
b3ddb22f75
commit
148c5e8ed5
|
@ -23,13 +23,14 @@ import org.springframework.data.relational.core.dialect.Dialect;
|
|||
* Configuration properties for Spring Data JDBC.
|
||||
*
|
||||
* @author Jens Schauder
|
||||
* @since 3.3
|
||||
* @since 3.3.0
|
||||
*/
|
||||
@ConfigurationProperties(prefix = "spring.data.jdbc")
|
||||
public class JdbcDataProperties {
|
||||
|
||||
/**
|
||||
* Dialect to use. By default, the dialect is determined by inspecting the database connection.
|
||||
* Dialect to use. By default, the dialect is determined by inspecting the database
|
||||
* connection.
|
||||
*/
|
||||
private Class<? extends Dialect> dialect;
|
||||
|
||||
|
|
|
@ -16,11 +16,10 @@
|
|||
|
||||
package org.springframework.boot.autoconfigure.data.jdbc;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
|
||||
import org.springframework.beans.factory.BeanCreationException;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.boot.autoconfigure.AutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
|
||||
|
@ -149,16 +148,8 @@ public class JdbcRepositoriesAutoConfiguration {
|
|||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
public Dialect jdbcDialect(NamedParameterJdbcOperations operations) {
|
||||
if (this.properties.getDialect() != null
|
||||
) {
|
||||
Class<?> dialectType = this.properties.getDialect();
|
||||
try {
|
||||
return (Dialect)dialectType.getDeclaredConstructor().newInstance();
|
||||
}
|
||||
catch (InstantiationException | IllegalAccessException |
|
||||
InvocationTargetException | NoSuchMethodException e) {
|
||||
throw new BeanCreationException("Couldn't create instance of type " + dialectType, e);
|
||||
}
|
||||
if (this.properties.getDialect() != null) {
|
||||
return BeanUtils.instantiateClass(this.properties.getDialect(), Dialect.class);
|
||||
}
|
||||
return super.jdbcDialect(operations);
|
||||
}
|
||||
|
|
|
@ -186,13 +186,11 @@ class JdbcRepositoriesAutoConfigurationTests {
|
|||
@Test
|
||||
void allowsConfigurationOfDialectByProperty() {
|
||||
this.contextRunner.with(database())
|
||||
.withPropertyValues("spring.data.jdbc.dialect:" + JdbcPostgresDialect.class.getName())
|
||||
.withConfiguration(AutoConfigurations.of(JdbcTemplateAutoConfiguration.class,
|
||||
DataSourceTransactionManagerAutoConfiguration.class))
|
||||
.withUserConfiguration(TestConfiguration.class)
|
||||
.run((context) -> {
|
||||
assertThat(context).hasSingleBean(JdbcPostgresDialect.class);
|
||||
});
|
||||
.withPropertyValues("spring.data.jdbc.dialect:" + JdbcPostgresDialect.class.getName())
|
||||
.withConfiguration(AutoConfigurations.of(JdbcTemplateAutoConfiguration.class,
|
||||
DataSourceTransactionManagerAutoConfiguration.class))
|
||||
.withUserConfiguration(TestConfiguration.class)
|
||||
.run((context) -> assertThat(context).hasSingleBean(JdbcPostgresDialect.class));
|
||||
}
|
||||
|
||||
private void allowsUserToDefineCustomBean(Class<?> configuration, Class<?> beanType, String beanName) {
|
||||
|
|
Loading…
Reference in New Issue