gpt4 book ai didi

java - Bean 引用为空

转载 作者:行者123 更新时间:2023-11-30 03:28:12 25 4
gpt4 key购买 nike

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

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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com