-
Notifications
You must be signed in to change notification settings - Fork 41.7k
Description
Spring Boot 1.5.1/1.4.4
I tried the @validated annotation as explained in the changelog of spring boot 1.5.1. I tried it with both version 1.4.4 and 1.5.1 and get the same exception. So before @validated will be mandatory I wanted to share my experiences.
@ConfigurationProperties validation
If you have @ConfigurationProperties classes that use JSR-303 constraint annotations, you should now additionally annotate them with @validated. Existing validation will currently continue to work, however, a warning will be logged. In the future, classes without @validated will not be validated at all.
I started a project with own spring boot starters and everything was fine until I started to use the @validated annotation. Since then the PropertiesConfigurationFactory in line 348 contains errors on validating my ConfigurationProperties because every member variables are "empty". Strings are null and ints are 0. dataBinder->bindingResult->target in the PropertiesConfigurationFactory contains only the default values of the types.
This seems to be some bug with cglib? It feels like that the proxy is not correctly instantiated or the validation is to early?
I tried to reproduce this with a small sample project but I could not recreate it.
Maybe you got some idea, what it could be. Maybe something with aop and cglib?
@Validated
@ConfigurationProperties("coffeenet.logging.file")
public class CoffeeNetLoggingFileProperties {
@NotBlank(message = "Please provide a file where your logs will be written e.g. logs/app.log")
private String file = "logs/app.log";
@NotBlank(message = "Please provide a file name pattern with a date pattern e.g. logs/app-%d{yyyy-MM-dd}.log")
private String fileNamePattern = "logs/app-%d{yyyy-MM-dd}.log";
@Min(value = 1, message = "Only positive integers are allowed for the maximum amount of history files.")
@NotNull(message = "Please provide a maximum amount of history files you want to keep.")
private int maxHistory = 30;
// getters and settersWill be injected into a AutoConfiguration and exposed as bean through @EnableConfigurationProperties on the class level of the AutoConfiguration.
With the output
***************************
APPLICATION FAILED TO START
***************************
Description:
Binding to target coffee.synyx.autoconfigure.logging.CoffeeNetLoggingFileProperties@1548b9a4 failed:
Property: coffeenet.logging.file.fileNamePattern
Value: null
Reason: Please provide a file name pattern with a date pattern e.g. logs/app-%d{yyyy-MM-dd}.log
Property: coffeenet.logging.file.file
Value: null
Reason: Please provide a file where your logs will be written e.g. logs/app.log
Property: coffeenet.logging.file.maxHistory
Value: 0
Reason: Only positive integers are allowed for the maximum amount of history files.
Action:
Update your application's configuration