我有一个Spring启动应用程序,并公开了一个端点以基于OrderId获取OrderDetails。
但是,我们收到了 间歇性 "class org.springframework.beans.factory.BeanCreationException"
异常。
我无法找出问题所在。 任何帮助都会有很大帮助。有关了解该错误和故障排除方法的任何建议都可以帮助我更好地了解它。
方法签名
@Override
@Transactional
public Optional<OrderResponse> getOrder(String orderId) {
// logic to fetch data using JPA and Entities
}
错误:
com.temp.services.exception.tempSystemException: class org.springframework.beans.factory.BeanCreationException","params":"null","result":"{
"errorMessage": "class org.springframework.beans.factory.BeanCreationException",
"causedBy": "BeanFactory not initialized or already closed - call 'refresh' before accessing beans via the ApplicationContext",
"methodSignature": "Optional com.ros.cms.services.adapters.OrderService.getOrder(String)",
"methodParameters": "[\"1234567\"]"
}","payload":"null"}
堆栈跟踪如下:
Failed to invoke com.test.services.adapters.DefaultOrderService@39274073. (org.mule.api.MessagingException)
org.springframework.context.support.AbstractRefreshableApplicationContext.getBeanFactory(AbstractRefreshableApplicationContext.java:170)
org.springframework.context.support.AbstractApplicationContext.getBeansOfType(AbstractApplicationContext.java:1059)
org.springframework.beans.factory.BeanFactoryUtils.beansOfTypeIncludingAncestors(BeanFactoryUtils.java:227)
org.springframework.data.jpa.repository.config.JpaMetamodelMappingContextFactoryBean.getMetamodels(JpaMetamodelMappingContextFactoryBean.java:85)
org.springframework.data.jpa.repository.config.JpaMetamodelMappingContextFactoryBean.createInstance(JpaMetamodelMappingContextFactoryBean.java:56)
org.springframework.data.jpa.repository.config.JpaMetamodelMappingContextFactoryBean.createInstance(JpaMetamodelMappingContextFactoryBean.java:26)
org.springframework.beans.factory.config.AbstractFactoryBean.afterPropertiesSet(AbstractFactoryBean.java:134)
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1631)
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1568)
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:539)
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476)
org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:303)
org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:299)
org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:351)
org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:108)
org.springframework.beans.factory.support.ConstructorResolver.resolvePreparedArguments(ConstructorResolver.java:786)
org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:123)
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1137)
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1028)
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:504)
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476)
org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:303)
org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:299)
org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
org.springframework.beans.factory.config.ObjectFactoryCreatingFactoryBean$TargetBeanObjectFactory.getObject(ObjectFactoryCreatingFactoryBean.java:148)
org.springframework.data.jpa.domain.support.AuditingEntityListener.touchForUpdate(AuditingEntityListener.java:96)
sun.reflect.GeneratedMethodAccessor10756.invoke(null:-1)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
java.lang.reflect.Method.invoke(Method.java:498)
org.hibernate.jpa.event.internal.jpa.ListenerCallback.performCallback(ListenerCallback.java:49)
org.hibernate.jpa.event.internal.jpa.CallbackRegistryImpl.callback(CallbackRegistryImpl.java:112)
org.hibernate.jpa.event.internal.jpa.CallbackRegistryImpl.preUpdate(CallbackRegistryImpl.java:76)
org.hibernate.jpa.event.internal.core.JpaFlushEntityEventListener.invokeInterceptor(JpaFlushEntityEventListener.java:68)
org.hibernate.event.internal.DefaultFlushEntityEventListener.handleInterception(DefaultFlushEntityEventListener.java:342)
org.hibernate.event.internal.DefaultFlushEntityEventListener.scheduleUpdate(DefaultFlushEntityEventListener.java:293)
org.hibernate.event.internal.DefaultFlushEntityEventListener.onFlushEntity(DefaultFlushEntityEventListener.java:160)
org.hibernate.event.internal.AbstractFlushingEventListener.flushEntities(AbstractFlushingEventListener.java:231)
org.hibernate.event.internal.AbstractFlushingEventListener.flushEverythingToExecutions(AbstractFlushingEventListener.java:102)
org.hibernate.event.internal.DefaultAutoFlushEventListener.onAutoFlush(DefaultAutoFlushEventListener.java:61)
org.hibernate.internal.SessionImpl.autoFlushIfRequired(SessionImpl.java:1227)
org.hibernate.internal.SessionImpl.list(SessionImpl.java:1293)
org.hibernate.internal.QueryImpl.list(QueryImpl.java:103)
org.hibernate.jpa.internal.QueryImpl.list(QueryImpl.java:573)
org.hibernate.jpa.internal.QueryImpl.getResultList(QueryImpl.java:449)
org.springframework.data.jpa.repository.query.JpaQueryExecution$CollectionExecution.doExecute(JpaQueryExecution.java:110)
org.springframework.data.jpa.repository.query.JpaQueryExecution.execute(JpaQueryExecution.java:74)
org.springframework.data.jpa.repository.query.AbstractJpaQuery.doExecute(AbstractJpaQuery.java:99)
org.springframework.data.jpa.repository.query.AbstractJpaQuery.execute(AbstractJpaQuery.java:90)
org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.doInvoke(RepositoryFactorySupport.java:415)
org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.invoke(RepositoryFactorySupport.java:393)
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
org.springframework.data.repository.core.support.RepositoryFactorySupport$DefaultMethodInvokingMethodInterceptor.invoke(RepositoryFactorySupport.java:506)
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:99)
org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:281)
org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96)
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:136)
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
org.springframework.data.jpa.repository.support.CrudMethodMetadataPostProcessor$CrudMethodMetadataPopulatingMethodIntercceptor.invoke(CrudMethodMetadataPostProcessor.java:122)
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92)
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:207)
com.sun.proxy.$Proxy808.getItemlookup(null:-1)
com.abc.services.adapters.DefaultOrderService.getOrder(DefaultOrderService.java:136)
sun.reflect.GeneratedMethodAccessor10790.invoke(null:-1)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
java.lang.reflect.Method.invoke(Method.java:498)
org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:317)
org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:190)
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157)
org.springframework.aop.aspectj.AspectJAfterThrowingAdvice.invoke(AspectJAfterThrowingAdvice.java:58)
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
org.springframework.aop.framework.adapter.MethodBeforeAdviceInterceptor.invoke(MethodBeforeAdviceInterceptor.java:52)
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
org.springframework.aop.aspectj.AspectJAfterAdvice.invoke(AspectJAfterAdvice.java:43)
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:99)
org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:281)
org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96)
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92)
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:207)
com.sun.proxy.$Proxy811.getOrder(null:-1)
sun.reflect.GeneratedMethodAccessor10789.invoke(null:-1)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
java.lang.reflect.Method.invoke(Method.java:498)
org.mule.processor.InvokerMessageProcessor.process(InvokerMessageProcessor.java:167)
org.mule.execution.ExceptionToMessagingExceptionExecutionInterceptor.execute(ExceptionToMessagingExceptionExecutionInterceptor.java:27)
org.mule.execution.MessageProcessorNotificationExecutionInterceptor.execute(MessageProcessorNotificationExecutionInterceptor.java:111)
POM.XML
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-oracle</artifactId>
<version>1.2.1.RELEASE</version>
</dependency>
<dependency>
<groupId>commons-beanutils</groupId>
<artifactId>commons-beanutils</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-test</artifactId>
<version>${spring.security.test.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
默认服务等级:
@Override
@Transactional
public Optional<OrderResponse> getOrder(String orderId) {
try {
Optional<OrderEntity> order =orderRepository.getByOrderNo(orderId);
if(order.isPresent())
{
List<OrderItemEntity> items = orderItemRepository.findByIdOrderNo(orderId);
for(OrderItemEntity i:items) {
List<ItemSupplierEntity> itemSupp = itemSupplierRepository
.getItemlookup(order.get().getOrderNo(), i.getId().getItem(),
order.get().getSupplier().getId());
ItemSupplierEntity itemExp = (ItemSupplierEntity) itemSupplierRepository
.getExpDetail(i.getId().getItem(),
Long.valueOf(order.get().getSupplier().getId()));
if (null != itemSupp && null != itemExp) {
itemSupp.stream().forEach(sup->{
sup.setLoad(itemExp.getLoad());
sup.setCommission(itemExp.getCommission());
sup.setRoyalty(itemExp.getRoyalty());
sup.setFreight(itemExp.getFreight());
sup.setDuty(itemExp.getDuty());
});
}
i.getItemmaster().setItemSuppList(itemSupp);
Optional<ItemMasterEntity> optItemMaster =null;
if(null != i.getId() && null != i.getId().getItem()) {
optItemMaster = itemMasterRepo.getSizeGroup(i.getId().getItem());
}
logger.info("optItemMaster : "+optItemMaster);
if(null != optItemMaster && optItemMaster.isPresent()) {
ItemMasterEntity itemMaster = optItemMaster.get();
logger.info("itemMaster "+itemMaster.toString());
i.getItemmaster().setSizeGroup(itemMaster.getSizeGroup());
i.getItemmaster().setSizeGroupDesc(itemMaster.getSizeGroupDesc());
}
List<PackItemEntity> packItemList = i.getItemmaster().getPackItemList();
if(!packItemList.isEmpty()) {
logger.info("Iterating through each component if this is a pack");
for (PackItemEntity comp : packItemList) {
logger.info("Getting ComponentItem's SizeGroup");
if(itemMasterRepo.getSizeGroup(comp.getId().getItem()).isPresent()) {
Optional<ItemMasterEntity> compIme = itemMasterRepo.getSizeGroup(comp.getId().getItem());
comp.getItemmaster().setSizeGroup(compIme.get().getSizeGroup());
comp.getItemmaster().setSizeGroupDesc(compIme.get().getSizeGroupDesc());
}
}
}
}
order.get().setItems(items);
OrderResponse orderResp = orderRepository.wrap(order.get());
for(int i = 0; i < orderResp.getItems().size(); i++) {
OrderItemResponse orderItemResp = orderResp.getItems().get(i);
orderItemResp.setRecNo(String.valueOf(i+1));
if(null!=orderItemResp && orderItemResp.getComp()) {
List<ItemSuppCountryLocEntity> ordloc = itemSuppCountryLocRepo.getItemHtsDetails(orderResp.getOrderNo(), orderItemResp.getPackNo());
if(null != ordloc && !ordloc.isEmpty()) {
ItemLocId itemLocId = new ItemLocId();
itemLocId.setItem(orderItemResp.getItem());
itemLocId.setLoc(ordloc.stream().findFirst().get().getItemSuppCountryLocId().getLocation());
ItemLocEntity itemLoc = itemLocRepo.findOne(itemLocId);
if(null != itemLoc)
orderItemResp.setRetail(itemLoc.getRetail());
}
}
}
Optional<OrderResponse> orderResponse = Optional.of(orderResp);
return orderResponse;
}
}catch(org.springframework.beans.factory.BeanCreationException e) {
if ( this.appContext.getParent() != null) {
this.appContext.getParent().getAutowireCapableBeanFactory();
}else {
this.appContext.getAutowireCapableBeanFactory();
}
}
return Optional.empty();
}