|
1 | 1 | /*
|
2 |
| - * Copyright 2012-2019 the original author or authors. |
| 2 | + * Copyright 2012-2020 the original author or authors. |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
|
13 | 13 | * See the License for the specific language governing permissions and
|
14 | 14 | * limitations under the License.
|
15 | 15 | */
|
16 |
| - |
17 | 16 | package org.springframework.boot.autoconfigure.jdbc;
|
18 | 17 |
|
| 18 | +import java.util.HashMap; |
| 19 | +import java.util.Map; |
| 20 | + |
19 | 21 | import javax.sql.DataSource;
|
20 | 22 | import javax.sql.XADataSource;
|
21 | 23 | import javax.transaction.TransactionManager;
|
|
28 | 30 | import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
|
29 | 31 | import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
30 | 32 | import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
| 33 | +import org.springframework.boot.autoconfigure.jdbc.DataSourceProperties.DataSourceBeanCreationException; |
31 | 34 | import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
32 | 35 | import org.springframework.boot.context.properties.bind.Bindable;
|
33 | 36 | import org.springframework.boot.context.properties.bind.Binder;
|
@@ -102,11 +105,17 @@ private void bindXaProperties(XADataSource target, DataSourceProperties dataSour
|
102 | 105 | }
|
103 | 106 |
|
104 | 107 | private ConfigurationPropertySource getBinderSource(DataSourceProperties dataSourceProperties) {
|
105 |
| - MapConfigurationPropertySource source = new MapConfigurationPropertySource(); |
106 |
| - source.put("user", dataSourceProperties.determineUsername()); |
107 |
| - source.put("password", dataSourceProperties.determinePassword()); |
108 |
| - source.put("url", dataSourceProperties.determineUrl()); |
109 |
| - source.putAll(dataSourceProperties.getXa().getProperties()); |
| 108 | + Map<Object, Object> properties = new HashMap<Object, Object>(); |
| 109 | + properties.putAll(dataSourceProperties.getXa().getProperties()); |
| 110 | + properties.computeIfAbsent("user", (key) -> dataSourceProperties.determineUsername()); |
| 111 | + properties.computeIfAbsent("password", (key) -> dataSourceProperties.determinePassword()); |
| 112 | + try { |
| 113 | + properties.computeIfAbsent("url", (key) -> dataSourceProperties.determineUrl()); |
| 114 | + } |
| 115 | + catch (DataSourceBeanCreationException ex) { |
| 116 | + // Continue as not all XA DataSource's require a URL |
| 117 | + } |
| 118 | + MapConfigurationPropertySource source = new MapConfigurationPropertySource(properties); |
110 | 119 | ConfigurationPropertyNameAliases aliases = new ConfigurationPropertyNameAliases();
|
111 | 120 | aliases.addAliases("user", "username");
|
112 | 121 | return source.withAliases(aliases);
|
|
0 commit comments