Polish
This commit is contained in:
@@ -96,8 +96,8 @@ class JedisConnectionConfiguration extends RedisConnectionConfiguration {
|
||||
|
||||
private JedisConnectionFactory createJedisConnectionFactory() {
|
||||
RedisProperties.Pool pool = this.properties.getJedis().getPool();
|
||||
JedisPoolConfig poolConfig = pool != null
|
||||
? jedisPoolConfig(pool) : new JedisPoolConfig();
|
||||
JedisPoolConfig poolConfig = pool != null ? jedisPoolConfig(pool)
|
||||
: new JedisPoolConfig();
|
||||
|
||||
if (getSentinelConfig() != null) {
|
||||
return new JedisConnectionFactory(getSentinelConfig(), poolConfig);
|
||||
|
||||
@@ -43,7 +43,8 @@ import org.springframework.util.StringUtils;
|
||||
* @author Mark Paluch
|
||||
*/
|
||||
@Configuration
|
||||
@ConditionalOnClass({ GenericObjectPool.class, RedisClient.class, RedisClusterClient.class })
|
||||
@ConditionalOnClass({ GenericObjectPool.class, RedisClient.class,
|
||||
RedisClusterClient.class })
|
||||
class LettuceConnectionConfiguration extends RedisConnectionConfiguration {
|
||||
|
||||
private final RedisProperties properties;
|
||||
@@ -149,8 +150,7 @@ class LettuceConnectionConfiguration extends RedisConnectionConfiguration {
|
||||
return new LettuceConnectionFactory(applyProperties(
|
||||
applyClientResources(lettucePool, clientResources)));
|
||||
}
|
||||
return applyClientResources(
|
||||
new LettuceConnectionFactory(getSentinelConfig()),
|
||||
return applyClientResources(new LettuceConnectionFactory(getSentinelConfig()),
|
||||
clientResources);
|
||||
}
|
||||
|
||||
@@ -166,8 +166,8 @@ class LettuceConnectionConfiguration extends RedisConnectionConfiguration {
|
||||
this.properties.getLettuce().getPool());
|
||||
DefaultLettucePool lettucePool = new DefaultLettucePool(
|
||||
this.properties.getHost(), this.properties.getPort(), config);
|
||||
return new LettuceConnectionFactory(applyProperties(
|
||||
applyClientResources(lettucePool, clientResources)));
|
||||
return new LettuceConnectionFactory(
|
||||
applyProperties(applyClientResources(lettucePool, clientResources)));
|
||||
}
|
||||
|
||||
return applyClientResources(new LettuceConnectionFactory(), clientResources);
|
||||
|
||||
@@ -46,15 +46,13 @@ import org.springframework.data.redis.core.StringRedisTemplate;
|
||||
@Configuration
|
||||
@ConditionalOnClass({ RedisOperations.class })
|
||||
@EnableConfigurationProperties(RedisProperties.class)
|
||||
@Import({ LettuceConnectionConfiguration.class,
|
||||
JedisConnectionConfiguration.class })
|
||||
@Import({ LettuceConnectionConfiguration.class, JedisConnectionConfiguration.class })
|
||||
public class RedisAutoConfiguration {
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean(name = "redisTemplate")
|
||||
public RedisTemplate<Object, Object> redisTemplate(
|
||||
RedisConnectionFactory redisConnectionFactory)
|
||||
throws UnknownHostException {
|
||||
RedisConnectionFactory redisConnectionFactory) throws UnknownHostException {
|
||||
RedisTemplate<Object, Object> template = new RedisTemplate<>();
|
||||
template.setConnectionFactory(redisConnectionFactory);
|
||||
return template;
|
||||
@@ -63,8 +61,7 @@ public class RedisAutoConfiguration {
|
||||
@Bean
|
||||
@ConditionalOnMissingBean(StringRedisTemplate.class)
|
||||
public StringRedisTemplate stringRedisTemplate(
|
||||
RedisConnectionFactory redisConnectionFactory)
|
||||
throws UnknownHostException {
|
||||
RedisConnectionFactory redisConnectionFactory) throws UnknownHostException {
|
||||
StringRedisTemplate template = new StringRedisTemplate();
|
||||
template.setConnectionFactory(redisConnectionFactory);
|
||||
return template;
|
||||
|
||||
@@ -200,11 +200,9 @@ public class ResourceServerProperties implements BeanFactoryAware {
|
||||
// resource token services
|
||||
return;
|
||||
}
|
||||
|
||||
if (!StringUtils.hasText(this.clientId)) {
|
||||
return;
|
||||
}
|
||||
|
||||
BindingResult result = getBindingResult();
|
||||
if (result.hasErrors()) {
|
||||
throw new BindException(result);
|
||||
@@ -217,12 +215,11 @@ public class ResourceServerProperties implements BeanFactoryAware {
|
||||
}
|
||||
|
||||
private BindingResult getBindingResult() {
|
||||
BindingResult errors = new BeanPropertyBindingResult(this, "resourceServerProperties");
|
||||
|
||||
BindingResult errors = new BeanPropertyBindingResult(this,
|
||||
"resourceServerProperties");
|
||||
boolean jwtConfigPresent = StringUtils.hasText(this.jwt.getKeyUri())
|
||||
|| StringUtils.hasText(this.jwt.getKeyValue());
|
||||
boolean jwkConfigPresent = StringUtils.hasText(this.jwk.getKeySetUri());
|
||||
|
||||
if (jwtConfigPresent && jwkConfigPresent) {
|
||||
errors.reject("ambiguous.keyUri",
|
||||
"Only one of jwt.keyUri (or jwt.keyValue) and jwk.keySetUri should"
|
||||
|
||||
@@ -96,8 +96,7 @@ public class RedisAutoConfigurationJedisTests {
|
||||
assertThat(cf.getPoolConfig().getMinIdle()).isEqualTo(1);
|
||||
assertThat(cf.getPoolConfig().getMaxIdle()).isEqualTo(4);
|
||||
assertThat(cf.getPoolConfig().getMaxTotal()).isEqualTo(16);
|
||||
assertThat(cf.getPoolConfig().getMaxWaitMillis())
|
||||
.isEqualTo(2000);
|
||||
assertThat(cf.getPoolConfig().getMaxWaitMillis()).isEqualTo(2000);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -70,7 +70,8 @@ public class RedisAutoConfigurationTests {
|
||||
@Test
|
||||
public void testOverrideRedisConfiguration() {
|
||||
load("spring.redis.host:foo", "spring.redis.database:1");
|
||||
LettuceConnectionFactory cf = this.context.getBean(LettuceConnectionFactory.class);
|
||||
LettuceConnectionFactory cf = this.context
|
||||
.getBean(LettuceConnectionFactory.class);
|
||||
assertThat(cf.getHostName()).isEqualTo("foo");
|
||||
assertThat(cf.getDatabase()).isEqualTo(1);
|
||||
assertThat(cf.getPassword()).isNull();
|
||||
@@ -81,7 +82,8 @@ public class RedisAutoConfigurationTests {
|
||||
public void testRedisUrlConfiguration() throws Exception {
|
||||
load("spring.redis.host:foo",
|
||||
"spring.redis.url:redis://user:password@example:33");
|
||||
LettuceConnectionFactory cf = this.context.getBean(LettuceConnectionFactory.class);
|
||||
LettuceConnectionFactory cf = this.context
|
||||
.getBean(LettuceConnectionFactory.class);
|
||||
assertThat(cf.getHostName()).isEqualTo("example");
|
||||
assertThat(cf.getPort()).isEqualTo(33);
|
||||
assertThat(cf.getPassword()).isEqualTo("password");
|
||||
@@ -93,7 +95,8 @@ public class RedisAutoConfigurationTests {
|
||||
load("spring.redis.host:foo", "spring.redis.password:xyz",
|
||||
"spring.redis.port:1000", "spring.redis.ssl:false",
|
||||
"spring.redis.url:rediss://user:password@example:33");
|
||||
LettuceConnectionFactory cf = this.context.getBean(LettuceConnectionFactory.class);
|
||||
LettuceConnectionFactory cf = this.context
|
||||
.getBean(LettuceConnectionFactory.class);
|
||||
assertThat(cf.getHostName()).isEqualTo("example");
|
||||
assertThat(cf.getPort()).isEqualTo(33);
|
||||
assertThat(cf.getPassword()).isEqualTo("password");
|
||||
@@ -106,7 +109,8 @@ public class RedisAutoConfigurationTests {
|
||||
"spring.redis.lettuce.pool.max-idle:4",
|
||||
"spring.redis.lettuce.pool.max-active:16",
|
||||
"spring.redis.lettuce.pool.max-wait:2000");
|
||||
LettuceConnectionFactory cf = this.context.getBean(LettuceConnectionFactory.class);
|
||||
LettuceConnectionFactory cf = this.context
|
||||
.getBean(LettuceConnectionFactory.class);
|
||||
assertThat(cf.getHostName()).isEqualTo("foo");
|
||||
assertThat(getDefaultLettucePool(cf).getHostName()).isEqualTo("foo");
|
||||
assertThat(getDefaultLettucePool(cf).getPoolConfig().getMinIdle()).isEqualTo(1);
|
||||
@@ -119,7 +123,8 @@ public class RedisAutoConfigurationTests {
|
||||
@Test
|
||||
public void testRedisConfigurationWithTimeout() throws Exception {
|
||||
load("spring.redis.host:foo", "spring.redis.timeout:100");
|
||||
LettuceConnectionFactory cf = this.context.getBean(LettuceConnectionFactory.class);
|
||||
LettuceConnectionFactory cf = this.context
|
||||
.getBean(LettuceConnectionFactory.class);
|
||||
assertThat(cf.getHostName()).isEqualTo("foo");
|
||||
assertThat(cf.getTimeout()).isEqualTo(100);
|
||||
}
|
||||
|
||||
@@ -78,8 +78,8 @@ public class ResourceServerPropertiesTests {
|
||||
this.properties.getJwt().setKeyUri("http://my-auth-server/token_key");
|
||||
setListableBeanFactory();
|
||||
this.thrown.expect(BindException.class);
|
||||
this.thrown.expect(getMatcher("Only one of jwt.keyUri (or jwt.keyValue) " +
|
||||
"and jwk.keySetUri should be configured.", null));
|
||||
this.thrown.expect(getMatcher("Only one of jwt.keyUri (or jwt.keyValue) "
|
||||
+ "and jwk.keySetUri should be configured.", null));
|
||||
this.properties.validate();
|
||||
}
|
||||
|
||||
@@ -89,10 +89,9 @@ public class ResourceServerPropertiesTests {
|
||||
this.properties.getJwk().setKeySetUri("http://my-auth-server/token_keys");
|
||||
this.properties.getJwt().setKeyValue("my-key");
|
||||
setListableBeanFactory();
|
||||
|
||||
this.thrown.expect(BindException.class);
|
||||
this.thrown.expect(getMatcher("Only one of jwt.keyUri (or jwt.keyValue) " +
|
||||
"and jwk.keySetUri should be configured.", null));
|
||||
this.thrown.expect(getMatcher("Only one of jwt.keyUri (or jwt.keyValue) "
|
||||
+ "and jwk.keySetUri should be configured.", null));
|
||||
this.properties.validate();
|
||||
}
|
||||
|
||||
@@ -127,8 +126,8 @@ public class ResourceServerPropertiesTests {
|
||||
throws Exception {
|
||||
setListableBeanFactory();
|
||||
this.thrown.expect(BindException.class);
|
||||
this.thrown.expect(getMatcher("Missing tokenInfoUri and userInfoUri and there" +
|
||||
" is no JWT verifier key", "tokenInfoUri"));
|
||||
this.thrown.expect(getMatcher("Missing tokenInfoUri and userInfoUri and there"
|
||||
+ " is no JWT verifier key", "tokenInfoUri"));
|
||||
this.properties.validate();
|
||||
}
|
||||
|
||||
@@ -201,6 +200,7 @@ public class ResourceServerPropertiesTests {
|
||||
|
||||
private BaseMatcher<BindException> getMatcher(String message, String field) {
|
||||
return new BaseMatcher<BindException>() {
|
||||
|
||||
@Override
|
||||
public void describeTo(Description description) {
|
||||
|
||||
@@ -217,6 +217,7 @@ public class ResourceServerPropertiesTests {
|
||||
String fieldErrors = ((FieldError) error).getField();
|
||||
return messageMatches && fieldErrors.equals(field);
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -26,7 +26,8 @@ import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
* An {@link AbstractFailureAnalyzer} that performs analysis of failures caused by a
|
||||
* {@link BindException} excluding {@link BindValidationException} and {@link UnboundConfigurationPropertiesException}.
|
||||
* {@link BindException} excluding {@link BindValidationException} and
|
||||
* {@link UnboundConfigurationPropertiesException}.
|
||||
*
|
||||
* @author Andy Wilkinson
|
||||
* @author Madhura Bhave
|
||||
@@ -36,8 +37,8 @@ class BindFailureAnalyzer extends AbstractFailureAnalyzer<BindException> {
|
||||
@Override
|
||||
protected FailureAnalysis analyze(Throwable rootFailure, BindException cause) {
|
||||
Throwable rootCause = cause.getCause();
|
||||
if (rootCause instanceof BindValidationException ||
|
||||
rootCause instanceof UnboundConfigurationPropertiesException) {
|
||||
if (rootCause instanceof BindValidationException
|
||||
|| rootCause instanceof UnboundConfigurationPropertiesException) {
|
||||
return null;
|
||||
}
|
||||
return analyzeGenericBindException(cause);
|
||||
|
||||
@@ -27,12 +27,13 @@ import org.springframework.validation.FieldError;
|
||||
import org.springframework.validation.ObjectError;
|
||||
|
||||
/**
|
||||
* An {@link AbstractFailureAnalyzer} that performs analysis of any bind validation failures
|
||||
* caused by {@link BindValidationException} or {@link org.springframework.validation.BindException}.
|
||||
* An {@link AbstractFailureAnalyzer} that performs analysis of any bind validation
|
||||
* failures caused by {@link BindValidationException} or
|
||||
* {@link org.springframework.validation.BindException}.
|
||||
*
|
||||
* @author Madhura Bhave
|
||||
*/
|
||||
public class BindValidationFailureAnalyzer extends AbstractFailureAnalyzer<Throwable> {
|
||||
class BindValidationFailureAnalyzer extends AbstractFailureAnalyzer<Throwable> {
|
||||
|
||||
@Override
|
||||
protected FailureAnalysis analyze(Throwable rootFailure, Throwable cause) {
|
||||
@@ -44,13 +45,16 @@ public class BindValidationFailureAnalyzer extends AbstractFailureAnalyzer<Throw
|
||||
}
|
||||
|
||||
private ExceptionDetails getBindValidationExceptionDetails(Throwable rootFailure) {
|
||||
BindValidationException validationException = findCause(rootFailure, BindValidationException.class);
|
||||
BindValidationException validationException = findCause(rootFailure,
|
||||
BindValidationException.class);
|
||||
if (validationException != null) {
|
||||
BindException target = findCause(rootFailure, BindException.class);
|
||||
List<ObjectError> errors = validationException.getValidationErrors().getAllErrors();
|
||||
List<ObjectError> errors = validationException.getValidationErrors()
|
||||
.getAllErrors();
|
||||
return new ExceptionDetails(errors, target, validationException);
|
||||
}
|
||||
org.springframework.validation.BindException bindException = findCause(rootFailure, org.springframework.validation.BindException.class);
|
||||
org.springframework.validation.BindException bindException = findCause(
|
||||
rootFailure, org.springframework.validation.BindException.class);
|
||||
if (bindException != null) {
|
||||
List<ObjectError> errors = bindException.getAllErrors();
|
||||
return new ExceptionDetails(errors, bindException.getTarget(), bindException);
|
||||
@@ -111,6 +115,7 @@ public class BindValidationFailureAnalyzer extends AbstractFailureAnalyzer<Throw
|
||||
public Throwable getCause() {
|
||||
return this.cause;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -28,10 +28,12 @@ import org.springframework.boot.diagnostics.FailureAnalysis;
|
||||
*
|
||||
* @author Madhura Bhave
|
||||
*/
|
||||
public class UnboundConfigurationPropertyFailureAnalyzer extends AbstractFailureAnalyzer<UnboundConfigurationPropertiesException> {
|
||||
class UnboundConfigurationPropertyFailureAnalyzer
|
||||
extends AbstractFailureAnalyzer<UnboundConfigurationPropertiesException> {
|
||||
|
||||
@Override
|
||||
protected FailureAnalysis analyze(Throwable rootFailure, UnboundConfigurationPropertiesException cause) {
|
||||
protected FailureAnalysis analyze(Throwable rootFailure,
|
||||
UnboundConfigurationPropertiesException cause) {
|
||||
BindException exception = findCause(rootFailure, BindException.class);
|
||||
return analyzeUnboundConfigurationPropertiesException(exception, cause);
|
||||
}
|
||||
|
||||
@@ -91,10 +91,13 @@ public class BindValidationFailureAnalyzerTests {
|
||||
|
||||
@Test
|
||||
public void otherBindExceptionShouldReturnAnalysis() throws Exception {
|
||||
BindException cause = new BindException(new FieldValidationFailureProperties(), "fieldValidationFailureProperties");
|
||||
BindException cause = new BindException(new FieldValidationFailureProperties(),
|
||||
"fieldValidationFailureProperties");
|
||||
cause.addError(new FieldError("test", "value", "may not be null"));
|
||||
BeanCreationException rootFailure = new BeanCreationException("bean creation failure", cause);
|
||||
FailureAnalysis analysis = new BindValidationFailureAnalyzer().analyze(rootFailure, rootFailure);
|
||||
BeanCreationException rootFailure = new BeanCreationException(
|
||||
"bean creation failure", cause);
|
||||
FailureAnalysis analysis = new BindValidationFailureAnalyzer()
|
||||
.analyze(rootFailure, rootFailure);
|
||||
assertThat(analysis.getDescription())
|
||||
.contains(failure("test.value", "null", "may not be null"));
|
||||
}
|
||||
|
||||
@@ -122,6 +122,7 @@ public class UnboundConfigurationPropertyFailureAnalyzerTests {
|
||||
public void setListValue(List<String> listValue) {
|
||||
this.listValue = listValue;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user