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();
|
||||
|
||||
/**
|
||||
* Creates a new {@code OpenTsdbGaugeWriter} with the default connect (10 seconds)
|
||||
* and read (30 seconds) timeouts.
|
||||
* Creates a new {@code OpenTsdbGaugeWriter} with the default connect (10 seconds) and
|
||||
* read (30 seconds) timeouts.
|
||||
*/
|
||||
public OpenTsdbGaugeWriter() {
|
||||
this(DEFAULT_CONNECT_TIMEOUT, DEFAULT_READ_TIMEOUT);
|
||||
|
@ -66,7 +66,8 @@ import org.springframework.util.StringUtils;
|
||||
public class JobLauncherCommandLineRunner
|
||||
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();
|
||||
|
||||
|
@ -66,7 +66,8 @@ public class ElasticsearchAutoConfiguration implements DisposableBean {
|
||||
DEFAULTS = Collections.unmodifiableMap(defaults);
|
||||
}
|
||||
|
||||
private static final Log logger = LogFactory.getLog(ElasticsearchAutoConfiguration.class);
|
||||
private static final Log logger = LogFactory
|
||||
.getLog(ElasticsearchAutoConfiguration.class);
|
||||
|
||||
@Autowired
|
||||
private ElasticsearchProperties properties;
|
||||
|
@ -68,7 +68,8 @@ import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType;
|
||||
@Import({ Registrar.class, DataSourcePoolMetadataProvidersConfiguration.class })
|
||||
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
|
||||
@ -119,7 +120,8 @@ public class DataSourceAutoConfiguration {
|
||||
DataSourceBuilder factory = DataSourceBuilder
|
||||
.create(this.properties.getClassLoader())
|
||||
.driverClassName(this.properties.determineDriverClassName())
|
||||
.url(this.properties.determineUrl()).username(this.properties.determineUsername())
|
||||
.url(this.properties.determineUrl())
|
||||
.username(this.properties.determineUsername())
|
||||
.password(this.properties.determinePassword());
|
||||
if (this.properties.getType() != null) {
|
||||
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.
|
||||
* <p>
|
||||
* If a pooled {@link DataSource} is available, it will always be preferred to
|
||||
* an {@code EmbeddedDatabase}.
|
||||
* If a pooled {@link DataSource} is available, it will always be preferred to an
|
||||
* {@code EmbeddedDatabase}.
|
||||
*/
|
||||
static class EmbeddedDatabaseCondition extends SpringBootCondition {
|
||||
|
||||
@ -212,8 +213,7 @@ public class DataSourceAutoConfiguration {
|
||||
public ConditionOutcome getMatchOutcome(ConditionContext context,
|
||||
AnnotatedTypeMetadata metadata) {
|
||||
if (anyMatches(context, metadata, this.pooledCondition)) {
|
||||
return ConditionOutcome
|
||||
.noMatch("supported DataSource class found");
|
||||
return ConditionOutcome.noMatch("supported DataSource class found");
|
||||
}
|
||||
EmbeddedDatabaseType type = EmbeddedDatabaseConnection
|
||||
.get(context.getClassLoader()).getType();
|
||||
@ -244,7 +244,8 @@ public class DataSourceAutoConfiguration {
|
||||
return ConditionOutcome
|
||||
.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.noMatch("no existing bean configured database");
|
||||
|
@ -286,7 +286,6 @@ public class DataSourceProperties
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Determine the password to use based on this configuration and the environment.
|
||||
* @return the password to use
|
||||
|
@ -188,8 +188,7 @@ public class AutoConfigurationReportLoggingInitializer
|
||||
private void addLogMessage(StringBuilder message, String source,
|
||||
ConditionAndOutcomes conditionAndOutcomes) {
|
||||
message.append(String.format("%n %s", source));
|
||||
message.append(
|
||||
conditionAndOutcomes.isFullMatch() ? " matched" : " did not match")
|
||||
message.append(conditionAndOutcomes.isFullMatch() ? " matched" : " did not match")
|
||||
.append(String.format("%n"));
|
||||
for (ConditionAndOutcome conditionAndOutcome : conditionAndOutcomes) {
|
||||
message.append(" - ");
|
||||
|
@ -167,8 +167,8 @@ public class AuthenticationManagerConfiguration {
|
||||
}
|
||||
User user = this.securityProperties.getUser();
|
||||
if (user.isDefaultPassword()) {
|
||||
logger.info(String.format(
|
||||
"%n%nUsing default security password: %s%n", user.getPassword()));
|
||||
logger.info(String.format("%n%nUsing default security password: %s%n",
|
||||
user.getPassword()));
|
||||
}
|
||||
Set<String> roles = new LinkedHashSet<String>(user.getRole());
|
||||
withUser(user.getName()).password(user.getPassword())
|
||||
|
@ -64,12 +64,8 @@ public class SendGridAutoConfiguration {
|
||||
if (this.properties.getApiKey() != null) {
|
||||
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 {
|
||||
|
||||
@ -84,5 +80,6 @@ public class SendGridAutoConfiguration {
|
||||
@ConditionalOnProperty(prefix = "spring.sendgrid", value = "api-key")
|
||||
static class SendGridApiKeyProperty {
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -34,17 +34,23 @@ import org.springframework.util.ClassUtils;
|
||||
public class JspTemplateAvailabilityProvider implements TemplateAvailabilityProvider {
|
||||
|
||||
@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)) {
|
||||
String resourceName = getResourceName(view, environment);
|
||||
return resourceLoader.getResource(resourceName).exists();
|
||||
}
|
||||
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 resourceLoader.getResource(prefix + view + suffix).exists();
|
||||
}
|
||||
return false;
|
||||
return prefix + view + suffix;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -63,7 +63,8 @@ public class SendGridAutoConfigurationTests {
|
||||
public void expectedSendGridBeanCreatedApiKey() {
|
||||
loadContext("spring.sendgrid.apiKey:SG.SECRET-API-KEY");
|
||||
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)
|
||||
|
@ -22,8 +22,8 @@ import org.springframework.core.io.DefaultResourceLoader;
|
||||
import org.springframework.core.io.ResourceLoader;
|
||||
import org.springframework.mock.env.MockEnvironment;
|
||||
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
/**
|
||||
* Tests for {@link JspTemplateAvailabilityProvider}.
|
||||
@ -40,26 +40,27 @@ public class JspTemplateAvailabilityProviderTests {
|
||||
|
||||
@Test
|
||||
public void availabilityOfTemplateThatDoesNotExist() {
|
||||
assertFalse(this.provider.isTemplateAvailable("whatever", this.environment,
|
||||
getClass().getClassLoader(), this.resourceLoader));
|
||||
assertThat(isTemplateAvailable("whatever"), equalTo(false));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void availabilityOfTemplateWithCustomPrefix() {
|
||||
this.environment.setProperty("spring.mvc.view.prefix",
|
||||
"classpath:/custom-templates/");
|
||||
|
||||
assertTrue(this.provider.isTemplateAvailable("custom.jsp", this.environment,
|
||||
getClass().getClassLoader(), this.resourceLoader));
|
||||
assertThat(isTemplateAvailable("custom.jsp"), equalTo(true));
|
||||
}
|
||||
|
||||
@Test
|
||||
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");
|
||||
assertThat(isTemplateAvailable("suffixed"), equalTo(true));
|
||||
}
|
||||
|
||||
assertTrue(this.provider.isTemplateAvailable("suffixed", this.environment,
|
||||
getClass().getClassLoader(), this.resourceLoader));
|
||||
private boolean isTemplateAvailable(String view) {
|
||||
return this.provider.isTemplateAvailable(view, this.environment,
|
||||
getClass().getClassLoader(), this.resourceLoader);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -159,8 +159,10 @@ public class DependencyManagementBomTransformation
|
||||
}
|
||||
|
||||
private void handleMalformedDependency(Expression expression) {
|
||||
Message message = createSyntaxErrorMessage(String.format(
|
||||
"The string must be of the form \"group:module:version\"%n"), expression);
|
||||
Message message = createSyntaxErrorMessage(
|
||||
String.format(
|
||||
"The string must be of the form \"group:module:version\"%n"),
|
||||
expression);
|
||||
getSourceUnit().getErrorCollector().addErrorAndContinue(message);
|
||||
}
|
||||
|
||||
|
@ -46,7 +46,8 @@ import org.springframework.core.Ordered;
|
||||
public class FileEncodingApplicationListener
|
||||
implements ApplicationListener<ApplicationEnvironmentPreparedEvent>, Ordered {
|
||||
|
||||
private static final Log logger = LogFactory.getLog(FileEncodingApplicationListener.class);
|
||||
private static final Log logger = LogFactory
|
||||
.getLog(FileEncodingApplicationListener.class);
|
||||
|
||||
@Override
|
||||
public int getOrder() {
|
||||
|
@ -59,7 +59,8 @@ import org.springframework.util.ClassUtils;
|
||||
public class ServletListenerRegistrationBean<T extends EventListener>
|
||||
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;
|
||||
|
||||
|
@ -150,8 +150,8 @@ public class LogbackLoggingSystem extends Slf4JLoggingSystem {
|
||||
}
|
||||
}
|
||||
if (errors.length() > 0) {
|
||||
throw new IllegalStateException(String.format(
|
||||
"Logback configuration error detected: %n%s", errors));
|
||||
throw new IllegalStateException(
|
||||
String.format("Logback configuration error detected: %n%s", errors));
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user