java - Bean 引用为空

标签 java spring

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

applicationContect.xml:

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

我的类(class)如下所示:

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;

    }
}

在类(class)的后面部分,我将调用 orderRestServiceL.getMethod(); 之类的方法; 这里“orderRestServiceL”为空。有人知道如何解决这个问题吗?

最佳答案

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

public class CalcValidate {

  private OrderRestService orderRestServiceL;

  public OrderRestService getOrderRestServiceL() {
    return orderRestServiceL;
  }

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

关于java - Bean 引用为空,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29685381/

相关文章:

java - 如何等待JDO中的事务结束?

java - Spring RMI刷新StubOnConnectFailure不工作

java - Java 中的方法重写抛出异常

Java接口(interface)扩展抽象类?

java - 从 java ws 返回复杂类型

java - Android RecyclerView : row swipe on click

spring - 使用 facebook 登录并使用 oauth 2.0 对 REST api 调用进行身份验证

java - EntityManager 不能使用 persist 将元素保存到数据库

java - Spring Boot、Spring Data JPA 具有多个 Hikari 数据源和单个数据源配置 Java 文件

java - 将解析后的 XML 对象加载到 Spring 上下文中