简体   繁体   English

自动接线豆

[英]Autowiring beans

I've created a few beans for validation of an object: 我创建了一些bean来验证对象:

<!-- RES rules engine -->
<bean id="rules-execution-server-engine"
    class="util.res.RuleEngineRESJSE">
    <constructor-arg index="0" value="util.res.rulesengine.log" />
</bean> 

  <bean id="rio-object" class="UROImpl">
  </bean>

<bean id="trade-validator-context"
    class="rule.trade.TradeValidationContext">
    <constructor-arg index="0" ref="rio-object" />
</bean>

<bean id="trade-validator"
    class="validator.RESTradeValidator">
    <constructor-arg index="0" ref="trade-validator-context" />
    <constructor-arg index="1" ref="validation-rules-helper" />
</bean>

<bean id="validation-rules-helper"
    class="util.res.RESRulesHelperImpl">
    <constructor-arg index="0" value="rule.traderules.loc" />
    <constructor-arg index="1" ref="rules-execution-server-engine" />
</bean>

I can call and create them through a main method sucessfully. 我可以成功地通过main方法调用并创建它们。 However I am now trying to integrate this code within my other modules. 但是,我现在正在尝试将此代码集成到其他模块中。 The trade-validator bean implements a interface which looks like: Trade-validator bean实现了一个类似于以下内容的接口:

public interface IValidator {

public Object validate(Object obj) throws ValidationException;

} }

I am hoping to call this via the interface: 我希望通过界面调用此方法:

validator.validate(rioObject);

However this is causing issues as I cannot instanate the interface and from the XML you can see the actual requires two other beans for it's constructor. 但是,这导致了问题,因为我无法实例化接口,并且从XML中可以看到实际需要为其构造函数添加另外两个bean。 I've been looking at the autowired approach. 我一直在研究自动接线方法。 But am still getting to grips with it. 但是我仍然在努力。

Is there a way to point it towards the bean as being the validator to use? 有没有办法将它指向要用作验证器的bean? As atm the validator is null. 作为atm,验证器为null。

My recommendation is to avoid using autowire for bigger deployments and wire the beans yourselves. 我的建议是避免将autowire用于更大的部署,并自行连接bean。

BTW, why are you not able to instantiate the trade validator ? 顺便说一句,为什么您不能实例化交易验证器? What is the error that you are getting? 您得到的错误是什么?

However this is causing issues as I cannot instanate the interface and from the XML 但是,这引起了问题,因为我无法实例化接口和XML

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM