Bean引用为空

时间:2015-04-16 20:31:19

标签: java spring

我有一个像这样的上下文配置文件:

applicationContect.xml:

       

   <bean id="CalcValidate" class="com.fmr.pmsvcs.orders.fixture.utility.CalcValidate" >
    <property name="orderRestServiceL" >
       <ref local="OrderRestService" />
    </property>
  </bean>

我的班级看起来像吼叫:

CalcValidate.java

public class CalcValidate {
 public static OrderRestService orderRestServiceL;

    public static OrderRestService getOrderRestServiceL() {
        return orderRestServiceL;
    }

    public static void setOrderRestServiceL(OrderRestService orderRestServiceL)      {
        CalcValidate.orderRestServiceL = orderRestServiceL;
    }
  public static String getNetAssets(String user, BigInteger fundid,
            Order CalcOrder) throws Exception {
        PortfolioReferenceParameter par =
                orderRestServiceL.netAssets(user, fundid);

        if (par.getPortfolios().get(0) == null
                && CalcOrder.getPortfolioTna() == null
                && CalcOrder.getPortfolioTnaUsd() == null) {
            System.out
                    .println("    ##### PASS Portfolio Net Asset are null in service and DB");
            return OrderFixtureConstants.TRUE;
        }

        // *** Validate against Net Asset in Fund Base Currency
        if (!par.getPortfolios().get(0).getTotalNetAssets()
                .equals(CalcOrder.getPortfolioTna())) {
            return ("FAIL  net Asset in response ["
                    + CalcOrder.getPortfolioTna()
                    + " ] doesn't match net Asset in DB ["
                    + par.getPortfolios().get(0).getTotalNetAssets() + " ]");
        }

        System.out.println("    ##### PASS   net Asset in response ["
                + CalcOrder.getPortfolioTna()
                + " ] does match net Asset in DB ["
                + par.getPortfolios().get(0).getTotalNetAssets() + " ]");

        // *** Validate against Net Asset in Fund Base Currency
        if (!par.getPortfolios().get(0).getTotalNetAssetsUSD()
                .equals(CalcOrder.getPortfolioTnaUsd())) {
            return ("FAIL  net Asset USD in response ["
                    + CalcOrder.getPortfolioTnaUsd()
                    + " ] doesn't match net Asset in DB ["
                    + par.getPortfolios().get(0).getTotalNetAssetsUSD() + " ]");
        }

        System.out.println("    ##### PASS   net Asset in response ["
                + CalcOrder.getPortfolioTnaUsd()
                + " ] does match net Asset in DB ["
                + par.getPortfolios().get(0).getTotalNetAssetsUSD() + " ]");

        return OrderFixtureConstants.TRUE;

    }
}

在我班级的后半部分,我调用的方法是orderRestServiceL.getMethod(); 这里&#34; orderRestServiceL&#34;即将归零。任何人有任何想法如何解决这个问题?

1 个答案:

答案 0 :(得分:2)

您的问题似乎与Java类字段有关。 它被声明为静态,而它应该是非静态的:

public class CalcValidate {

  private OrderRestService orderRestServiceL;

  public OrderRestService getOrderRestServiceL() {
    return orderRestServiceL;
  }

  public void setOrderRestServiceL(OrderRestService orderRestServiceL) {
    this.orderRestServiceL = orderRestServiceL;
  }