推土机和Spring集成 [英] Dozer and Spring integration

查看:177
本文介绍了推土机和Spring集成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

引入了一个新的库,用于澄清新版本的情况

EDIT : A new lib has been introduced which clarify the thing for new versions

从5.5.0版开始,Spring集成包含在附加模块中 推土机弹簧.

Since version 5.5.0 Spring integration comes within additional module dozer-spring.


您好,我对Dozer和Spring还是比较陌生,对如何将其放置到位有些困惑.


Hi there I'm relatively new to Dozer and Spring and a bit confused about how to put that in place.

从推土机网站上: http://dozer.sourceforge.net/documentation/usage.html

春季整合 ...

<bean id="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>

现在来自 http://dozer.sourceforge.net/documentation/springintegration.html:

<bean class="org.dozer.spring.DozerBeanMapperFactoryBean">
    <property name="mappingFiles" value="classpath*:/*mapping.xml"/>
    <property name="customConverters">
        <list>
            <bean class="org.dozer.converters.CustomConverter"/>      
        </list>
    </property>
    <property name="eventListeners">
        <list>
            <bean class="org.dozer.listeners.EventListener"/>
        </list>
    </property>
    <property name="factories">
        <map>
            <entry key="id" value-ref="bean-factory-ref"/>
        </map>
    </property>
</bean>

所以我不确定我应该使用哪种方式.我的目标是在我的业务类中有一个映射器对象,该对象将把Business Objects转换为DTO(并相反). 所以我认为这应该只是一个基本的依赖注入?

So I'm not really sure which way I should use it. My objectives is to have a mapper object in my business classes that will convert Business Objects to DTO (and reversely). So I think it just should be a basic Dependency Injection ?

感谢您的帮助.

推荐答案

都是有效的方法,只需将此映射器作为依赖项注入到负责映射的服务类中即可,例如:

Both are valid approaches, just inject this mapper as a dependency in the service class responsible for mapping, eg:

@Service
public class MyMappingService{
 @Autowired DozerBeanMapper dozerBeanMapper;
}

使用DozerBeanMapperFactoryBean时,应遵循以下方法:

With DozerBeanMapperFactoryBean the approach along these lines should work:

<bean class="org.dozer.spring.DozerBeanMapperFactoryBean">
....
</bean>

这将返回一个映射器实例,因此只需以这种方式注入一个映射器类型:

This returns a mapper instance, so just inject in a mapper type this way:

@Service
public class MyMappingService{
 @Autowired Mapper dozerBeanMapper;
}

这篇关于推土机和Spring集成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