我尝试将我的应用程序版本从Hybris 4.8迁移到Hybris 5.6.0.5。
当服务器启动时,我有这个例外:
JSONObject jsonObject = new JSONObject("jsonResponse");
JSONArray jsonArr= jsonObj.getJSONArray("destination_addresses");
String[] arrDestinations=new String[jsonArr.lLength()];
for(int i=0;i<jsonArr.length();i++)
arrDestinations[i]=jsonArr.get(i);
jsonArr= jsonObj.getJSONArray("origin_addresses");
String[] arrOrigins=new String[jsonArr.lLength()];
for(int i=0;i<jsonArr.length();i++)
arrOrigins[i]=jsonArr.get(i);
JSONArray rows = jsonObj.getJSONArray("rows");
for(int i =0; i < rows.length(); i++)
{
JSONObject rowObj = rows.getJSONObject(i);
JSONArray rowElements = rowObj.getJSONArray("elements");
for(int element = 0; element < rowElements.length(); element++) {
// get the elements and parse
}
}
因为在FlexSelector类中:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'csTicketFacade' defined in class path resource [CoopAcceleratorFrontEndfacades-spring.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [com.accenture.hybris.facades.customerservice.impl.CoopCSTicketFacade]: Constructor threw exception; nested exception is java.lang.NullPointerException
INFO | jvm 1 | main | 2016/01/20 11:41:54.777 | Caused by: java.lang.NullPointerException
INFO | jvm 1 | main | 2016/01/20 11:41:54.790 | at com.accenture.facades.common.FlexSelector.getPropertiesReader(FlexSelector.java:27)
INFO | jvm 1 | main | 2016/01/20 11:41:54.797 | at com.accenture.hybris.facades.customerservice.impl.CoopCSTicketFacade$TicketFlexSelector.getCsAgentGroupUID(CoopCSTicketFacade.java:68)
INFO | jvm 1 | main | 2016/01/20 11:41:54.805 | at com.accenture.hybris.facades.customerservice.impl.CoopCSTicketFacade$TicketFlexSelector.getCsAgentGroupModel(CoopCSTicketFacade.java:31)
INFO | jvm 1 | main | 2016/01/20 11:41:54.809 | at com.accenture.hybris.facades.customerservice.impl.CoopCSTicketFacade.<init>(CoopCSTicketFacade.java:80)
INFO | jvm 1 | main | 2016/01/20 11:41:54.820 | at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
INFO | jvm 1 | main | 2016/01/20 11:41:54.823 | at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
INFO | jvm 1 | main | 2016/01/20 11:41:54.828 | at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
INFO | jvm 1 | main | 2016/01/20 11:41:54.834 | at java.lang.reflect.Constructor.newInstance(Constructor.java:422)
INFO | jvm 1 | main | 2016/01/20 11:41:54.838 | at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:148)
INFO | jvm 1 | main | 2016/01/20 11:41:54.843 | ... 35 more
spring的应用程序上下文为null。 如果有人有任何想法,请告诉我。
答案 0 :(得分:1)
对应用程序上下文进行静态引用并不是一个好主意。
相反,正如@thijsraets建议你应该为flexSelector
bean实现ApplicationContextAware
创建类。
E.g:
public class FlexSelector implements ApplicationContextAware {
ApplicationContext context;
public ApplicationContext getContext() {
return context;
}
@Override
public void setApplicationContext(ApplicationContext context)
throws BeansException {
this.context=context;
}
[...]
}
这将确保在Spring连接bean时设置应用程序上下文。
如果您在FlexSelector
中有静态方法并且需要应用程序上下文,则应始终通过Registry.getApplicationContext()
调用在静态方法中动态查找,而不是将其存储在静态变量中
答案 1 :(得分:1)
你真的只需要applicationContext对象吗?如果你只需要检索bean,你可以像下面这样做:
final ManagerFactoryBean managerFactoryBean =(ManagerFactoryBean)Registry.getApplicationContext()。getBean(“managerFactoryBean”);
我也在hybris工作,这就是我的bean引用方式。