Polish
This commit is contained in:
parent
da9e496818
commit
7a5248e38c
|
|
@ -51,7 +51,7 @@ import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType;
|
|||
* @author Phillip Webb
|
||||
*/
|
||||
@Configuration
|
||||
@ConditionalOnClass(EmbeddedDatabaseType.class)
|
||||
@ConditionalOnClass({ DataSource.class, EmbeddedDatabaseType.class })
|
||||
@EnableConfigurationProperties(DataSourceProperties.class)
|
||||
@Import(Registrar.class)
|
||||
public class DataSourceAutoConfiguration {
|
||||
|
|
@ -73,7 +73,7 @@ public class DataSourceAutoConfiguration {
|
|||
}
|
||||
}
|
||||
|
||||
@Conditional(DataSourceAutoConfiguration.EmbeddedDatabaseCondition.class)
|
||||
@Conditional(DataSourceAutoConfiguration.EmbeddedDataSourceCondition.class)
|
||||
@ConditionalOnMissingBean(DataSource.class)
|
||||
@Import(EmbeddedDataSourceConfiguration.class)
|
||||
protected static class EmbeddedConfiguration {
|
||||
|
|
@ -88,9 +88,10 @@ public class DataSourceAutoConfiguration {
|
|||
public DataSourceInitializer dataSourceInitializer() {
|
||||
return new DataSourceInitializer();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Conditional(DataSourceAutoConfiguration.NonEmbeddedDatabaseCondition.class)
|
||||
@Conditional(DataSourceAutoConfiguration.NonEmbeddedDataSourceCondition.class)
|
||||
@ConditionalOnMissingBean(DataSource.class)
|
||||
protected static class NonEmbeddedConfiguration {
|
||||
|
||||
|
|
@ -112,7 +113,7 @@ public class DataSourceAutoConfiguration {
|
|||
}
|
||||
|
||||
@Configuration
|
||||
@Conditional(DataSourceAutoConfiguration.DatabaseCondition.class)
|
||||
@Conditional(DataSourceAutoConfiguration.DataSourceAvailableCondition.class)
|
||||
protected static class JdbcTemplateConfiguration {
|
||||
|
||||
@Autowired(required = false)
|
||||
|
|
@ -133,19 +134,17 @@ public class DataSourceAutoConfiguration {
|
|||
}
|
||||
|
||||
/**
|
||||
* Base {@link Condition} for non-embedded database checks.
|
||||
* {@link Condition} to test is a supported non-embedded {@link DataSource} type is
|
||||
* available.
|
||||
*/
|
||||
static class NonEmbeddedDatabaseCondition extends SpringBootCondition {
|
||||
static class NonEmbeddedDataSourceCondition extends SpringBootCondition {
|
||||
|
||||
@Override
|
||||
public ConditionOutcome getMatchOutcome(ConditionContext context,
|
||||
AnnotatedTypeMetadata metadata) {
|
||||
|
||||
ClassLoader dataSourceClassLoader = getDataSourceClassLoader(context);
|
||||
if (dataSourceClassLoader != null) {
|
||||
return ConditionOutcome.match("Supported DataSource class found");
|
||||
if (getDataSourceClassLoader(context) != null) {
|
||||
return ConditionOutcome.match("supported DataSource class found");
|
||||
}
|
||||
|
||||
return ConditionOutcome.noMatch("missing supported DataSource");
|
||||
}
|
||||
|
||||
|
|
@ -156,20 +155,16 @@ public class DataSourceAutoConfiguration {
|
|||
private ClassLoader getDataSourceClassLoader(ConditionContext context) {
|
||||
Class<?> dataSourceClass = new DataSourceBuilder(context.getClassLoader())
|
||||
.findType();
|
||||
if (dataSourceClass == null) {
|
||||
return null;
|
||||
}
|
||||
return dataSourceClass.getClassLoader();
|
||||
return (dataSourceClass == null ? null : dataSourceClass.getClassLoader());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* {@link Condition} to detect when an embedded database is used.
|
||||
* {@link Condition} to detect when an embedded {@link DataSource} type can be used.
|
||||
*/
|
||||
static class EmbeddedDatabaseCondition extends SpringBootCondition {
|
||||
static class EmbeddedDataSourceCondition extends SpringBootCondition {
|
||||
|
||||
private final SpringBootCondition nonEmbedded = new NonEmbeddedDatabaseCondition();
|
||||
private final SpringBootCondition nonEmbedded = new NonEmbeddedDataSourceCondition();
|
||||
|
||||
@Override
|
||||
public ConditionOutcome getMatchOutcome(ConditionContext context,
|
||||
|
|
@ -189,27 +184,25 @@ public class DataSourceAutoConfiguration {
|
|||
}
|
||||
|
||||
/**
|
||||
* {@link Condition} to detect when a database is configured.
|
||||
* {@link Condition} to detect when a {@link DataSource} is available (either because
|
||||
* the user provided one or because one will be auto-configured)
|
||||
*/
|
||||
static class DatabaseCondition extends SpringBootCondition {
|
||||
static class DataSourceAvailableCondition extends SpringBootCondition {
|
||||
|
||||
private final SpringBootCondition nonEmbedded = new NonEmbeddedDatabaseCondition();
|
||||
private final SpringBootCondition nonEmbedded = new NonEmbeddedDataSourceCondition();
|
||||
|
||||
private final SpringBootCondition embeddedCondition = new EmbeddedDatabaseCondition();
|
||||
private final SpringBootCondition embeddedCondition = new EmbeddedDataSourceCondition();
|
||||
|
||||
@Override
|
||||
public ConditionOutcome getMatchOutcome(ConditionContext context,
|
||||
AnnotatedTypeMetadata metadata) {
|
||||
|
||||
if (hasBean(context, DataSource.class)) {
|
||||
return ConditionOutcome
|
||||
.match("existing bean configured database detected");
|
||||
}
|
||||
if (anyMatches(context, metadata, this.nonEmbedded, this.embeddedCondition)) {
|
||||
return ConditionOutcome.match("existing auto database detected");
|
||||
}
|
||||
|
||||
if (hasBean(context, DataSource.class)) {
|
||||
return ConditionOutcome
|
||||
.match("Existing bean configured database detected");
|
||||
}
|
||||
|
||||
return ConditionOutcome.noMatch("no existing bean configured database");
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -112,16 +112,18 @@ public class DataSourceBuilder {
|
|||
return this;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public Class<? extends DataSource> findType() {
|
||||
if (this.type != null) {
|
||||
return this.type;
|
||||
}
|
||||
for (String name : DATA_SOURCE_TYPE_NAMES) {
|
||||
if (ClassUtils.isPresent(name, this.classLoader)) {
|
||||
@SuppressWarnings("unchecked")
|
||||
Class<DataSource> resolved = (Class<DataSource>) ClassUtils
|
||||
.resolveClassName(name, this.classLoader);
|
||||
return resolved;
|
||||
try {
|
||||
return (Class<? extends DataSource>) ClassUtils.forName(name,
|
||||
this.classLoader);
|
||||
}
|
||||
catch (Exception ex) {
|
||||
// Swallow and continue
|
||||
}
|
||||
}
|
||||
return null;
|
||||
|
|
|
|||
|
|
@ -211,4 +211,5 @@ public class DataSourceProperties implements BeanClassLoaderAware, InitializingB
|
|||
public ClassLoader getClassLoader() {
|
||||
return this.classLoader;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,13 +19,10 @@ package org.springframework.boot.autoconfigure.jms;
|
|||
import javax.jms.ConnectionFactory;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
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.jms.activemq.ActiveMQAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.jms.hornetq.HornetQAutoConfiguration;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
|
@ -45,7 +42,6 @@ import org.springframework.jms.core.JmsTemplate;
|
|||
@ConditionalOnClass(JmsTemplate.class)
|
||||
@ConditionalOnBean(ConnectionFactory.class)
|
||||
@EnableConfigurationProperties(JmsProperties.class)
|
||||
@AutoConfigureAfter({ HornetQAutoConfiguration.class, ActiveMQAutoConfiguration.class })
|
||||
public class JmsAutoConfiguration {
|
||||
|
||||
@Autowired
|
||||
|
|
|
|||
Loading…
Reference in New Issue