您可以执行以下操作:
package com.mycompany;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.DependsOn;
import org.springframework.stereotype.Component;
@Component
@DependsOn("ruleStore")
public class RuleIdValidator implements ConstraintValidator<ValidRuleId, String> {
@Autowired
private RuleStore ruleStore;
// Some other methods
}
您的 Spring Context 应如下所示:
<context:component-scan base-package="com.mycompany" />
<bean id="ruleStore" class="org.easymock.EasyMock" factory-method="createMock">
<constructor-arg index="0" value="com.mycompany.RuleStore"/>
</bean>