Hi everyone,
I'm facing a small configuration problem within my Spring Batch calls.
My batch is currently just an EJB connectivity test. I'm deploying my EAR application on a JBoss 5.1.0 GA server. Here is what I first made, which completely succeeded :
PersonReader.java
batch-sample-context.xmlCode:private PersonApplicationService personApplicationService; private int readIndex = 1; @Override public PersonDTO read() throws Exception, UnexpectedInputException, ParseException { Properties p = new Properties(); p.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory"); p.put(Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces"); p.put(Context.PROVIDER_URL, "jnp://localhost:1099"); InitialContext context = new InitialContext(p); personApplicationService = (PersonApplicationService) context.lookup("test/PersonApplicationServiceBean/remote"); List<PersonDTO> persons = personApplicationService.findList(readIndex, 1); readIndex++; if(persons.size() > 0) return persons.get(0); else return null; }
I do run the batch in Eclipse with a "Run as..." configuration which do call the main class org.springframework.batch.core.launch.support.Comm andLineJobRunner with "batch-sample-context.xml minimal" as argumentsCode:<beans xmlns="http://www.springframework.org/schema/beans" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:p="http://www.springframework.org/schema/p" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd http://www.springframework.org/schema/batch http://www.springframework.org/schema/batch/spring-batch-2.1.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd"> <bean id="PersonReader" class="test.batch.PersonReader"> </bean> <bean id="PersonWriter" class="test.batch.PersonWriter"></bean> <bean id="jobLauncher" class="org.springframework.batch.core.launch.support.SimpleJobLauncher"> <property name="jobRepository" ref="jobRepository" /> </bean> <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> <bean id="minimal" class="org.springframework.batch.core.job.SimpleJob"> <property name="jobRepository" ref="jobRepository" /> <property name="steps"> <bean id="simpleStep" class="org.springframework.batch.core.step.item.SimpleStepFactoryBean"> <property name="transactionManager" ref="transactionManager" /> <property name="jobRepository" ref="jobRepository" /> <property name="itemReader" ref="PersonReader" /> <property name="itemWriter" ref="PersonWriter" /> </bean> </property> </bean> </beans>
My findList() function do return a list of persons, but my second parameter make it return only one element for each call.
The writer just System.out.println the PersonDTO object, which is completely correctly printed in my Spring Batch console.
Now, this is not optimal as JNDI call is performed at each read() call to get the remote EJB. This has a large performance overhead (I suppose). Here is my second test, trying to use Spring configuration file to initialise it correctly :
PersonReader.java
batch-sample-context.xmlCode:private PersonApplicationService personApplicationService; private int readIndex = 1; @Override public PersonDTO read() throws Exception, UnexpectedInputException, ParseException { List<PersonDTO> persons= personApplicationService.findList(readIndex, 1); readIndex++; if(persons.size() > 0) return persons.get(0); else return null; }
But, at execution time, I do receive this exception :Code:<beans xmlns="http://www.springframework.org/schema/beans" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:p="http://www.springframework.org/schema/p" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd http://www.springframework.org/schema/batch http://www.springframework.org/schema/batch/spring-batch-2.1.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd"> <bean id="PersonApplicationServiceBean" class="org.springframework.ejb.access.SimpleRemoteStatelessSessionProxyFactoryBean"> <property name="jndiName" value="test/PersonApplicationServiceBean/remote" /> <property name="businessInterface" value="test.common.application.PersonApplicationService" /> <property name="jndiEnvironment"> <props> <prop key="java.naming.factory.initial">org.jnp.interfaces.NamingContextFactory</prop> <prop key="java.naming.factory.url.pkgs">org.jboss.naming:org.jnp.interfaces</prop> <prop key="java.naming.provider.url">jnp://localhost:1099</prop> </props> </property> </bean> <bean id="PersonReader" class="test.batch.PersonReader"> <property name="personApplicationService" ref="PersonApplicationServiceBean" /> </bean> <bean id="PersonWriter" class="test.batch.PersonWriter"></bean> <bean id="jobLauncher" class="org.springframework.batch.core.launch.support.SimpleJobLauncher"> <property name="jobRepository" ref="jobRepository" /> </bean> <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> <bean id="minimal" class="org.springframework.batch.core.job.SimpleJob"> <property name="jobRepository" ref="jobRepository" /> <property name="steps"> <bean id="simpleStep" class="org.springframework.batch.core.step.item.SimpleStepFactoryBean"> <property name="transactionManager" ref="transactionManager" /> <property name="jobRepository" ref="jobRepository" /> <property name="itemReader" ref="PersonReader" /> <property name="itemWriter" ref="PersonWriter" /> </bean> </property> </bean> </beans>
The deploy version is strictly the same on JBoss server. I don't understand why the Spring configuration keeps saying this EJB is not a Remote Stateles Session Bean, as I can access it through the manual JNDI initialization in read().Code:org.springframework.remoting.RemoteLookupFailureException: EJB instance [Proxy to jboss.j2ee:ear=test.ear,jar=test_ejb.jar,name=PersonApplicationServiceBean,service=EJB3 implementing [interface test.common.application.PersonApplicationService]] is not a Remote Stateless Session Bean
The stacktrace (if it helps) is :
The JNDI configuration in the XML really looks the same as the manual EJB lookup, I could not figure out any difference.Code:at org.springframework.ejb.access.AbstractRemoteSlsbInvokerInterceptor.newSessionBeanInstance(AbstractRemoteSlsbInvokerInterceptor.java:228) at org.springframework.ejb.access.SimpleRemoteSlsbInvokerInterceptor.getSessionBeanInstance(SimpleRemoteSlsbInvokerInterceptor.java:141) at org.springframework.ejb.access.SimpleRemoteSlsbInvokerInterceptor.doInvoke(SimpleRemoteSlsbInvokerInterceptor.java:97) at org.springframework.ejb.access.AbstractRemoteSlsbInvokerInterceptor.invoke(AbstractRemoteSlsbInvokerInterceptor.java:140) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171) at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204) at $Proxy3.findList(Unknown Source) at test.batch.PersonReader.read(PersonReader.java:42) at test.batch.PersonReader.read(PersonReader.java:1) at org.springframework.batch.core.step.item.SimpleChunkProvider.doRead(SimpleChunkProvider.java:90) at org.springframework.batch.core.step.item.SimpleChunkProvider.read(SimpleChunkProvider.java:127) at org.springframework.batch.core.step.item.SimpleChunkProvider$1.doInIteration(SimpleChunkProvider.java:106) at org.springframework.batch.repeat.support.RepeatTemplate.getNextResult(RepeatTemplate.java:367) at org.springframework.batch.repeat.support.RepeatTemplate.executeInternal(RepeatTemplate.java:214) at org.springframework.batch.repeat.support.RepeatTemplate.iterate(RepeatTemplate.java:143) at org.springframework.batch.core.step.item.SimpleChunkProvider.provide(SimpleChunkProvider.java:103) at org.springframework.batch.core.step.item.ChunkOrientedTasklet.execute(ChunkOrientedTasklet.java:68) at ...... (I did need to remove a few of the stacktrace, as forum limit to 10'000 caracters) at org.springframework.batch.core.launch.support.SimpleJobLauncher.run(SimpleJobLauncher.java:114) at org.springframework.batch.core.launch.support.CommandLineJobRunner.start(CommandLineJobRunner.java:300) at org.springframework.batch.core.launch.support.CommandLineJobRunner.main(CommandLineJobRunner.java:464)
Any suggest to try to figure out the problem will be appreciated.


Reply With Quote