mirror of
https://github.com/spring-projects/spring-boot.git
synced 2024-09-03 04:26:12 +08:00
Polish
This commit is contained in:
parent
9065ddd857
commit
f276ff4bd0
@ -80,8 +80,8 @@ public class OpenTsdbGaugeWriter implements GaugeWriter {
|
|||||||
private OpenTsdbNamingStrategy namingStrategy = new DefaultOpenTsdbNamingStrategy();
|
private OpenTsdbNamingStrategy namingStrategy = new DefaultOpenTsdbNamingStrategy();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new {@code OpenTsdbGaugeWriter} with the default connect (10 seconds)
|
* Creates a new {@code OpenTsdbGaugeWriter} with the default connect (10 seconds) and
|
||||||
* and read (30 seconds) timeouts.
|
* read (30 seconds) timeouts.
|
||||||
*/
|
*/
|
||||||
public OpenTsdbGaugeWriter() {
|
public OpenTsdbGaugeWriter() {
|
||||||
this(DEFAULT_CONNECT_TIMEOUT, DEFAULT_READ_TIMEOUT);
|
this(DEFAULT_CONNECT_TIMEOUT, DEFAULT_READ_TIMEOUT);
|
||||||
|
@ -66,7 +66,8 @@ import org.springframework.util.StringUtils;
|
|||||||
public class JobLauncherCommandLineRunner
|
public class JobLauncherCommandLineRunner
|
||||||
implements CommandLineRunner, ApplicationEventPublisherAware {
|
implements CommandLineRunner, ApplicationEventPublisherAware {
|
||||||
|
|
||||||
private static final Log logger = LogFactory.getLog(JobLauncherCommandLineRunner.class);
|
private static final Log logger = LogFactory
|
||||||
|
.getLog(JobLauncherCommandLineRunner.class);
|
||||||
|
|
||||||
private JobParametersConverter converter = new DefaultJobParametersConverter();
|
private JobParametersConverter converter = new DefaultJobParametersConverter();
|
||||||
|
|
||||||
|
@ -66,7 +66,8 @@ public class ElasticsearchAutoConfiguration implements DisposableBean {
|
|||||||
DEFAULTS = Collections.unmodifiableMap(defaults);
|
DEFAULTS = Collections.unmodifiableMap(defaults);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final Log logger = LogFactory.getLog(ElasticsearchAutoConfiguration.class);
|
private static final Log logger = LogFactory
|
||||||
|
.getLog(ElasticsearchAutoConfiguration.class);
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private ElasticsearchProperties properties;
|
private ElasticsearchProperties properties;
|
||||||
|
@ -68,7 +68,8 @@ import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType;
|
|||||||
@Import({ Registrar.class, DataSourcePoolMetadataProvidersConfiguration.class })
|
@Import({ Registrar.class, DataSourcePoolMetadataProvidersConfiguration.class })
|
||||||
public class DataSourceAutoConfiguration {
|
public class DataSourceAutoConfiguration {
|
||||||
|
|
||||||
private static final Log logger = LogFactory.getLog(DataSourceAutoConfiguration.class);
|
private static final Log logger = LogFactory
|
||||||
|
.getLog(DataSourceAutoConfiguration.class);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Determines if the {@code dataSource} being used by Spring was created from
|
* Determines if the {@code dataSource} being used by Spring was created from
|
||||||
@ -119,7 +120,8 @@ public class DataSourceAutoConfiguration {
|
|||||||
DataSourceBuilder factory = DataSourceBuilder
|
DataSourceBuilder factory = DataSourceBuilder
|
||||||
.create(this.properties.getClassLoader())
|
.create(this.properties.getClassLoader())
|
||||||
.driverClassName(this.properties.determineDriverClassName())
|
.driverClassName(this.properties.determineDriverClassName())
|
||||||
.url(this.properties.determineUrl()).username(this.properties.determineUsername())
|
.url(this.properties.determineUrl())
|
||||||
|
.username(this.properties.determineUsername())
|
||||||
.password(this.properties.determinePassword());
|
.password(this.properties.determinePassword());
|
||||||
if (this.properties.getType() != null) {
|
if (this.properties.getType() != null) {
|
||||||
factory.type(this.properties.getType());
|
factory.type(this.properties.getType());
|
||||||
@ -200,9 +202,8 @@ public class DataSourceAutoConfiguration {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* {@link Condition} to detect when an embedded {@link DataSource} type can be used.
|
* {@link Condition} to detect when an embedded {@link DataSource} type can be used.
|
||||||
* <p>
|
* If a pooled {@link DataSource} is available, it will always be preferred to an
|
||||||
* If a pooled {@link DataSource} is available, it will always be preferred to
|
* {@code EmbeddedDatabase}.
|
||||||
* an {@code EmbeddedDatabase}.
|
|
||||||
*/
|
*/
|
||||||
static class EmbeddedDatabaseCondition extends SpringBootCondition {
|
static class EmbeddedDatabaseCondition extends SpringBootCondition {
|
||||||
|
|
||||||
@ -212,8 +213,7 @@ public class DataSourceAutoConfiguration {
|
|||||||
public ConditionOutcome getMatchOutcome(ConditionContext context,
|
public ConditionOutcome getMatchOutcome(ConditionContext context,
|
||||||
AnnotatedTypeMetadata metadata) {
|
AnnotatedTypeMetadata metadata) {
|
||||||
if (anyMatches(context, metadata, this.pooledCondition)) {
|
if (anyMatches(context, metadata, this.pooledCondition)) {
|
||||||
return ConditionOutcome
|
return ConditionOutcome.noMatch("supported DataSource class found");
|
||||||
.noMatch("supported DataSource class found");
|
|
||||||
}
|
}
|
||||||
EmbeddedDatabaseType type = EmbeddedDatabaseConnection
|
EmbeddedDatabaseType type = EmbeddedDatabaseConnection
|
||||||
.get(context.getClassLoader()).getType();
|
.get(context.getClassLoader()).getType();
|
||||||
@ -244,7 +244,8 @@ public class DataSourceAutoConfiguration {
|
|||||||
return ConditionOutcome
|
return ConditionOutcome
|
||||||
.match("existing bean configured database detected");
|
.match("existing bean configured database detected");
|
||||||
}
|
}
|
||||||
if (anyMatches(context, metadata, this.pooledCondition, this.embeddedCondition)) {
|
if (anyMatches(context, metadata, this.pooledCondition,
|
||||||
|
this.embeddedCondition)) {
|
||||||
return ConditionOutcome.match("existing auto database detected");
|
return ConditionOutcome.match("existing auto database detected");
|
||||||
}
|
}
|
||||||
return ConditionOutcome.noMatch("no existing bean configured database");
|
return ConditionOutcome.noMatch("no existing bean configured database");
|
||||||
|
@ -286,7 +286,6 @@ public class DataSourceProperties
|
|||||||
this.password = password;
|
this.password = password;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Determine the password to use based on this configuration and the environment.
|
* Determine the password to use based on this configuration and the environment.
|
||||||
* @return the password to use
|
* @return the password to use
|
||||||
|
@ -188,8 +188,7 @@ public class AutoConfigurationReportLoggingInitializer
|
|||||||
private void addLogMessage(StringBuilder message, String source,
|
private void addLogMessage(StringBuilder message, String source,
|
||||||
ConditionAndOutcomes conditionAndOutcomes) {
|
ConditionAndOutcomes conditionAndOutcomes) {
|
||||||
message.append(String.format("%n %s", source));
|
message.append(String.format("%n %s", source));
|
||||||
message.append(
|
message.append(conditionAndOutcomes.isFullMatch() ? " matched" : " did not match")
|
||||||
conditionAndOutcomes.isFullMatch() ? " matched" : " did not match")
|
|
||||||
.append(String.format("%n"));
|
.append(String.format("%n"));
|
||||||
for (ConditionAndOutcome conditionAndOutcome : conditionAndOutcomes) {
|
for (ConditionAndOutcome conditionAndOutcome : conditionAndOutcomes) {
|
||||||
message.append(" - ");
|
message.append(" - ");
|
||||||
|
@ -167,8 +167,8 @@ public class AuthenticationManagerConfiguration {
|
|||||||
}
|
}
|
||||||
User user = this.securityProperties.getUser();
|
User user = this.securityProperties.getUser();
|
||||||
if (user.isDefaultPassword()) {
|
if (user.isDefaultPassword()) {
|
||||||
logger.info(String.format(
|
logger.info(String.format("%n%nUsing default security password: %s%n",
|
||||||
"%n%nUsing default security password: %s%n", user.getPassword()));
|
user.getPassword()));
|
||||||
}
|
}
|
||||||
Set<String> roles = new LinkedHashSet<String>(user.getRole());
|
Set<String> roles = new LinkedHashSet<String>(user.getRole());
|
||||||
withUser(user.getName()).password(user.getPassword())
|
withUser(user.getName()).password(user.getPassword())
|
||||||
|
@ -64,13 +64,9 @@ public class SendGridAutoConfiguration {
|
|||||||
if (this.properties.getApiKey() != null) {
|
if (this.properties.getApiKey() != null) {
|
||||||
return new SendGrid(this.properties.getApiKey());
|
return new SendGrid(this.properties.getApiKey());
|
||||||
}
|
}
|
||||||
else {
|
return new SendGrid(this.properties.getUsername(), this.properties.getPassword());
|
||||||
return new SendGrid(this.properties.getUsername(),
|
|
||||||
this.properties.getPassword());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static class SendGridPropertyCondition extends AnyNestedCondition {
|
static class SendGridPropertyCondition extends AnyNestedCondition {
|
||||||
|
|
||||||
SendGridPropertyCondition() {
|
SendGridPropertyCondition() {
|
||||||
@ -84,5 +80,6 @@ public class SendGridAutoConfiguration {
|
|||||||
@ConditionalOnProperty(prefix = "spring.sendgrid", value = "api-key")
|
@ConditionalOnProperty(prefix = "spring.sendgrid", value = "api-key")
|
||||||
static class SendGridApiKeyProperty {
|
static class SendGridApiKeyProperty {
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -34,17 +34,23 @@ import org.springframework.util.ClassUtils;
|
|||||||
public class JspTemplateAvailabilityProvider implements TemplateAvailabilityProvider {
|
public class JspTemplateAvailabilityProvider implements TemplateAvailabilityProvider {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isTemplateAvailable(String view, Environment environment, ClassLoader classLoader, ResourceLoader resourceLoader) {
|
public boolean isTemplateAvailable(String view, Environment environment,
|
||||||
|
ClassLoader classLoader, ResourceLoader resourceLoader) {
|
||||||
if (ClassUtils.isPresent("org.apache.jasper.compiler.JspConfig", classLoader)) {
|
if (ClassUtils.isPresent("org.apache.jasper.compiler.JspConfig", classLoader)) {
|
||||||
PropertyResolver resolver = new RelaxedPropertyResolver(environment,
|
String resourceName = getResourceName(view, environment);
|
||||||
"spring.mvc.view.");
|
return resourceLoader.getResource(resourceName).exists();
|
||||||
String prefix = resolver.getProperty("prefix",
|
|
||||||
WebMvcAutoConfiguration.DEFAULT_PREFIX);
|
|
||||||
String suffix = resolver.getProperty("suffix",
|
|
||||||
WebMvcAutoConfiguration.DEFAULT_SUFFIX);
|
|
||||||
return resourceLoader.getResource(prefix + view + suffix).exists();
|
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private String getResourceName(String view, Environment environment) {
|
||||||
|
PropertyResolver resolver = new RelaxedPropertyResolver(environment,
|
||||||
|
"spring.mvc.view.");
|
||||||
|
String prefix = resolver.getProperty("prefix",
|
||||||
|
WebMvcAutoConfiguration.DEFAULT_PREFIX);
|
||||||
|
String suffix = resolver.getProperty("suffix",
|
||||||
|
WebMvcAutoConfiguration.DEFAULT_SUFFIX);
|
||||||
|
return prefix + view + suffix;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -63,7 +63,8 @@ public class SendGridAutoConfigurationTests {
|
|||||||
public void expectedSendGridBeanCreatedApiKey() {
|
public void expectedSendGridBeanCreatedApiKey() {
|
||||||
loadContext("spring.sendgrid.apiKey:SG.SECRET-API-KEY");
|
loadContext("spring.sendgrid.apiKey:SG.SECRET-API-KEY");
|
||||||
SendGrid sendGrid = this.context.getBean(SendGrid.class);
|
SendGrid sendGrid = this.context.getBean(SendGrid.class);
|
||||||
assertEquals("SG.SECRET-API-KEY", ReflectionTestUtils.getField(sendGrid, "password"));
|
assertEquals("SG.SECRET-API-KEY",
|
||||||
|
ReflectionTestUtils.getField(sendGrid, "password"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = NoSuchBeanDefinitionException.class)
|
@Test(expected = NoSuchBeanDefinitionException.class)
|
||||||
|
@ -22,8 +22,8 @@ import org.springframework.core.io.DefaultResourceLoader;
|
|||||||
import org.springframework.core.io.ResourceLoader;
|
import org.springframework.core.io.ResourceLoader;
|
||||||
import org.springframework.mock.env.MockEnvironment;
|
import org.springframework.mock.env.MockEnvironment;
|
||||||
|
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.hamcrest.Matchers.equalTo;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertThat;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests for {@link JspTemplateAvailabilityProvider}.
|
* Tests for {@link JspTemplateAvailabilityProvider}.
|
||||||
@ -40,26 +40,27 @@ public class JspTemplateAvailabilityProviderTests {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void availabilityOfTemplateThatDoesNotExist() {
|
public void availabilityOfTemplateThatDoesNotExist() {
|
||||||
assertFalse(this.provider.isTemplateAvailable("whatever", this.environment,
|
assertThat(isTemplateAvailable("whatever"), equalTo(false));
|
||||||
getClass().getClassLoader(), this.resourceLoader));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void availabilityOfTemplateWithCustomPrefix() {
|
public void availabilityOfTemplateWithCustomPrefix() {
|
||||||
this.environment.setProperty("spring.mvc.view.prefix",
|
this.environment.setProperty("spring.mvc.view.prefix",
|
||||||
"classpath:/custom-templates/");
|
"classpath:/custom-templates/");
|
||||||
|
assertThat(isTemplateAvailable("custom.jsp"), equalTo(true));
|
||||||
assertTrue(this.provider.isTemplateAvailable("custom.jsp", this.environment,
|
|
||||||
getClass().getClassLoader(), this.resourceLoader));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void availabilityOfTemplateWithCustomSuffix() {
|
public void availabilityOfTemplateWithCustomSuffix() {
|
||||||
this.environment.setProperty("spring.mvc.view.prefix", "classpath:/custom-templates/");
|
this.environment.setProperty("spring.mvc.view.prefix",
|
||||||
|
"classpath:/custom-templates/");
|
||||||
this.environment.setProperty("spring.mvc.view.suffix", ".jsp");
|
this.environment.setProperty("spring.mvc.view.suffix", ".jsp");
|
||||||
|
assertThat(isTemplateAvailable("suffixed"), equalTo(true));
|
||||||
|
}
|
||||||
|
|
||||||
assertTrue(this.provider.isTemplateAvailable("suffixed", this.environment,
|
private boolean isTemplateAvailable(String view) {
|
||||||
getClass().getClassLoader(), this.resourceLoader));
|
return this.provider.isTemplateAvailable(view, this.environment,
|
||||||
|
getClass().getClassLoader(), this.resourceLoader);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -159,8 +159,10 @@ public class DependencyManagementBomTransformation
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void handleMalformedDependency(Expression expression) {
|
private void handleMalformedDependency(Expression expression) {
|
||||||
Message message = createSyntaxErrorMessage(String.format(
|
Message message = createSyntaxErrorMessage(
|
||||||
"The string must be of the form \"group:module:version\"%n"), expression);
|
String.format(
|
||||||
|
"The string must be of the form \"group:module:version\"%n"),
|
||||||
|
expression);
|
||||||
getSourceUnit().getErrorCollector().addErrorAndContinue(message);
|
getSourceUnit().getErrorCollector().addErrorAndContinue(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -46,7 +46,8 @@ import org.springframework.core.Ordered;
|
|||||||
public class FileEncodingApplicationListener
|
public class FileEncodingApplicationListener
|
||||||
implements ApplicationListener<ApplicationEnvironmentPreparedEvent>, Ordered {
|
implements ApplicationListener<ApplicationEnvironmentPreparedEvent>, Ordered {
|
||||||
|
|
||||||
private static final Log logger = LogFactory.getLog(FileEncodingApplicationListener.class);
|
private static final Log logger = LogFactory
|
||||||
|
.getLog(FileEncodingApplicationListener.class);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getOrder() {
|
public int getOrder() {
|
||||||
|
@ -59,7 +59,8 @@ import org.springframework.util.ClassUtils;
|
|||||||
public class ServletListenerRegistrationBean<T extends EventListener>
|
public class ServletListenerRegistrationBean<T extends EventListener>
|
||||||
extends RegistrationBean {
|
extends RegistrationBean {
|
||||||
|
|
||||||
private static final Log logger = LogFactory.getLog(ServletListenerRegistrationBean.class);
|
private static final Log logger = LogFactory
|
||||||
|
.getLog(ServletListenerRegistrationBean.class);
|
||||||
|
|
||||||
private static final Set<Class<?>> SUPPORTED_TYPES;
|
private static final Set<Class<?>> SUPPORTED_TYPES;
|
||||||
|
|
||||||
|
@ -150,8 +150,8 @@ public class LogbackLoggingSystem extends Slf4JLoggingSystem {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (errors.length() > 0) {
|
if (errors.length() > 0) {
|
||||||
throw new IllegalStateException(String.format(
|
throw new IllegalStateException(
|
||||||
"Logback configuration error detected: %n%s", errors));
|
String.format("Logback configuration error detected: %n%s", errors));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user