Skip to content

Commit

Permalink
Merge branch '2.2.x' into 2.3.x
Browse files Browse the repository at this point in the history
Closes gh-22641
  • Loading branch information
wilkinsona committed Jul 29, 2020
2 parents 5dd7780 + 7255124 commit a580e3a
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 8 deletions.
1 change: 1 addition & 0 deletions spring-boot-project/spring-boot-autoconfigure/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ dependencies {
testImplementation("ch.qos.logback:logback-classic")
testImplementation("commons-fileupload:commons-fileupload")
testImplementation("com.atomikos:transactions-jms")
testImplementation("com.ibm.db2:jcc")
testImplementation("com.jayway.jsonpath:json-path")
testImplementation("com.squareup.okhttp3:mockwebserver")
testImplementation("com.sun.xml.messaging.saaj:saaj-impl")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2012-2019 the original author or authors.
* Copyright 2012-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -13,9 +13,11 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.springframework.boot.autoconfigure.jdbc;

import java.util.HashMap;
import java.util.Map;

import javax.sql.DataSource;
import javax.sql.XADataSource;
import javax.transaction.TransactionManager;
Expand All @@ -28,6 +30,7 @@
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.jdbc.DataSourceProperties.DataSourceBeanCreationException;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.boot.context.properties.bind.Bindable;
import org.springframework.boot.context.properties.bind.Binder;
Expand Down Expand Up @@ -102,11 +105,17 @@ private void bindXaProperties(XADataSource target, DataSourceProperties dataSour
}

private ConfigurationPropertySource getBinderSource(DataSourceProperties dataSourceProperties) {
MapConfigurationPropertySource source = new MapConfigurationPropertySource();
source.put("user", dataSourceProperties.determineUsername());
source.put("password", dataSourceProperties.determinePassword());
source.put("url", dataSourceProperties.determineUrl());
source.putAll(dataSourceProperties.getXa().getProperties());
Map<Object, Object> properties = new HashMap<Object, Object>();
properties.putAll(dataSourceProperties.getXa().getProperties());
properties.computeIfAbsent("user", (key) -> dataSourceProperties.determineUsername());
properties.computeIfAbsent("password", (key) -> dataSourceProperties.determinePassword());
try {
properties.computeIfAbsent("url", (key) -> dataSourceProperties.determineUrl());
}
catch (DataSourceBeanCreationException ex) {
// Continue as not all XA DataSource's require a URL
}
MapConfigurationPropertySource source = new MapConfigurationPropertySource(properties);
ConfigurationPropertyNameAliases aliases = new ConfigurationPropertyNameAliases();
aliases.addAliases("user", "username");
return source.withAliases(aliases);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2012-2019 the original author or authors.
* Copyright 2012-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -19,10 +19,14 @@
import javax.sql.DataSource;
import javax.sql.XADataSource;

import com.ibm.db2.jcc.DB2XADataSource;
import org.hsqldb.jdbc.pool.JDBCXADataSource;
import org.junit.jupiter.api.Test;

import org.springframework.boot.autoconfigure.AutoConfigurations;
import org.springframework.boot.jdbc.XADataSourceWrapper;
import org.springframework.boot.test.context.FilteredClassLoader;
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
import org.springframework.boot.test.util.TestPropertyValues;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
Expand Down Expand Up @@ -60,6 +64,20 @@ void createFromUrl() {
assertThat(dataSource.getUser()).isEqualTo("un");
}

@Test
void createNonEmbeddedFromXAProperties() {
new ApplicationContextRunner().withConfiguration(AutoConfigurations.of(XADataSourceAutoConfiguration.class))
.withUserConfiguration(FromProperties.class)
.withClassLoader(new FilteredClassLoader("org.h2.Driver", "org.hsqldb.jdbcDriver"))
.withPropertyValues("spring.datasource.xa.data-source-class-name:com.ibm.db2.jcc.DB2XADataSource",
"spring.datasource.xa.properties.user:test", "spring.datasource.xa.properties.password:secret")
.run((context) -> {
MockXADataSourceWrapper wrapper = context.getBean(MockXADataSourceWrapper.class);
XADataSource xaDataSource = wrapper.getXaDataSource();
assertThat(xaDataSource).isInstanceOf(DB2XADataSource.class);
});
}

@Test
void createFromClass() throws Exception {
ApplicationContext context = createContext(FromProperties.class,
Expand Down

0 comments on commit a580e3a

Please sign in to comment.