autowiring jee-jdni-lookup datasource entry in spring-config to #repository dao impl class - spring

I am using #repository annotation for DAO impl classes but not able to #autowire or #resource the datasource defined in beanRefContext.xml configuration as
jee:jndi-lookup tag
I have all the required tag entries in place, like annotation and component package scan
<jee:jndi-lookup id="dataSource" jndi-name="jdbc/xyzName"
cache="true" resource-ref="true" lookup-on-startup="false"
proxy-interface="javax.sql.DataSource" />
I tried following in #Repository impl class,
#Resource(mappedName="jdbc/xyzName")
private DataSource dataSource;
#Resource(name="datasource")
private DataSource dataSource;
#Autowired
private DataSource dataSource;
Please help!
######### Main xml file ##########
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:jee="http://www.springframework.org/schema/jee"
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.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.0.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd">
<!-- This will automatically declare several post-processors
including the AutowiredAnnotationBeanPostProcessor -->
<context:annotation-config/>
<context:component-scan base-package="com.domain"/>
<bean id="context" lazy-init="true"
class="org.springframework.context.support.ClassPathXmlApplicationContext">
<constructor-arg value="ejbBeans.xml" />
</bean>
</beans>
########## EJB beans xml file ################
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:jee="http://www.springframework.org/schema/jee"
xmlns:tx="http://www.springframework.org/schema/tx" xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.0.xsd">
<tx:annotation-driven transaction-manager="someTransactionManager" />
<bean
class="org.springframework.context.annotation.CommonAnnotationBeanPostProcessor">
<property name="alwaysUseJndiLookup" value="true" />
</bean>
<bean id="someTransactionManager"
class="org.springframework.transaction.jta.WebSphereUowTransactionManager">
</bean>
<jee:jndi-lookup id="dataSource" jndi-name="jdbc/xyzName"
cache="true" resource-ref="true" lookup-on-startup="false"
proxy-interface="javax.sql.DataSource" />
</beans>
Now getting below exception java.lang.IllegalArgumentException: 'dataSource' or 'jdbcTemplate' is required..the below is the code for my DAOImpl class
#Repository
public class UtilityDAOImpl extends JdbcDaoSupport implements
UtilityDAO {
final String className = UtilityDAOImpl.class.getName();
private JdbcTemplate jdbcTemplate ;
#Autowired
#Qualifier("dataSource")
public void setJdbcTemplate(DataSource dataSource) {
this.jdbcTemplate = new JdbcTemplate(dataSource);
}
EDIT: Got this exception
; nested exception is: org.springframework.beans.factory.access.BootstrapException: Unable to initialize group definition. Group resource name [classpath*:beanRefContext.xml], factory key [null]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'ProgramEligiblityEventCheckController': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com...domain.dao.vista.VistaEligiblityEventDAO com...domain.core.claim.ProgramEligiblityEventCheckController.vistaEligiblityEventDAO; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'vistaEligiblityEventDAOImpl': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com...domain.dao..UtilityDAO com...domain.dao.vista.impl.VistaEligiblityEventDAOImpl.utilityDAO; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'UtilityDAOImpl' defined in file [C:\workspace_1.2\ejb12\ejbModule\com\\\domain\dao\\impl\UtilityDAOImpl.class]: Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: 'dataSource' or 'jdbcTemplate' is required
org.springframework.beans.factory.access.BootstrapException: Unable to initialize group definition. Group resource name [classpath*:beanRefContext.xml], factory key [null]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'ProgramEligiblityEventCheckController': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com...domain.dao.vista.VistaEligiblityEventDAO com...domain.core.claim.ProgramEligiblityEventCheckController.vistaEligiblityEventDAO; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'vistaEligiblityEventDAOImpl': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com...domain.dao..UtilityDAO com...domain.dao.vista.impl.VistaEligiblityEventDAOImpl.utilityDAO; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'UtilityDAOImpl' defined in file [C:\workspace_1.2\ejb12\ejbModule\com\\\domain\dao\\impl\UtilityDAOImpl.class]: Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: 'dataSource' or 'jdbcTemplate' is required
at org.springframework.beans.factory.access.SingletonBeanFactoryLocator.useBeanFactory(SingletonBeanFactoryLocator.java:386)
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:48)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:37)
at java.lang.reflect.Method.invoke(Method.java:600)
at com.ibm.ejs.container.interceptors.InterceptorProxy.invokeInterceptor(InterceptorProxy.java:227)
at com.ibm.ejs.container.interceptors.InvocationContextImpl.proceed(InvocationContextImpl.java:566)
at com.ibm.ejs.container.interceptors.InvocationContextImpl.doLifeCycle(InvocationContextImpl.java:264)
at com.ibm.ejs.container.SessionBeanO.callPostConstructInterceptors(SessionBeanO.java:260)
at com.ibm.ejs.container.StatelessBeanO.initialize(StatelessBeanO.java:409)
at com.ibm.ejs.container.CMStatelessBeanOFactory.create(CMStatelessBeanOFactory.java:45)
at com.ibm.ejs.container.EJSHome.createBeanO(EJSHome.java:1031)
at com.ibm.ejs.container.EJSHome.createBeanO(EJSHome.java:1141)
at com.ibm.ejs.container.activator.UncachedActivationStrategy.atActivate(UncachedActivationStrategy.java:84)
at com.ibm.ejs.container.activator.Activator.activateBean(Activator.java:599)
at com.ibm.ejs.container.EJSContainer.preInvokeActivate(EJSContainer.java:3964)
at com.ibm.ejs.container.EJSContainer.EjbPreInvoke(EJSContainer.java:3349)
at com..domain.ejb.facade.EJSRemote0SLExternalRequestDelegatorFacad_35bfd46c.processRequest(EJSRemote0SLExternalRequestDelegatorFacad_35bfd46c.java)
at com..domain.ejb.facade._EJSRemote0SLExternalRequestDelegatorFacad_35bfd46c_Tie.processRequest(_EJSRemote0SLExternalRequestDelegatorFacad_35bfd46c_Tie.java)
at com..domain.ejb.facade._EJSRemote0SLRequestDelegatorFacad_35bfd46c_Tie._invoke(_EJSRemote0SLExternalRequestDelegatorFacad_35bfd46c_Tie.java)
at com.ibm.CORBA.iiop.ServerDelegate.dispatchInvokeHandler(ServerDelegate.java:622)
at com.ibm.CORBA.iiop.ServerDelegate.dispatch(ServerDelegate.java:475)
at com.ibm.rmi.iiop.ORB.process(ORB.java:513)
at com.ibm.CORBA.iiop.ORB.process(ORB.java:1574)
at com.ibm.rmi.iiop.Connection.respondTo(Connection.java:2841)
at com.ibm.rmi.iiop.Connection.doWork(Connection.java:2714)
at com.ibm.rmi.iiop.WorkUnitImpl.doWork(WorkUnitImpl.java:63)
at com.ibm.ejs.oa.pool.PooledThread.run(ThreadPool.java:118)
at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:1550)
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'ProgramEligiblityEventCheckController': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com...domain.dao.vista.VistaEligiblityEventDAO com.domain.core.claim.ProgramEligiblityEventCheckController.vistaEligiblityEventDAO; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'vistaEligiblityEventDAOImpl': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com...domain.dao..UtilityDAO com...domain.dao.vista.impl.VistaEligiblityEventDAOImpl.utilityDAO; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'UtilityDAOImpl' defined in file [C:\workspace_1.2\ejb12\ejbModule\com\\\domain\dao\\impl\UtilityDAOImpl.class]: Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: 'dataSource' or 'jdbcTemplate' is required
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:288)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1120)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:522)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:461)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:295)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:292)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:626)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:932)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:479)
at org.springframework.context.access.ContextSingletonBeanFactoryLocator.initializeDefinition(ContextSingletonBeanFactoryLocator.java:143)
at org.springframework.beans.factory.access.SingletonBeanFactoryLocator.useBeanFactory(SingletonBeanFactoryLocator.java:381)
... 32 more
And the class in question
#Repository
public class TempUtilityDAOImpl extends JdbcDaoSupport implements
TempUtilityDAO {
final String className = TempUtilityDAOImpl.class.getName();
private JdbcTemplate jdbcTemplate ;
#Autowired
#Qualifier("dataSource")
public void setJdbcTemplate(DataSource dataSource) {
this.jdbcTemplate = new JdbcTemplate(dataSource);
}
private static String IS_DEALER_IN_Temp = "select count(id_dlr) from "
+ TempConstants.DB_NAME_Temp + "V_Temp_DLR where id_dlr = ? with UR";
/**
* Method verifies that Dealer is not an Canadian dealer.
*
* #param dealerID
* #return
* #throws TempSystemException
*/
public boolean verifyTempDealer(String dealerID) throws TempSystemException {
boolean isTempDealer = false;
final String methodName = "verifyTempDealer(String dealerID)";
MSLog.debug(className, "Exiting Method : " + methodName);
int rowcount = getJdbcTemplate().queryForInt(IS_DEALER_IN_Temp,
dealerID);
if (rowcount > 0) {
isTempDealer = true;
}
MSLog.debug(className, "Exiting Method : " + methodName);
return isTempDealer;
}
}

