-
Notifications
You must be signed in to change notification settings - Fork 32
Description
As of now, Mapstruct spring extension(more specifically ConverterRegistrationConfigurationGenerator) generates configuration class with name ConverterRegistrationConfiguration, name of this bean/component is not set, ie defaults to converterRegistrationConfiguration:
@Generated(
value = "org.mapstruct.extensions.spring.converter.ConverterRegistrationConfigurationGenerator",
date = "2025-01-21T08:53:44.800409700Z"
)
@Configuration
class ConverterRegistrationConfiguration {
private final ConfigurableConversionService conversionService;
private final List<Converter<?, ?>> converters;
ConverterRegistrationConfiguration(
@Qualifier("conversionService") final ConfigurableConversionService conversionService,
final List<Converter<?, ?>> converters) {
this.conversionService = conversionService;
this.converters = converters;
}
@PostConstruct
void registerConverters() {
converters.forEach(conversionService::addConverter);
}
}
in my project Mapstruct is used in multiple places: a different set of mappers is implemented for each of them. So 2 different mapstruct related spring configs are defined with pretty much identical content:
package some.package.name1;
...
@Configuration
@ComponentScan("some.package.name1")
@MapperConfig(componentModel = "spring", uses = ConversionServiceAdapter.class)
@SpringMapperConfig(conversionServiceAdapterPackage ="some.package.name1.adapter",
conversionServiceAdapterClassName ="ConversionServiceAdapter",
conversionServiceBeanName = "conversionService",
generateConverterScan = true)
public class MapperSpringConfig1 {
}
and
package some.package.name2;
...
@Configuration
@ComponentScan("some.package.name2")
@MapperConfig(componentModel = "spring", uses = ConversionServiceAdapter.class)
@SpringMapperConfig(conversionServiceAdapterPackage ="some.package.name2.adapter",
conversionServiceAdapterClassName ="ConversionServiceAdapter",
conversionServiceBeanName = "conversionService",
generateConverterScan = true)
public class MapperSpringConfig2 {
}
when application is started I see a conflict between them due to same bean name used in both cases for ConverterRegistrationConfiguration instance:
ERROR o.s.boot.SpringApplication - Application run failed
org.springframework.context.annotation.ConflictingBeanDefinitionException: Annotation-specified bean name 'converterRegistrationConfiguration' for bean class [some.package.name1.adapter.ConverterRegistrationConfiguration] conflicts with existing, non-compatible bean definition of same name and class [some.package.name2.adapter.ConverterRegistrationConfiguration]
So I want to propose to provide ability to configure it's class name and bean name(just like it is done for adapter class - conversionServiceAdapterClassName in org.mapstruct.extensions.spring.SpringMapperConfig with default value "ConversionServiceAdapter"), so smth like:
converterRegistrationConfigurationClassName in org.mapstruct.extensions.spring.SpringMapperConfig with default value "ConverterRegistrationConfiguration"