Spring不能使用final方法自动化抽象类

时间:2015-12-09 02:26:35

标签: java spring

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不起作用。

0 个答案:

没有答案