I don't know that
<bean id="context" lazy-init="true"
class="org.springframework.context.support.ClassPathXmlApplicationContext">
<constructor-arg value="ejbBeans.xml" />
</bean>
can import beans from one context to another.
You should use
<import resource="ejbBeans.xml"/>
All beans declared in ejbBeans.xml will then be available in your importing context.

Related

Spring BeanPostProcessor BeanCreationException runtime error

I'm unable to launch hello world app with Spring 4.3.6 Please, help, I don't even know what may be wrong.
Without bean messageService and aop section everything works. But I got this error with config as it is
WARNING: Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'printer' defined in class path resource [config.xml]: BeanPostProcessor before instantiation of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.aop.aspectj.AspectJPointcutAdvisor#0': Cannot create inner bean '(inner bean)#c273d3' of type [org.springframework.aop.aspectj.AspectJMethodBeforeAdvice] while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)#c273d3': Cannot create inner bean '(inner bean)#1423665' of type [org.springframework.aop.config.MethodLocatingFactoryBean] while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)#1423665': Initialization of bean failed; nested exception is org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [MessagePrinterService] for bean with name 'messageService' defined in class path resource [config.xml]; nested exception is java.lang.ClassNotFoundException: MessagePrinterService
Related cause: org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [MessagePrinterService] for bean with name 'messageService' defined in class path resource [config.xml]; nested exception is java.lang.ClassNotFoundException: MessagePrinterService
Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'printer' defined in class path resource [config.xml]: BeanPostProcessor before instantiation of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.aop.aspectj.AspectJPointcutAdvisor#0': Cannot create inner bean '(inner bean)#c273d3' of type [org.springframework.aop.aspectj.AspectJMethodBeforeAdvice] while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)#c273d3': Cannot create inner bean '(inner bean)#1423665' of type [org.springframework.aop.config.MethodLocatingFactoryBean] while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)#1423665': Initialization of bean failed; nested exception is org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [MessagePrinterService] for bean with name 'messageService' defined in class path resource [config.xml]; nested exception is java.lang.ClassNotFoundException: MessagePrinterService
Related cause: org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [MessagePrinterService] for bean with name 'messageService' defined in class path resource [config.xml]; nested exception is java.lang.ClassNotFoundException: MessagePrinterService
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:479)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
Xml config:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop.xsd">
<bean id="printer" class="helloword.MessagePrinter">
<constructor-arg ref="message"></constructor-arg>
</bean>
<bean id="message" class="helloword.HelloWordMessage">
<constructor-arg value="Hello Spring World!"></constructor-arg>
</bean>
<bean id="messageService" class="MessagePrinterService">
</bean>
<aop:config>
<aop:aspect ref="messageService">
<aop:pointcut id="print" expression="execution(* *.print(..))"/>
<aop:before pointcut-ref="print" method="preMsg"/>
<aop:after pointcut-ref="print" method="postMsg"/>
</aop:aspect>
</aop:config>
</beans>
Classes, all is separate files:
public class HelloWordMessage implements Message{
private String msg;
public HelloWordMessage(String s) {
msg = s;
}
#Override
public String getText() {
return msg;
}
}
public class MessagePrinter implements Printer {
private Message msg;
public MessagePrinter(Message m){
msg = m;
}
#Override
public void print(){
System.out.println(msg.getText());
}
}
public class MessagePrinterService {
public MessagePrinterService(){
System.out.println("MessagePrinterService created");
}
public void preMsg(){
System.out.println("Message alert!:");
}
public void postMsg(){
System.out.println("End of message.");
}
}
public class Aplication {
public static void main(String[] args) {
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("config.xml");
MessagePrinter printer = context.getBean(MessagePrinter.class);
printer.print();
context.close();
}
}
java.lang.ClassNotFoundException: MessagePrinterService
Spring cannot load the class MessagePrinterService.
Put it into a specific package and change the configuration accordingly. It should work then.

