EJB3 interceptor cannot load context

I am trying to introduce Spring beans in EJB using @Interceptors (SpringBeanAutowiringInterceptor.class)

Here is my EJB:

@Stateless @Interceptors(SpringBeanAutowiringInterceptor.class) public class processMethodService implements processMethodService { @Autowired private SomeBean bean; @Schedule(minute = "*/5", hour = "*", persistent = false) @TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED) public void startProcessing() { //businesslogic } } 

And beanRefContext.xml as follows

 <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd"> <bean id="ejb-businesslayer.application.context" lazy-init="true" class="org.springframework.context.support.ClassPathXmlApplicationContext"> <constructor-arg> <list> <value>classpath:/META-INF/spring-config.xml</value> </list> </constructor-arg> </bean> ` 

beanRefContext.xml, spring -config.xml are in the META-INF folder.

when startProcessing is called every 5 minutes and we get an exception below

 Exception data: javax.ejb.EJBException: session bean lifecycle interceptor failure;nested exception is:org.springframework.beans.factory.access.BootstrapException: Unable to return specified BeanFactory instance: factory key [null], from group with resource name [classpath*:beanRefContext.xml]; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [org.springframework.beans.factory.BeanFactory] is defined 

Please find the complete exception as below

 Exception data: javax.ejb.EJBException: session bean lifecycle interceptor failure;nested exception is: org.springframework.beans.factory.access.BootstrapException: Unable to return specified BeanFactory instance: factory key [null], from group with resource name [classpath*:beanRefContext.xml]; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [org.springframework.beans.factory.BeanFactory] is defined`enter code here` at com.ibm.ejs.container.util.ExceptionUtil.EJBException(ExceptionUtil.java:466) at com.ibm.ejs.container.SessionBeanO.callLifecycleInterceptors(SessionBeanO.java:288) at com.ibm.ejs.container.StatelessBeanO.initialize(StatelessBeanO.java:399) at com.ibm.ejs.container.BeanOFactory.create(BeanOFactory.java:147) at com.ibm.ejs.container.EJSHome.createBeanO(EJSHome.java:1238) at com.ibm.ejs.container.EJSHome.createBeanO(EJSHome.java:1356) at com.ibm.ejs.container.activator.UncachedActivationStrategy.atActivate(UncachedActivationStrategy.java:88) at com.ibm.ejs.container.activator.Activator.preInvokeActivateBean(Activator.java:615) at com.ibm.ejs.container.EJSContainer.preInvokeActivate(EJSContainer.java:4205) at com.ibm.ejs.container.EJSContainer.EjbPreInvoke(EJSContainer.java:3535) at com.ibm.ejs.container.TimedObjectWrapper.invokeCallback(TimedObjectWrapper.java:110) at com.ibm.ejs.container.TimerNpListener.doWork(TimerNpListener.java:293) at com.ibm.ejs.container.TimerNpListener.doWorkWithRetries(TimerNpListener.java:171) at com.ibm.ejs.container.TimerNpListener.fired(TimerNpListener.java:141) at com.ibm.ws.asynchbeans.AlarmImpl.callListenerMethod(AlarmImpl.java:427) at com.ibm.ws.asynchbeans.timer.GenericTimer.run(GenericTimer.java:228) at com.ibm.ws.asynchbeans.J2EEContext.run(J2EEContext.java:1178) at com.ibm.ws.asynchbeans.AlarmImpl.runListenerAsCJWork(AlarmImpl.java:249) at com.ibm.ws.asynchbeans.am._Alarm.fireAlarm(_Alarm.java:333) at com.ibm.ws.asynchbeans.am._Alarm.run(_Alarm.java:230) at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:1783) Caused by: org.springframework.beans.factory.access.BootstrapException: Unable to return specified BeanFactory instance: factory key [null], from group with resource name [classpath*:beanRefContext.xml]; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [org.springframework.beans.factory.BeanFactory] is defined at org.springframework.beans.factory.access.SingletonBeanFactoryLocator.useBeanFactory(SingletonBeanFactoryLocator.java:402) at org.springframework.ejb.interceptor.SpringBeanAutowiringInterceptor.getBeanFactoryReference(SpringBeanAutowiringInterceptor.java:160) at org.springframework.ejb.interceptor.SpringBeanAutowiringInterceptor.getBeanFactory(SpringBeanAutowiringInterceptor.java:141) at org.springframework.ejb.interceptor.SpringBeanAutowiringInterceptor.doAutowireBean(SpringBeanAutowiringInterceptor.java:121) at org.springframework.ejb.interceptor.SpringBeanAutowiringInterceptor.autowireBean(SpringBeanAutowiringInterceptor.java:95) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:88) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:55) at java.lang.reflect.Method.invoke(Method.java:613) at com.ibm.ejs.container.interceptors.InterceptorProxy.invokeInterceptor(InterceptorProxy.java:227) at com.ibm.ejs.container.interceptors.InvocationContextImpl.proceed(InvocationContextImpl.java:548) at com.ibm.ejs.container.interceptors.InvocationContextImpl.doLifeCycle(InvocationContextImpl.java:273) at com.ibm.ejs.container.SessionBeanO.callLifecycleInterceptors(SessionBeanO.java:274) 

Read how to resolve this error.

+5
source share
2 answers

ContextSingletonBeanFactoryLocator is looking for the path to the resource class *: beanRefContext.xml, so the beanRefContext.xml file must be in the class path, ref this link ,

Move beanRefContext.xml to a folder that is on the class path and that should fix the problem.

0
source

Firstly, I think the removal of META-INF should help. In addition, I just solved the same problem by moving the context in question to the / resources directory

0
source

Source: https://habr.com/ru/post/1207965/


All Articles