public abstract class BaseLoaneeRepayment implements Repayment {
@Autowired
protected LoanRepository loanRepository;
@Transactional(propagation = Propagation.REQUIRES_NEW)
public final void repay(RepaymentInfo repaymentInfo) {
Loan loan = loanRepository.lockAndLoad(repaymentInfo.getLoan().id());
}
protected abstract void preCheck(final RepaymentInfo repaymentInfo);
protected abstract void updateLoanee(final RepaymentInfo repaymentInfo);
protected abstract void repayment(final RepaymentInfo repaymentInfo);
protected abstract void calcDifference(final RepaymentInfo repaymentInfo);
}
@Service("loaneeNormalRepayment")
public class NormalRepayment extends BaseLoaneeRepayment implements Repayment {
private static final CatLogger logger = CatLoggerFactory.getLogger(NormalRepayment.class);
@Override
public final void preCheck(RepaymentInfo repaymentInfo) {}
@Override
public final void updateLoanee(RepaymentInfo repaymentInfo) {}
@Override
public final void repayment(RepaymentInfo repaymentInfo) {}
@Override
public final void calcDifference(RepaymentInfo repaymentInfo) {}
}
在Junit,
@TransactionConfiguration(defaultRollback = true)
public class NormalRepaymentTest extends ServiceTest {
@Autowired
@Qualifier("normalRepayment2")
private NormalRepayment normalRepayment;
@Autowired
private LoanService loanService;
@Test
public void test() {
normalRepayment.repay(repaymentInfo);
}
}
normalRepayment.repay(repaymentInfo);
NormalRepayment
中的loanRepository
为空。 autowire不起作用。