EJB3 interceptor cannot bootstrap context

I'm trying to inject Spring beans into an EJB using
#Interceptors(SpringBeanAutowiringInterceptor.class)
Here's 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 under META-INF folder.
when startProcessing is called for every 5 minutes and we are getting the below exception
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)
Please guide me on how to resolve this error
The ContextSingletonBeanFactoryLocator is looking for resource classpath*:beanRefContext.xml, so the beanRefContext.xml file has to be in the classpath, ref this link,
Move beanRefContext.xml into a folder that's in the class path and that should solve the problem.
First off, I think removing META-INF should help. Also, I just solved this same issue by moving context in question to /resources directory

creating custom ItemReader with defaultLineMapper using spring annotations

I am trying to make a annotation based ItemReader in spring-batch. I was able to make the desired ItemReader in my xml but annotation based is not at all working giving the following error:
Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'runScheduler': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.springframework.batch.core.Job com.techavalanche.batch.RunScheduler.job; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'reportJob': Cannot create inner bean '(inner bean)#3f9bb1' of type [org.springframework.batch.core.configuration.xml.SimpleFlowFactoryBean] while setting bean property 'flow'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)#3f9bb1': Cannot create inner bean '(inner bean)#17e6f05' of type [org.springframework.batch.core.job.flow.support.StateTransition] while setting bean property 'stateTransitions' with key [0]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)#17e6f05': Cannot create inner bean '(inner bean)#66da50' of type [org.springframework.batch.core.job.flow.support.state.StepState] while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)#66da50': Cannot resolve reference to bean 'step1' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'step1': Cannot resolve reference to bean 'customItemReader' while setting bean property 'itemReader'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'customItemReader': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: public org.springframework.batch.item.file.FlatFileItemReader com.techavalanche.reader.CustomReader.itemReader; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'getFlatFileItemReader' defined in class path resource [com/techavalanche/reader/CustomReader.class]: Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: LineMapper is required
and it is caused by :
Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.springframework.batch.core.Job com.techavalanche.batch.RunScheduler.job; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'reportJob': Cannot create inner bean '(inner bean)#3f9bb1' of type [org.springframework.batch.core.configuration.xml.SimpleFlowFactoryBean] while setting bean property 'flow'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)#3f9bb1': Cannot create inner bean '(inner bean)#17e6f05' of type [org.springframework.batch.core.job.flow.support.StateTransition] while setting bean property 'stateTransitions' with key [0]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)#17e6f05': Cannot create inner bean '(inner bean)#66da50' of type [org.springframework.batch.core.job.flow.support.state.StepState] while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)#66da50': Cannot resolve reference to bean 'step1' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'step1': Cannot resolve reference to bean 'customItemReader' while setting bean property 'itemReader'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'customItemReader': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: public org.springframework.batch.item.file.FlatFileItemReader com.techavalanche.reader.CustomReader.itemReader; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'getFlatFileItemReader' defined in class path resource [com/techavalanche/reader/CustomReader.class]: Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: LineMapper is required
My CustomReader is
package com.techavalanche.reader;
#Component("customReader")
public class CustomReader implements ItemReader<Report> {
#Autowired
public FlatFileItemReader<Report> itemReader;
#Bean
public FlatFileItemReader getFlatFileItemReader(){
return new FlatFileItemReader();
}
#Bean
public DefaultLineMapper getDefaultLineMapper(){
return new DefaultLineMapper();
}
#Autowired
public DefaultLineMapper<Report> lineMapper;
#Bean
public FixedLengthTokenizer getLinetokenizer(){
return new FixedLengthTokenizer();
}
#Autowired
public FixedLengthTokenizer linetokenizer;
#Bean
public BeanWrapperFieldSetMapper getBeanWrapperFieldSetMapper() {
return new BeanWrapperFieldSetMapper();
}
#Autowired
public BeanWrapperFieldSetMapper<Report> fieldSetMapper;
public Resource res=new FileSystemResource("D:\\testresource\\report.csv");
String[] names= {"date","impressions","clicks","earning"};
#Override
public Report read() throws Exception, UnexpectedInputException, ParseException,
NonTransientResourceException {
for(String name:names){
System.out.println(name);
}
linetokenizer.setNames(new String[] {"date","impressions","clicks","earning"});
Range range1=new Range(1,12);
Range range2=new Range(13,15);
Range range3=new Range(16,20);
Range range4=new Range(21,28);
Range[] ranges={range1,range2,range3,range4};
linetokenizer.setColumns(ranges);
lineMapper.setLineTokenizer(linetokenizer);
fieldSetMapper.setPrototypeBeanName("report");
lineMapper.setFieldSetMapper(fieldSetMapper);
itemReader.setResource(res);
itemReader.setLineMapper(lineMapper);
itemReader.open(new ExecutionContext());
Report report= itemReader.read();
return report;
}
}
My Xml Configuration looks like this:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:batch="http://www.springframework.org/schema/batch"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:task="http://www.springframework.org/schema/task" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/batch
http://www.springframework.org/schema/batch/spring-batch-2.2.xsd
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
http://www.springframework.org/schema/task
http://www.springframework.org/schema/task/spring-task-3.2.xsd
">
<context:component-scan base-package="com.techavalanche" />
<bean id="jobRepository"
class="org.springframework.batch.core.repository.support.MapJobRepositoryFactoryBean">
<property name="transactionManager" ref="transactionManager" />
</bean>
<bean id="transactionManager"
class="org.springframework.batch.support.transaction.ResourcelessTransactionManager" />
<bean id="jobLauncher"
class="org.springframework.batch.core.launch.support.SimpleJobLauncher">
<property name="jobRepository" ref="jobRepository" />
</bean>
<bean id="report" class="com.techavalanche.batch.Report" scope="prototype" />
<bean id="customWriter" class="com.techavalanche.writer.CustomWriter" />
<batch:job id="reportJob">
<batch:step id="step1">
<batch:tasklet>
<batch:chunk reader="customItemReader" writer="customWriter"
commit-interval="2">
</batch:chunk>
</batch:tasklet>
</batch:step>
</batch:job>
<bean id="multiResourceReader"
class=" org.springframework.batch.item.file.MultiResourceItemReader">
<property name="resources" value="file:D:\testresource\report.csv" />
<property name="delegate" ref="cvsFileItemReader" />
</bean>
<bean id="customItemReader" class="com.techavalanche.reader.CustomReader" />
<bean id="cvsFileItemReader" class="org.springframework.batch.item.file.FlatFileItemReader">
<!-- Read a csv file -->
<!-- <property name="resource" ref="resource" /> -->
<property name="lineMapper">
<bean class="org.springframework.batch.item.file.mapping.DefaultLineMapper">
<!-- split it -->
<property name="lineTokenizer">
<bean id="fixedLengthLineTokenizer"
class="org.springframework.batch.item.file.transform.FixedLengthTokenizer">
<property name="names" value="date,impressions,clicks,earning" />
<property name="columns" value="1-12,13-15,16-20,21-28" />
</bean>
</property>
<property name="fieldSetMapper">
<!-- return back to reader, rather than a mapped object. -->
<!-- <bean class="org.springframework.batch.item.file.mapping.PassThroughFieldSetMapper"
/> -->
<!-- map to an object -->
<bean
class="org.springframework.batch.item.file.mapping.BeanWrapperFieldSetMapper">
<property name="prototypeBeanName" value="report" />
</bean>
</property>
</bean>
</property>
</bean>
</beans>

