静态方法使用bean
java类中的代码
public class BidMsgUtil { private static Logger log = Logger.getLogger(BidMsgUtil.class); private static BidMsgUtil sybBidMsgUtil; private DetailManager detailManager; private IBidTypeInfoCopyManager bidTypeInfoCopyManager; public void init(){ log.error("---------------BidMsgUtil静态类加载了"); sybBidMsgUtil = this; sybBidMsgUtil.detailManager = this.detailManager; sybBidMsgUtil.bidTypeInfoCopyManager = this.bidTypeInfoCopyManager; }/** * @param borrowMoney * @return */ public static double getGtTotalFixInterest(BorrowMoney borrowMoney){
//使用的时候一定要用类名.属性名.方法名 List<RepayDetail> details = sybBidMsgUtil.detailManager.rDList(borrowMoney.getBorrowMoneyId()); double gtTotalFixInterest = 0; int loginId = borrowMoney.getLoginId(); for(RepayDetail repayDetail : details){ if(repayDetail.getLoginId()!=loginId){ gtTotalFixInterest+=repayDetail.getInterest(); } } ); return gtTotalFixInterest; } }
spring配置文件中添加bean
<!--BidMsgUtil 静态类加载 注意使用lazy-init="false"-->
<bean id="bidMsgUtil" class="com.xxx.BidMsgUtil" autowire="byName" scope="singleton" init-method="init" lazy-init="false">
<property name="detailManager" ref="detailManager"></property>
<property name="bidTypeInfoCopyManager" ref="bidTypeInfoCopyManager"></property>
</bean>