调用Java中的重写方法

时间:2019-03-25 08:20:22

标签: java spring

我想重写在父类中编写的方法。所以我写了ExtendDocumentLinkServiceImpl来扩展父类。但是,当我执行它时,它仍在调用父createDocumentLink()方法。

<bean name="documentLinkService" 
    class="org.xxxx.repo.doclink.ExtraDocumentLinkServiceImpl" init-method="init">
    <property name="nodeService" ref="NodeService"/>
</bean>


public class DocumentLinkServiceImpl implements DocumentLinkService {
    private NodeService nodeService;

    public void init() {
        PropertyCheck.mandatory(this, "nodeService", nodeService);
    }

    @Override
    public NodeRef createDocumentLink(final NodeRef source, NodeRef destination) {
        if (logger.isDebugEnabled()) {
            logger.debug("Creating document link. source: " + source + ", destination: " + destination);
        }
    }

    public void setNodeService(NodeService nodeService) {
        this.nodeService = nodeService;
    }
}

<bean name="extendDocumentLinkService" class="com.xxxx.cms.doclink.ExtendDocumentLinkServiceImpl" parent="documentLinkService">
   <constructor-arg ref="nodeService"/>
</bean>


public class ExtendDocumentLinkServiceImpl extends DocumentLinkServiceImpl {
    private NodeService nodeService;

    public CustomizedDocumentLinkServiceImpl(NodeService nodeService) {
        this.nodeService=nodeService;
    }

    @Override
    public NodeRef createDocumentLink(final NodeRef source, NodeRef destination) {
        if (logger.isDebugEnabled()) {
            logger.debug("Creating document link. source: " + source + ", destination: " + destination);
        }
    }
}

0 个答案:

没有答案