This commit is contained in:
Phillip Webb
2015-08-03 11:03:32 -07:00
parent 5c1f700c3a
commit 891dd5a0f6
25 changed files with 139 additions and 129 deletions

View File

@@ -34,7 +34,7 @@ public class SampleProperties {
private Integer port = 8080;
public String getHost() {
return host;
return this.host;
}
public void setHost(String host) {
@@ -42,10 +42,11 @@ public class SampleProperties {
}
public Integer getPort() {
return port;
return this.port;
}
public void setPort(Integer port) {
this.port = port;
}
}

View File

@@ -35,10 +35,9 @@ public class SamplePropertiesValidator implements Validator {
public void validate(Object o, Errors errors) {
ValidationUtils.rejectIfEmpty(errors, "host", "host.empty");
ValidationUtils.rejectIfEmpty(errors, "port", "port.empty");
SampleProperties properties = (SampleProperties) o;
if (properties.getHost() != null &&
!pattern.matcher(properties.getHost()).matches()) {
if (properties.getHost() != null
&& !this.pattern.matcher(properties.getHost()).matches()) {
errors.rejectValue("host", "Invalid host");
}
}

View File

@@ -52,8 +52,8 @@ public class SamplePropertyValidationApplication {
}
public static void main(String[] args) throws Exception {
new SpringApplicationBuilder(SamplePropertyValidationApplication.class)
.profiles("app").run(args);
new SpringApplicationBuilder(SamplePropertyValidationApplication.class).profiles(
"app").run(args);
}
}