-
Notifications
You must be signed in to change notification settings - Fork 41.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
@ConfigurationProperties bug when a property is a list of classes #6240
Comments
Thanks for the sample. I see what's going on now. The problem is that the underlying support in Spring Framework for property conversion can't convert a comma-separate String into a List of classes. Instead, it tries to load a class named
If you'd like Spring Framework to be able to support this comma-separated In the meantime, you could add your own converter: @ConfigurationPropertiesBinding
@Bean
public Converter<String, List<Class<? extends Throwable>>> customConverter() {
return new Converter<String, List<Class<? extends Throwable>>>() {
@SuppressWarnings("unchecked")
@Override
public List<Class<? extends Throwable>> convert(String source) {
try {
List<Class<? extends Throwable>> classes = new ArrayList<>();
for (String className: StringUtils.commaDelimitedListToStringArray(source)) {
classes.add((Class<? extends Throwable>)ClassUtils.forName(className.trim(),
getClass().getClassLoader()));
}
return classes;
} catch (ClassNotFoundException ex) {
ex.printStackTrace();
throw new IllegalStateException(ex);
}
}
};
} |
Thanks again! |
thanks |
This looks very similar to #12166 so you might want to consider upgrading to Spring Boot 2.0 |
I'm using 1.3.5.RELEASE version.
I have a configuration class:
and application.yml file:
Now I expect
classes
to be[java.io.IOException, java.lang.IllegalArgumentException]
but they are[java.lang.Exception, java.lang.RuntimeException]
See the demo project for more details.
The text was updated successfully, but these errors were encountered: