Use `@Validated` as trigger for JSR-330 validation
Update `ConfigurationPropertiesBindingPostProcessor` so that `@Validated` is expected to be used to trigger JSR-330 validation. Any existing configuration classes that use JSR-330 annotations but don't have `@Validated` will currently still be validated, but will now log a warning. This should give users a chance to add the requested annotations before the next Spring Boot release where we will use them as the exclusive signal that validation is required. Closes gh-7579pull/8038/head
parent
f42ebe428c
commit
10dbf3c571
@ -0,0 +1,39 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2012-2017 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package sample.simple;
|
||||||
|
|
||||||
|
import javax.validation.constraints.NotNull;
|
||||||
|
|
||||||
|
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
@ConfigurationProperties(prefix = "sample")
|
||||||
|
public class SampleConfigurationProperties {
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return this.name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setName(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -1 +1,3 @@
|
|||||||
name: Phil
|
name=Phil
|
||||||
|
sample.name=Andy
|
||||||
|
|
||||||
|
@ -1 +0,0 @@
|
|||||||
name: Phil
|
|
Loading…
Reference in New Issue