2016-01-21 59 views
1

我嘗試將我的應用程序的版本從Hybris 4.8遷移到Hybris 5.6.0.5。HybrisContextFactory - 初始化全局應用程序上下文時出錯

服務器啓動時我有這樣的例外:

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(); 

彈簧的應用程序上下文爲null。 如果有人有任何想法,請告訴我。

+0

難道你不能只是讓類beanfactoryaware或applicationcontextaware? – thijsraets

+0

你可以發佈類CoopCSTicketFacade的內容嗎?或者至少是它的主要部分? – Juan

回答

1

擁有對應用程序上下文的靜態引用並不是一個好主意。 相反,由於@thijsraets建議您應該爲flexSelector豆類實現類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; 
    } 
    [...] 
} 

這將確保當bean是由Spring有線了應用程序上下文獲取設置。

如果您在FlexSelector中有靜態方法並且需要應用程序上下文,則應該始終通過Registry.getApplicationContext()調用動態查找靜態方法,而不是將其存儲在靜態變量中。

1

你真的只需要applicationContext對象嗎?如果你只是需要檢索這個bean,你可以這樣做:

final ManagerFactoryBean managerFactoryBean =(ManagerFactoryBean)Registry.getApplicationContext()。getBean(「managerFactoryBean」);

我也在hybris工作,這就是我如何獲得我的bean引用。