Is is possible to add a non-empty default constructor to a FactoryBean
, where the parameter is injected by @Value
?
@Service
public class DateTimeFormatterFactory implements FactoryBean<DateTimeFormatter> {
private DateTimeFormatter formatter;
@Autowired
public DateTimeFormatterFactory(@Value("${custom.format}") String format) {
formatter = DateTimeFormatter.ofPattern(format);
}
@Override
public DateTimeFormatter getObject() {
return formatter;
}
@Override
public Class<?> getObjectType() {
return DateTimeFormatter.class;
}
@Override
public boolean isSingleton() {
return true;
}
}
/edit: I should have added the error message. Spring complains that there is not "default" constructor without arguments. But if I add one, then my @Value constructor is never called...