我正在开发一个Spring Boot项目.我只有注释配置.我想包括推土机将实体转换为DTO,将DTO转换为实体.我在dozer网站上看到,他们解释说我必须在spring xml配置文件中添加以下配置.由于我没有xml文件而是注释配置Java类,我不知道如何将其转换为Java Configuration类.
<bean id="org.dozer.Mapper" class="org.dozer.DozerBeanMapper">
<property name="mappingFiles">
<list>
<value>dozer-global-configuration.xml</value>
<value>dozer-bean-mappings.xml</value>
<value>more-dozer-bean-mappings.xml</value>
</list>
</property>
</bean>
如果有人能给我一个例子,它会非常有用.谢谢
解决方法:
我认为这样的事情应该有效:
@Configuration
public class YourConfiguration {
@Bean(name = "org.dozer.Mapper")
public DozerBeanMapper dozerBean() {
List<String> mappingFiles = Arrays.asList(
"dozer-global-configuration.xml",
"dozer-bean-mappings.xml",
"more-dozer-bean-mappings.xml"
);
DozerBeanMapper dozerBean = new DozerBeanMapper();
dozerBean.setMappingFiles(mappingFiles);
return dozerBean;
}
...
}