gpt4 book ai didi

java - HybrisContextFactory - 初始化全局应用程序上下文时出错

转载 作者:行者123 更新时间:2023-11-30 03:05:23 26 4
gpt4 key购买 nike

我尝试将应用程序的版本从 Hybris 4.8 迁移到 Hybris 5.6.0.5。

当服务器启动时,我遇到了这个异常:

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

因为在 FlexSelector 类中:

protected static final ApplicationContext ctx = Registry.getApplicationContext();

spring的应用上下文为null。如果有人有任何想法请告诉我。

最佳答案

对应用程序上下文进行静态引用并不是一个好主意。相反,正如 @thijsraets 建议的那样,您应该为 flexSelector 创建类(class)。 bean 具ApplicationContextAware 。例如:

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() 在静态方法中动态查找它。调用而不是将其存储在静态变量中。

关于java - HybrisContextFactory - 初始化全局应用程序上下文时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34922023/

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