I am trying to configure dozer in spring configuration. when using xml config it will be like
<bean class="org.dozer.spring.DozerBeanMapperFactoryBean">
<property name="mappingFiles" value="classpath*:dozer/**/*.dzr.xml"/>
</bean>
how can I define the resources in the configuration file. I tried to use ctx.getResource(), but I cannot access the ApplicationContext in the configuration class.
I tried ContextRefreshedEvent and added resources from there, but still no luck. (afterPropertiesSet is already called and the added mappings do not work)
public class ContextRefreshedEventBuilder extends ContextRefreshedEvent {
public ContextRefreshedEventBuilder(ApplicationContext ctx) {
super(ctx);
DozerBeanMapperFactoryBean mapper = ctx.getBean(DozerBeanMapperFactoryBean.class);
try {
mapper.setMappingFiles(ctx.getResources("classpath*:dozer/**/*.dzr.xml"));
} catch (IOException e) {
e.printStackTrace();
}
}
}
also tried using ClassPathResource but could not find the correct way
DozerBeanMapperFactoryBean mapper = new DozerBeanMapperFactoryBean();
mapper.setMappingFiles(new Resource[]{new ClassPathResource("classpath*:dozer/**/*.dzr.xml")});
return mapper;
How can I add ClassPathResource as mapping locations?
--- ANSWER ---
@Bean
public DozerBeanMapperFactoryBean configDozer() throws IOException {
DozerBeanMapperFactoryBean mapper = new DozerBeanMapperFactoryBean();
Resource[] resources = new PathMatchingResourcePatternResolver().getResources("classpath*:dozer/**/*.dzr.xml");
mapper.setMappingFiles(resources);
return mapper;
}