Skip to content

Commit

Permalink
Replace JdbcRepositoryFactoryBean autowiring with RuntimeBeanRefere…
Browse files Browse the repository at this point in the history
…nces.

We now specify runtime bean references to qualify the desired mapping context type instead of using autowiring that can match the wrong mapping context.

Closes #1143
  • Loading branch information
mp911de committed Jun 8, 2023
1 parent 6b3819c commit 9b2032d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,12 @@
import java.util.Locale;
import java.util.Optional;

import org.springframework.beans.factory.config.RuntimeBeanReference;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.data.jdbc.core.convert.JdbcConverter;
import org.springframework.data.jdbc.core.mapping.JdbcMappingContext;
import org.springframework.data.jdbc.repository.support.JdbcRepositoryFactoryBean;
import org.springframework.data.relational.core.dialect.Dialect;
import org.springframework.data.relational.core.mapping.Table;
import org.springframework.data.repository.config.RepositoryConfigurationExtensionSupport;
import org.springframework.data.repository.config.RepositoryConfigurationSource;
Expand Down Expand Up @@ -74,6 +78,10 @@ public void postProcess(BeanDefinitionBuilder builder, RepositoryConfigurationSo

Optional<String> transactionManagerRef = source.getAttribute("transactionManagerRef");
builder.addPropertyValue("transactionManager", transactionManagerRef.orElse(DEFAULT_TRANSACTION_MANAGER_BEAN_NAME));

builder.addPropertyValue("mappingContext", new RuntimeBeanReference(JdbcMappingContext.class));
builder.addPropertyValue("dialect", new RuntimeBeanReference(Dialect.class));
builder.addPropertyValue("converter", new RuntimeBeanReference(JdbcConverter.class));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ protected RepositoryFactorySupport doCreateRepositoryFactory() {
return jdbcRepositoryFactory;
}

@Autowired
public void setMappingContext(RelationalMappingContext mappingContext) {

Assert.notNull(mappingContext, "MappingContext must not be null");
Expand All @@ -104,7 +103,6 @@ public void setMappingContext(RelationalMappingContext mappingContext) {
this.mappingContext = mappingContext;
}

@Autowired
public void setDialect(Dialect dialect) {

Assert.notNull(dialect, "Dialect must not be null");
Expand Down Expand Up @@ -141,7 +139,6 @@ public void setJdbcOperations(NamedParameterJdbcOperations operations) {
this.operations = operations;
}

@Autowired
public void setConverter(JdbcConverter converter) {

Assert.notNull(converter, "JdbcConverter must not be null");
Expand Down

0 comments on commit 9b2032d

Please sign in to comment.