|
32 | 32 | import org.springframework.boot.jdbc.DataSourceInitializationMode;
|
33 | 33 | import org.springframework.boot.jdbc.DatabaseDriver;
|
34 | 34 | import org.springframework.boot.jdbc.EmbeddedDatabaseConnection;
|
35 |
| -import org.springframework.context.EnvironmentAware; |
36 |
| -import org.springframework.core.env.Environment; |
37 | 35 | import org.springframework.util.Assert;
|
38 | 36 | import org.springframework.util.ClassUtils;
|
39 |
| -import org.springframework.util.ObjectUtils; |
40 | 37 | import org.springframework.util.StringUtils;
|
41 | 38 |
|
42 | 39 | /**
|
|
47 | 44 | * @author Stephane Nicoll
|
48 | 45 | * @author Benedikt Ritter
|
49 | 46 | * @author Eddú Meléndez
|
| 47 | + * @author Patryk Kostrzewa |
50 | 48 | * @since 1.1.0
|
51 | 49 | */
|
52 | 50 | @ConfigurationProperties(prefix = "spring.datasource")
|
53 | 51 | public class DataSourceProperties
|
54 |
| - implements BeanClassLoaderAware, EnvironmentAware, InitializingBean { |
| 52 | + implements BeanClassLoaderAware, InitializingBean { |
55 | 53 |
|
56 | 54 | private ClassLoader classLoader;
|
57 | 55 |
|
58 |
| - private Environment environment; |
59 |
| - |
60 | 56 | /**
|
61 | 57 | * Name of the datasource. Default to "testdb" when using an embedded database.
|
62 | 58 | */
|
@@ -166,11 +162,6 @@ public void setBeanClassLoader(ClassLoader classLoader) {
|
166 | 162 | this.classLoader = classLoader;
|
167 | 163 | }
|
168 | 164 |
|
169 |
| - @Override |
170 |
| - public void setEnvironment(Environment environment) { |
171 |
| - this.environment = environment; |
172 |
| - } |
173 |
| - |
174 | 165 | @Override
|
175 | 166 | public void afterPropertiesSet() throws Exception {
|
176 | 167 | this.embeddedDatabaseConnection = EmbeddedDatabaseConnection
|
@@ -244,8 +235,9 @@ public String determineDriverClassName() {
|
244 | 235 | driverClassName = this.embeddedDatabaseConnection.getDriverClassName();
|
245 | 236 | }
|
246 | 237 | if (!StringUtils.hasText(driverClassName)) {
|
247 |
| - throw new DataSourceBeanCreationException(this.embeddedDatabaseConnection, |
248 |
| - this.environment, "driver class"); |
| 238 | + throw new DataSourceBeanCreationException( |
| 239 | + "Failed to determine a suitable driver class", |
| 240 | + this.embeddedDatabaseConnection); |
249 | 241 | }
|
250 | 242 | return driverClassName;
|
251 | 243 | }
|
@@ -290,8 +282,9 @@ public String determineUrl() {
|
290 | 282 | String url = (databaseName == null ? null
|
291 | 283 | : this.embeddedDatabaseConnection.getUrl(databaseName));
|
292 | 284 | if (!StringUtils.hasText(url)) {
|
293 |
| - throw new DataSourceBeanCreationException(this.embeddedDatabaseConnection, |
294 |
| - this.environment, "url"); |
| 285 | + throw new DataSourceBeanCreationException( |
| 286 | + "Failed to determine suitable jdbc url", |
| 287 | + this.embeddedDatabaseConnection); |
295 | 288 | }
|
296 | 289 | return url;
|
297 | 290 | }
|
@@ -522,37 +515,17 @@ public void setProperties(Map<String, String> properties) {
|
522 | 515 |
|
523 | 516 | static class DataSourceBeanCreationException extends BeanCreationException {
|
524 | 517 |
|
525 |
| - DataSourceBeanCreationException(EmbeddedDatabaseConnection connection, |
526 |
| - Environment environment, String property) { |
527 |
| - super(getMessage(connection, environment, property)); |
528 |
| - } |
| 518 | + private final EmbeddedDatabaseConnection connection; |
529 | 519 |
|
530 |
| - private static String getMessage(EmbeddedDatabaseConnection connection, |
531 |
| - Environment environment, String property) { |
532 |
| - StringBuilder message = new StringBuilder(); |
533 |
| - message.append("Cannot determine embedded database " + property |
534 |
| - + " for database type " + connection + ". "); |
535 |
| - message.append("If you want an embedded database please put a supported " |
536 |
| - + "one on the classpath. "); |
537 |
| - message.append("If you have database settings to be loaded from a " |
538 |
| - + "particular profile you may need to active it"); |
539 |
| - if (environment != null) { |
540 |
| - String[] profiles = environment.getActiveProfiles(); |
541 |
| - if (ObjectUtils.isEmpty(profiles)) { |
542 |
| - message.append(" (no profiles are currently active)"); |
543 |
| - } |
544 |
| - else { |
545 |
| - message.append(" (the profiles \"" |
546 |
| - + StringUtils.arrayToCommaDelimitedString( |
547 |
| - environment.getActiveProfiles()) |
548 |
| - + "\" are currently active)"); |
549 |
| - |
550 |
| - } |
551 |
| - } |
552 |
| - message.append("."); |
553 |
| - return message.toString(); |
| 520 | + DataSourceBeanCreationException(String message, |
| 521 | + EmbeddedDatabaseConnection connection) { |
| 522 | + |
| 523 | + super(message); |
| 524 | + this.connection = connection; |
554 | 525 | }
|
555 | 526 |
|
| 527 | + public EmbeddedDatabaseConnection getConnection() { |
| 528 | + return this.connection; |
| 529 | + } |
556 | 530 | }
|
557 |
| - |
558 | 531 | }
|
0 commit comments