Starting asynchronous task via Spring TaskScheduler

I need to execute a task at 7.05am but I am getting an error.
This is the Controller I created.
#Service("myCtr")
public class MyController {
#Autowired
private TaskScheduler scheduler;
#Async
public void executeTaskT() {
scheduler.schedule(new MyWorker(),
new CronTrigger("5 7 * * *"));
}
}
MyWorker is implementing Runnable simply this way:
[...]
#Override
public void run() {
doWork();
}
private void doWork() { [...]
My scheduler configuration file is imported by the web-application-config.xml:
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd">
<bean id="TaskScheduler"
class="org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler">
<property name="waitForTasksToCompleteOnShutdown" value="true" />
<property name="poolSize" value="1000" />
</bean>
</beans>
The error:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'MyCtr': Injection
of autowired dependencies failed; nested exception is
org.springframework.beans.factory.BeanCreationException: Could not autowire field: private
org.springframework.scheduling.TaskScheduler [...].MyController.scheduler; nested
exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type
[org.springframework.scheduling.TaskScheduler] found for dependency: expected at least 1 bean which
qualifies as autowire candidate for this dependency. Dependency annotations:
{#org.springframework.beans.factory.annotation.Autowired(required=true)}
[...]
Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: private
org.springframework.scheduling.TaskScheduler [...].MyController.scheduler; nested
exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type
[org.springframework.scheduling.TaskScheduler] found for dependency: expected at least 1 bean which
qualifies as autowire candidate for this dependency. Dependency annotations:
{#org.springframework.beans.factory.annotation.Autowired(required=true)}
[...]
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type
[org.springframework.scheduling.TaskScheduler] found for dependency: expected at least 1 bean which
qualifies as autowire candidate for this dependency. Dependency annotations:
{#org.springframework.beans.factory.annotation.Autowired(required=true)}
It appears that Spring can't find your TaskScheduler bean.
With INFO logging, you should be able to find your bean definition in the log during initialization. If not, make sure your configuration file is effectively read by doing further tests.
For your precise need, you can also use the following:
#Service
public class MyService {
#Scheduled(cron = "0 5 7 * * *")
public void myMethod() { ... }
}
With this configuration:
<task:annotation-driven scheduler="myScheduler"/>
<task:scheduler id="myScheduler" pool-size="1000"/>
And assuming MyService is properly seen as a bean, using e.g. Component Scan.

java.lang.NoSuchMethodError: org.neo4j.kernel.impl.transaction.SpringTransactionManager.<init>(Lorg/neo4j/graphdb/GraphDatabaseService;)V

I am am starting to learn spring-data-neo4j
Very basic test case i am running but unable to succeed.
the error is: java.lang.IllegalStateException: Failed to load ApplicationContext
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'neo4jRelationshipBacking' defined in class path resource [org/springframework/data/neo4j/aspects/config/Neo4jAspectConfiguration.class]: Instantiation of bean failed; nested exception is org.springframework.beans.factory.BeanDefinitionStoreException: Factory method [public org.springframework.data.neo4j.aspects.support.relationship.Neo4jRelationshipBacking org.springframework.data.neo4j.aspects.config.Neo4jAspectConfiguration.neo4jRelationshipBacking() throws java.lang.Exception] threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'neo4jTemplate' defined in class path resource [org/springframework/data/neo4j/aspects/config/Neo4jAspectConfiguration.class]: Instantiation of bean failed; nested exception is org.springframework.beans.factory.BeanDefinitionStoreException: Factory method [public org.springframework.data.neo4j.support.Neo4jTemplate org.springframework.data.neo4j.config.Neo4jConfiguration.neo4jTemplate() throws java.lang.Exception] threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mappingInfrastructure' defined in class path resource [org/springframework/data/neo4j/aspects/config/Neo4jAspectConfiguration.class]: Instantiation of bean failed; nested exception is org.springframework.beans.factory.BeanDefinitionStoreException: Factory method [public org.springframework.data.neo4j.support.MappingInfrastructureFactoryBean org.springframework.data.neo4j.config.Neo4jConfiguration.mappingInfrastructure() throws java.lang.Exception] threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'neo4jTransactionManager' defined in class path resource [org/springframework/data/neo4j/aspects/config/Neo4jAspectConfiguration.class]: Instantiation of bean failed; nested exception is org.springframework.beans.factory.BeanDefinitionStoreException: Factory method [public org.springframework.transaction.PlatformTransactionManager org.springframework.data.neo4j.config.Neo4jConfiguration.neo4jTransactionManager()] threw exception; nested exception is java.lang.NoSuchMethodError: org.neo4j.kernel.impl.transaction.SpringTransactionManager.<init>(Lorg/neo4j/graphdb/GraphDatabaseService;)V
User.java pojo annotated with #NodeEntity
#NodeEntity
public class User {
#GraphId
private Long id;
User(String name){
this.name = name;
}
private String name;
public Long getId() {
return id;
}
public String getName() {
return name;
}
}
configuration file is:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:neo4j="http://www.springframework.org/schema/data/neo4j"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/data/neo4j http://www.springframework.org/schema/data/neo4j/spring-neo4j-2.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">
<context:annotation-config/>
<context:spring-configured/>
<neo4j:config storeDirectory="D:/data/db"/>
<tx:annotation-driven mode="proxy"/>
<context:component-scan base-package="com.neo4j.model"/>
</beans>
JUnit test case is :
#RunWith(SpringJUnit4ClassRunner.class)
#ContextConfiguration(locations={"classpath:/graph-test-context.xml"})
public class Neo4jUserTest {
#Autowired
Neo4jTemplate neo4jTemplate;
#Test
public void test() {
User user = new User("test");
neo4jTemplate.beginTx();
neo4jTemplate.save(user);
}
}
i have manually added below jar files from the eclipse buildpath:
commons-logging-1.0.4.jar
log4j-1.2.15.jar
jta.jar
cglib-2.1.3.jar
validation-api-1.0.0.GA.jar
lucene-core-3.5.0.jar
servlet-api.jar
org.springframework.aop-3.1.2.RELEASE.jar
org.springframework.asm-3.1.2.RELEASE.jar
org.springframework.aspects-3.1.2.RELEASE.jar
org.springframework.beans-3.1.2.RELEASE.jar
org.springframework.context.support-3.1.2.RELEASE.jar
org.springframework.context-3.1.2.RELEASE.jar
org.springframework.core-3.1.2.RELEASE.jar
org.springframework.expression-3.1.2.RELEASE.jar
org.springframework.instrument.tomcat-3.1.2.RELEASE.jar
org.springframework.instrument-3.1.2.RELEASE.jar
org.springframework.jdbc-3.1.2.RELEASE.jar
org.springframework.jms-3.1.2.RELEASE.jar
org.springframework.orm-3.1.2.RELEASE.jar
org.springframework.oxm-3.1.2.RELEASE.jar
org.springframework.test-3.1.2.RELEASE.jar
org.springframework.transaction-3.1.2.RELEASE.jar
org.springframework.web.portlet-3.1.2.RELEASE.jar
org.springframework.web.servlet-3.1.2.RELEASE.jar
org.springframework.web.struts-3.1.2.RELEASE.jar
org.springframework.web-3.1.2.RELEASE.jar
D:\JUnit\junit-4.6.jar
com.springsource.org.aopalliance-1.0.0.jar
aspectjtools-1.6.0.jar
asm-attrs.jar
asm.jar
spring-data-neo4j-2.1.0.RC1.jar
spring-data-neo4j-aspects-2.1.0.RC1.jar
spring-data-neo4j-cross-store-2.1.0.RC1.jar
spring-data-neo4j-rest-2.1.0.RC1.jar
slf4j-api-1.6.1.jar
slf4j-log4j12-1.7.2.jar
geronimo-jta_1.1_spec-1.1.1.jar
lucene-core-3.5.0.jar
org.apache.servicemix.bundles.jline-0.9.94_1.jar
scala-library-2.9.0-1.jar
server-api-1.7.2.jar
spring-data-commons-core-1.3.1.RELEASE.jar
hamcrest-all-1.3.jar
neo4j-cypher-dsl-1.6.M02.jar
neo4j-cypher-1.9-20120912.103508-32.jar
neo4j-kernel-1.9-20120912.102607-33.jar
neo4j-lucene-index-1.9-20120912.103015-33.jar
As Peter said, the problem is you are including a different version of the Neo4J library than Spring is expecting. A NoSuchMethodError means a client is calling a method that doesn't exist. This couldn't happen if you include the version Spring is using becuase Spring would have got a compile error if they called a method that doesn't exist.
How are you building you project? Please provide more detail like a POM if its a maven project.
Update: The org.neo4j.kernel.impl.transaction.SpringTransactionManager comes from your Neo4J installation not the jars you are supplying. What version of Neo4J are you running? It needs to match the version that spring-data-neo4j is expecting.
It seems you are using an old Neo4j version. Could you try with the coresponding Neo4j version, I think 1.8 instead of 1.7.2?
Finally i solved it by using below jar files:
aopalliance-1.0.jar
asm-3.1.jar
aspectjrt-1.6.12.jar
backport-util-concurrent-3.1.jar
cglib-2.2.jar
codegen-0.5.5.jar
commons-cli-1.0.jar
ecj-3.7.2.jar
guava-11.0.2.jar
hamcrest-core-1.3.jar
hamcrest-library-1.3.jar
jakarta-regexp-1.4.jar
javax.inject-1.jar
jcl-over-slf4j-1.7.1.jar
jsr305-1.3.9.jar
jta.jar
junit-3.8.1.jar
junit-dep-4.10.jar
logback-classic-1.0.6.jar
logback-core-1.0.6.jar
lucene-core-3.5.0.jar
lucene-queries-3.5.0.jar
mysema-commons-lang-0.2.4.jar
neo4j-1.8.jar
neo4j-cypher-1.8.jar
neo4j-cypher-dsl-1.8.jar
neo4j-graph-algo-1.8.jar
neo4j-graph-matching-1.8.jar
neo4j-jmx-1.8.jar
neo4j-kernel-1.8.jar
neo4j-lucene-index-1.8.jar
neo4j-udc-1.8.jar
plexus-compiler-api-1.9.1.jar
plexus-compiler-javac-1.9.1.jar
plexus-compiler-manager-1.9.1.jar
plexus-interactivity-api-1.0-alpha-4.jar
plexus-interpolation-1.11.jar
plexus-interpolation-1.13.jar
plexus-utils-1.5.15.jar
plexus-utils-2.0.5.jar
plexus-utils-3.0.jar
querydsl-apt-2.8.2.jar
querydsl-codegen-2.8.2.jar
querydsl-core-2.8.2.jar
querydsl-lucene-2.8.2.jar
scala-library-2.9.1-1.jar
slf4j-api-1.7.1.jar
spring-aop-3.2.0.M2.jar
spring-aspects-3.2.0.M2.jar
spring-beans-3.2.0.M2.jar
spring-context-3.2.0.M2.jar
spring-core-3.2.0.M2.jar
spring-data-commons-core-1.4.0.RELEASE.jar
spring-data-neo4j-2.1.0.RELEASE.jar
spring-expression-3.2.0.M2.jar
spring-jdbc-3.2.0.M2.jar
spring-orm-3.2.0.M2.jar
spring-test-3.2.0.M2.jar
spring-tx-3.2.0.M2.jar
validation-api-1.0.0.GA.jar

Resources