Remove JSR-330 configuration annotations

Replace JSR-330 validation annotations from all internal
`@ConfigurationProperties` classes with standard Asserts.

Prior to this commit validation of our own configuration properties
would only occur when the user happens to have compliant JSR-330
implementation on their classpath.

See gh-7579
This commit is contained in:
Phillip Webb
2017-01-18 20:32:46 -08:00
parent 0a6456a748
commit f42ebe428c
9 changed files with 69 additions and 27 deletions

View File

@@ -37,10 +37,11 @@ import org.springframework.boot.context.properties.ConfigurationProperties;
public class FlywayProperties {
/**
* Locations of migrations scripts. Can contain the special "{vendor}" placeholder
* to use vendor-specific locations.
* Locations of migrations scripts. Can contain the special "{vendor}" placeholder to
* use vendor-specific locations.
*/
private List<String> locations = new ArrayList<String>(Collections.singletonList("db/migration"));
private List<String> locations = new ArrayList<String>(
Collections.singletonList("db/migration"));
/**
* Check that migration scripts location exists.

View File

@@ -16,10 +16,10 @@
package org.springframework.boot.autoconfigure.h2;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Pattern;
import javax.annotation.PostConstruct;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.util.Assert;
/**
* Configuration properties for H2's console.
@@ -35,8 +35,6 @@ public class H2ConsoleProperties {
/**
* Path at which the console will be available.
*/
@NotNull
@Pattern(regexp = "/[^?#]*", message = "Path must start with /")
private String path = "/h2-console";
/**
@@ -46,6 +44,13 @@ public class H2ConsoleProperties {
private final Settings settings = new Settings();
@PostConstruct
private void validate() {
Assert.notNull(this.path, "Path must not be null");
Assert.isTrue(this.path.length() == 0 || this.path.startsWith("/"),
"Path must start with / or be empty");
}
public String getPath() {
return this.path;
}

View File

@@ -19,11 +19,12 @@ package org.springframework.boot.autoconfigure.liquibase;
import java.io.File;
import java.util.Map;
import javax.validation.constraints.NotNull;
import javax.annotation.PostConstruct;
import liquibase.integration.spring.SpringLiquibase;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.util.Assert;
/**
* Configuration properties to configure {@link SpringLiquibase}.
@@ -37,7 +38,6 @@ public class LiquibaseProperties {
/**
* Change log configuration path.
*/
@NotNull
private String changeLog = "classpath:/db/changelog/db.changelog-master.yaml";
/**
@@ -96,6 +96,11 @@ public class LiquibaseProperties {
*/
private File rollbackFile;
@PostConstruct
private void validate() {
Assert.notNull(this.changeLog, "ChangeLog must not be null");
}
public String getChangeLog() {
return this.changeLog;
}

View File

@@ -26,11 +26,11 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
import javax.annotation.PostConstruct;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.SessionCookieConfig;
import javax.servlet.SessionTrackingMode;
import javax.validation.constraints.NotNull;
import io.undertow.Undertow.Builder;
import io.undertow.UndertowOptions;
@@ -74,6 +74,7 @@ import org.springframework.boot.web.servlet.ServletContextInitializer;
import org.springframework.context.EnvironmentAware;
import org.springframework.core.Ordered;
import org.springframework.core.env.Environment;
import org.springframework.util.Assert;
import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;
@@ -122,7 +123,6 @@ public class ServerProperties
/**
* Path of the main dispatcher servlet.
*/
@NotNull
private String servletPath = "/";
/**
@@ -176,6 +176,11 @@ public class ServerProperties
private Environment environment;
@PostConstruct
private void validate() {
Assert.notNull(this.servletPath, "ServletPath must not be null");
}
@Override
public int getOrder() {
return 0;

View File

@@ -19,10 +19,10 @@ package org.springframework.boot.autoconfigure.webservices;
import java.util.HashMap;
import java.util.Map;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Pattern;
import javax.annotation.PostConstruct;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.util.Assert;
/**
* {@link ConfigurationProperties} for Spring Web Services.
@@ -37,12 +37,17 @@ public class WebServicesProperties {
/**
* Path that serves as the base URI for the services.
*/
@NotNull
@Pattern(regexp = "/[^?#]*", message = "Path must start with /")
private String path = "/services";
private final Servlet servlet = new Servlet();
@PostConstruct
private void validate() {
Assert.notNull(this.path, "Path must not be null");
Assert.isTrue(this.path.length() == 0 || this.path.startsWith("/"),
"Path must start with / or be empty");
}
public String getPath() {
return this.path;
}