0

In a Spring Boot starter project I've created an AttributeConverter, and applied it with autoApply=true @Converter annotation. My problem is that the projects using the starter still need to specify @Convert for the fields.

I've created the AttributeConverter, and applied it with @Converter(autoApply = true):

@Converter(autoApply = true)
public class YearWeekDayAttributeConverter implements AttributeConverter<YearWeekDay, String> {
        public String convertToDatabaseColumn(YearWeekDay yearWeekDay) {
            return yearWeekDay.toString();
        }

        @Override
        public YearWeekDay convertToEntityAttribute(String jsonString) {
            return YearWeekDay.parse(jsonString);
        }
}

Then I've added it to the auto configuration (org.springframework.boot.autoconfigure.AutoConfiguration.imports):

com.eg.nextgen.microservice.converters.YearWeekDayAttributeConverter

The problem comes when I use the starter in another project. I can specify @Convert for the entity fields, and it works perfectly. But if I don't specify @Convert the value is not converted - despite the fact that I added autoApply=true.

Any ideas as to why the autoApply doesn't work? If I put the converter in the project it is being used, and not in the starter project, it will also work (without specyfing @Convert).

  • 1
    Does this answer your question? [@Converter(autoApply = true) not working in different package](https://stackoverflow.com/questions/66966435/converterautoapply-true-not-working-in-different-package) – Simon Martinelli May 30 '23 at 13:40
  • We're going to have a lot of projects, and have therefore created starter projects, so that we can avoid specifying the scanning in all the projects using the starter. We already have some auto configuration that works just fine without the scanning. The problem is just this converter, and that it's not auto applied. – Brian Siim Andersen May 30 '23 at 14:20
  • And you have the Converter in the package that is used in EntityScan? – Simon Martinelli May 30 '23 at 14:22
  • I haven't specified the EntityScan but added the Converter to META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports. Maybe that does not work for converters? – Brian Siim Andersen May 30 '23 at 14:26
  • It should work with EntityScan as well if the Converter ist not below the application root package – Simon Martinelli May 30 '23 at 15:11

0 Answers0