Spring batch -Error in Bean Creation - spring

i want to create a memory jobrepository and i get this exception, Any idea why I am getting this exception?
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jobExplorerInitial' defined in class path resource [fr/rsi/gdficoba/batch/integrationinitial/job/datasource.xml]: Initialization of bean failed; nested exception is org.springframework.beans.ConversionNotSupportedException: Failed to convert property value of type 'com.sun.proxy.$Proxy22 implementing org.springframework.batch.core.repository.JobRepository,org.springframework.aop.SpringProxy,org.springframework.aop.framework.Advised' to required type 'org.springframework.batch.core.repository.support.MapJobRepositoryFactoryBean' for property 'repositoryFactory'; nested exception is java.lang.IllegalStateException: Cannot convert value of type [com.sun.proxy.$Proxy22 implementing org.springframework.batch.core.repository.JobRepository,org.springframework.aop.SpringProxy,org.springframework.aop.framework.Advised] to required type [org.springframework.batch.core.repository.support.MapJobRepositoryFactoryBean] for property 'repositoryFactory': no matching editors or conversion strategy found
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:547) ~[spring-beans-4.0.5.RELEASE.jar:4.0.5.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:475) ~[spring-beans-4.0.5.RELEASE.jar:4.0.5.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:304) ~[spring-beans-4.0.5.RELEASE.jar:4.0.5.RELEASE]
....
at org.springframework.batch.core.launch.support.CommandLineJobRunner.start(CommandLineJobRunner.java:290) [spring-batch-core-3.0.3.RELEASE.jar:3.0.3.RELEASE]
at org.springframework.batch.core.launch.support.CommandLineJobRunner.main(CommandLineJobRunner.java:590) [spring-batch-core-3.0.3.RELEASE.jar:3.0.3.RELEASE]
Caused by: org.springframework.beans.ConversionNotSupportedException: Failed to convert property value of type 'com.sun.proxy.$Proxy22 implementing org.springframework.batch.core.repository.JobRepository,org.springframework.aop.SpringProxy,org.springframework.aop.framework.Advised' to required type 'org.springframework.batch.core.repository.support.MapJobRepositoryFactoryBean' for property 'repositoryFactory'; nested exception is java.lang.IllegalStateException: Cannot convert value of type [com.sun.proxy.$Proxy22 implementing org.springframework.batch.core.repository.JobRepository,org.springframework.aop.SpringProxy,org.springframework.aop.framework.Advised] to required type [org.springframework.batch.core.repository.support.MapJobRepositoryFactoryBean] for property 'repositoryFactory': no matching editors or conversion strategy found
at org.springframework.beans.BeanWrapperImpl.convertIfNecessary(BeanWrapperImpl.java:474) ~[spring-beans-4.0.5.RELEASE.jar:4.0.5.RELEASE]
at org.springframework.beans.BeanWrapperImpl.convertForProperty(BeanWrapperImpl.java:511) ~[spring-beans-4.0.5.RELEASE.jar:4.0.5.RELEASE]
at org.springframework.beans.BeanWrapperImpl.convertForProperty(BeanWrapperImpl.java:505) ~[spring-beans-4.0.5.RELEASE.jar:4.0.5.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.convertForProperty(AbstractAutowireCapableBeanFactory.java:1502) ~[spring-beans-4.0.5.RELEASE.jar:4.0.5.RELEASE]
..
... 13 common frames omitted
Caused by: java.lang.IllegalStateException: Cannot convert value of type [com.sun.proxy.$Proxy22 implementing org.springframework.batch.core.repository.JobRepository,org.springframework.aop.SpringProxy,org.springframework.aop.framework.Advised] to required type [org.springframework.batch.core.repository.support.MapJobRepositoryFactoryBean] for property 'repositoryFactory': no matching editors or conversion strategy found
at org.springframework.beans.TypeConverterDelegate.convertIfNecessary(TypeConverterDelegate.java:267) ~[spring-beans-4.0.5.RELEASE.jar:4.0.5.RELEASE]
at org.springframework.beans.BeanWrapperImpl.convertIfNecessary(BeanWrapperImpl.java:459) ~[spring-beans-4.0.5.RELEASE.jar:4.0.5.RELEASE]
... 19 common frames omitted
my configuration is
<bean id="repositoryFactory"
class="org.springframework.batch.core.repository.support.MapJobRepositoryFactoryBean">
<property name="transactionManager" ref="transactionManager" />
</bean>
<bean id="jobExplorerInitial" class="org.springframework.batch.core.explore.support.MapJobExplorerFactoryBean>
<property name="repositoryFactory" ref="repositoryFactory" />
</bean>

You have to add a '&':
<property name="repositoryFactory" ref="&repositoryFactory"/>

Related

500 error -- CannotLoadBeanClassException

I am getting a 500 error from my Spring web application. The mentioned files are correctly named and in the correct packages. Here is the error message.
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping': Invocation of init method failed; nested exception is org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [com.dao.CommentDAO] for bean with name 'commentDAO' defined in ServletContext resource [/WEB-INF/ghs1986-servlet.xml]; nested exception is java.lang.ClassNotFoundException: com.dao.CommentDAO
Related cause: org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [com.dao.CommentDAO] for bean with name 'commentDAO' defined in ServletContext resource [/WEB-INF/ghs1986-servlet.xml]; nested exception is java.lang.ClassNotFoundException: com.dao.CommentDAO
Related cause: org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [com.controller.PagesController] for bean with name 'pagesController' defined in ServletContext resource [/WEB-INF/ghs1986-servlet.xml]; nested exception is java.lang.ClassNotFoundException: com.controller.PagesController
Related cause: org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [com.controller.CommentController] for bean with name 'commentController' defined in ServletContext resource [/WEB-INF/ghs1986-servlet.xml]; nested exception is java.lang.ClassNotFoundException: com.controller.CommentController
Here is the relevant portion of ghs1986-servlet.xml.
<bean id="commentDAO" class="com.dao.CommentDAO">
<property name="dataSource" ref="dataSource" />
</bean>
<bean id="pagesController" class="com.controller.PagesController" />
<bean id="commentController" class="com.controller.CommentController">
<property name="commentDAO" ref="commentDAO" />
</bean>
Problem solved. I needed the #Component annotation on CommentDAO.

Getting : java.lang.IllegalStateException: Cannot convert value of type [java.lang.String] to required type [javax.sql.DataSource]

I am using Spring 3.2.13 jars and ibatis 2.3.4.726 version to set up a dataSource as below
I am getting the below Exception
Caused by: java.lang.IllegalStateException: Cannot convert value of type [java.lang.String] to required type [javax.sql.DataSource] for property 'dataSource': no matching editors or conversion strategy found
My xml Spring Configurations are as below :
<bean id="commonDataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName" value="jdbc/ds_GOLD" />
<property name="defaultObject" value="jdbc/ds_SILVERR" />
</bean>
<bean id="sqlMapClient" class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
<property name="configLocation">
<value>
classpath:com/dav/dao/config/sqlMapConfig.xml
</value>
</property>
<property name="dataSource">
<ref bean="commonDataSource" />
</property>
<property name="transactionConfigClass">
<value>com.ibatis.sqlmap.engine.transaction.external.ExternalTransactionConfig
</value>
</property>
<property name="transactionConfigProperties">
<props>
<prop key="DefaultAutoCommit">false</prop>
<prop key="SetAutoCommitAllowed">false</prop>
</props>
</property>
</bean>
The Configurations seems good for me but getting exception
only if the "jdbc/ds_GOLD" is not configured in App server. In this case it should get picked the defaultObject JNDI. If the "jdbc/ds_GOLD" is configured in App server i don't see any error in logs. But Failover case it is not working.
[5/1/16 3:32:51:329 EDT] 00000098 webapp I com.ibm.ws.webcontainer.webapp.WebApp log SRVE0296E: [glow#glow.war][/glow][Servlet.LOG]:.StrutsServlet: null:.org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'gcdSqlMapClient' defined in ServletContext resource [/WEB-INF/config/common-dao.xml]: Initialization of bean failed; nested exception is org.springframework.beans.ConversionNotSupportedException: Failed to convert property value of type 'java.lang.String' to required type 'javax.sql.DataSource' for property 'dataSource'; nested exception is java.lang.IllegalStateException: Cannot convert value of type [java.lang.String] to required type [javax.sql.DataSource] for property 'dataSource': no matching editors or conversion strategy found
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:529)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:458)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:293)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:290)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:191)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:618)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:934)
.
.
.
at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:1862)
Caused by: org.springframework.beans.ConversionNotSupportedException: Failed to convert property value of type 'java.lang.String' to required type 'javax.sql.DataSource' for property 'dataSource'; nested exception is java.lang.IllegalStateException: Cannot convert value of type [java.lang.String] to required type [javax.sql.DataSource] for property 'dataSource': no matching editors or conversion strategy found
at org.springframework.beans.BeanWrapperImpl.convertIfNecessary(BeanWrapperImpl.java:464)
at org.springframework.beans.BeanWrapperImpl.convertForProperty(BeanWrapperImpl.java:495)
at org.springframework.beans.BeanWrapperImpl.convertForProperty(BeanWrapperImpl.java:489)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.convertForProperty(AbstractAutowireCapableBeanFactory.java:1465)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1424)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1160)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519)
... 114 more
Caused by: java.lang.IllegalStateException: Cannot convert value of type [java.lang.String] to required type [javax.sql.DataSource] for property 'dataSource': no matching editors or conversion strategy found
at org.springframework.beans.TypeConverterDelegate.convertIfNecessary(TypeConverterDelegate.java:267)
at org.springframework.beans.BeanWrapperImpl.convertIfNecessary(BeanWrapperImpl.java:449)
... 120 more
``
Forget to keep the defaultObject as property reference to the dataSource. I wrongly configured it as property value.

Getting error while dynamically providing input,output path

I have created a multi-file reader and flat file writer (Later, I have to extend it to multifile read to multiple file write, one to one mapping). When i provide the input path through property file, It works all good, but when I try to provide path through jobExecutionContext it starts giving me error. What surprises me is that writer is successfully taking the path from executionContext and writing whatever location i provide but not the reader.
PS: I am using "SingleItemPeekableItemReader" because the data i have in file is multi-line record and has no way to determine when one record ends . the only way to know that record 2 has started is when you have access to next line and you know that its start of new record.
Can someone through some light, What wrong i am doing.
<bean id="itemReader" class="com.varun.reader.AccountDataReader">
<property name="fieldSetReader" ref="PeekableitemReader" />
<property name="headerFieldSetMapper" ref="headerFieldSetMapper" />
<property name="multiReader" ref="multiResourceReader"/>
</bean>
<bean id="PeekableitemReader" class="org.springframework.batch.item.support.SingleItemPeekableItemReader" >
<property name="delegate" ref="multiResourceReader"/>
</bean>
<bean id="multiResourceReader" class=" org.springframework.batch.item.file.MultiResourceItemReader" >
<property name="resources" value="file:${file.input.dir}*.DAT" />
<property name="delegate" ref="fileItemReader" />
</bean>
<bean id="fileItemReader" class="org.springframework.batch.item.file.FlatFileItemReader">
<property name="lineMapper">
<bean class="org.springframework.batch.item.file.mapping.DefaultLineMapper">
<property name="lineTokenizer" ref="accountDataTokenizer"/>
<property name="fieldSetMapper">
<bean class="org.springframework.batch.item.file.mapping.PassThroughFieldSetMapper" />
</property>
</bean>
</property>
<property name="comments" value=""></property>
</bean>
It error out, when i provide the resources in multiresourceReader as below
<property name="resources" value="file:#{JobExecutionContext[input_dir]}*.DAT" />
Error logs as below:
Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'step1': Cannot resolve reference to bean 'itemReader' while setting bean property 'itemReader'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'itemReader' defined in class path resource [spring/config/process-config.xml]: Cannot resolve reference to bean 'PeekableitemReader' while setting bean property 'fieldSetReader'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'PeekableitemReader' defined in class path resource [spring/config/process-config.xml]: Cannot resolve reference to bean 'multiResourceReader' while setting bean property 'delegate'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'multiResourceReader' defined in class path resource [spring/config/process-config.xml]: Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanExpressionException: Expression parsing failed; nested exception is org.springframework.expression.spel.SpelEvaluationException: EL1008E:(pos 0): Property or field 'JobExecutionContext' cannot be found on object of type 'org.springframework.beans.factory.config.BeanExpressionContext' - maybe not public?
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:359)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:108)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1481)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1226)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:543)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)
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)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:753)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:760)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:482)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83)
after making multireader scope as step i am getting error as below.I have tried putting scope on all the other delegate readers as well, but i am getting the same error.
Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'step1': Cannot resolve reference to bean 'itemReader' while setting bean property 'itemReader'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'itemReader' defined in class path resource [spring/config/process-config.xml]: Initialization of bean failed; nested exception is org.springframework.beans.ConversionNotSupportedException: Failed to convert property value of type [com.sun.proxy.$Proxy11 implementing org.springframework.batch.item.ItemStreamReader,org.springframework.batch.item.ItemStream,org.springframework.aop.scope.ScopedObject,java.io.Serializable,org.springframework.aop.framework.AopInfrastructureBean,org.springframework.aop.SpringProxy,org.springframework.aop.framework.Advised] to required type [org.springframework.batch.item.file.MultiResourceItemReader] for property 'multiReader'; nested exception is java.lang.IllegalStateException: Cannot convert value of type [com.sun.proxy.$Proxy11 implementing org.springframework.batch.item.ItemStreamReader,org.springframework.batch.item.ItemStream,org.springframework.aop.scope.ScopedObject,java.io.Serializable,org.springframework.aop.framework.AopInfrastructureBean,org.springframework.aop.SpringProxy,org.springframework.aop.framework.Advised] to required type [org.springframework.batch.item.file.MultiResourceItemReader] for property 'multiReader': no matching editors or conversion strategy found
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:359)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:108)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1481)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1226)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:543)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)
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)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:753)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:760)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:482)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83)
at com.varun.JobScheduler.main(JobScheduler.java:9)
My custom Reader
public class AccountDataReader implements ItemReader<AccountDataBO> {
private static Log log = LogFactory.getLog(AccountDataReader.class);
private boolean recordFinished;
private AccountDataBO acctObj = new AccountDataBO();
private SingleItemPeekableItemReader<FieldSet> fieldSetReader;
private HeaderFieldSetMapper headerFieldSetMapper;
private MultiResourceItemReader<FieldSet> multiReader;
#Override
public AccountDataBO read() throws Exception {
recordFinished = false;
while (!recordFinished) {
process(fieldSetReader.read());
}
AccountDataBO result = acctObj;
acctObj = new AccountDataBO();
return result;
}
private void process(FieldSet fieldSet) throws Exception {
if (fieldSet == null) {
log.debug("FINISHED Reading");
recordFinished = true;
acctObj=null;
return;
}
String lineId = fieldSet.readString(0);
if (!StringUtils.isEmpty(lineId) && lineId.contains(AccountDataBO.ACCOUNT)) {
log.debug("Starting new Record");
acctObj.setHeader(headerFieldSetMapper.mapFieldSet(fieldSet));
acctObj.setResource(multiReader.getCurrentResource());
}
//Code
}
private void CheckEOFNewAccount() throws Exception {
if ((fieldSetReader.peek() != null
&& ((fieldSetReader.peek().getValues())[0].contains(AccountDataBO.ACCOUNT)))
|| fieldSetReader.peek() == null) {
log.debug("Next Line is Account or EOF Hence returning for current Account");
recordFinished = true;
return;
}
}
public void setFieldSetReader(SingleItemPeekableItemReader<FieldSet> fieldSetReader) {
this.fieldSetReader = fieldSetReader;
}
public void setHeaderFieldSetMapper(HeaderFieldSetMapper headerFieldSetMapper) {
this.headerFieldSetMapper = headerFieldSetMapper;
}
public void setMultiReader(MultiResourceItemReader<FieldSet> multiReader) {
this.multiReader = multiReader;
}
}
In order to inject job parameters into a batch component, the component needs to be step scoped. So in your example, change this:
<bean id="multiResourceReader"
class=" org.springframework.batch.item.file.MultiResourceItemReader" >
To this:
<bean id="multiResourceReader"
class=" org.springframework.batch.item.file.MultiResourceItemReader"
scope="step" >

How do I use the spring jars in my liferay portlet instead of the spring jars in the ROOT\WEB-INF\lib?

I have a portlet that I've created and I'm trying to use spring jpa in it for data retrieval. I'm using Spring version 3.2.14 and the spring jars that I need are deployed in my portlet's WEB-INF/lib folder.
On tomcat start up I keep getting the following exception:
Caused by: org.springframework.beans.NotWritablePropertyException: Invalid property 'packagesToScan' of bean class [org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean]: Bean property 'packagesToScan' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?
at org.springframework.beans.BeanWrapperImpl.setPropertyValue(BeanWrapperImpl.java:1052)
at org.springframework.beans.BeanWrapperImpl.setPropertyValue(BeanWrapperImpl.java:921)
at org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:76)
at org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:58)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1360)
... 39 more
If I attach a debugger to Tomcat I can see that it is using spring-beans.jar(version 3.0.7.RELEASE) that is in ROOT/WEB-INF/lib which has a know issue with 'packageToScan' in LocalContainerEntityManagerFactoryBean in my bean definition:
<bean id="reportingEntityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="packagesToScan">
<list>
<value>org.preptoolkit.exercise.reporting.model</value>
</list>
</property>
<property name="jpaVendorAdapter">
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
<property name="showSql" value="true" />
<property name="databasePlatform" value="org.hibernate.dialect.MySQL5Dialect"/>
</bean>
</property>
</bean>
I have tried putting spring-beans-3.2.14.RELEASE.jar in $tomcat_home/lib/ext and liferay still uses the 3.0.7 verion.
Liferay Version: 6.2-ce-ga4
So how do I get Liferay to use spring-beans-3.2.14.RELEASE.jar instead of the one ROOT for my portlet?
(I've been pounding my head on this wall for 3 days now)
UPDATE
Here is the full stacktrace:
13:26:55,702 ERROR [localhost-startStop-1][ContextLoader:206] Context initialization failed org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'reportingEntityManagerFactory' defined in ServletContext resource [/WEB-INF/classes/persistenceContext.xml]: Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'packagesToScan' of bean class [org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean]: Bean property 'packagesToScan' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1363)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1085)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:516)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:455)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:293)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:290)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:192)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:567)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:895)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:425)
at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:282)
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:204)
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:47)
at com.liferay.portal.spring.context.PortletContextLoaderListener.contextInitialized(PortletContextLoaderListener.java:85)
at com.liferay.portal.deploy.hot.SpringHotDeployListener.doInvokeDeploy(SpringHotDeployListener.java:85)
at com.liferay.portal.deploy.hot.SpringHotDeployListener.invokeDeploy(SpringHotDeployListener.java:41)
at com.liferay.portal.deploy.hot.HotDeployImpl.doFireDeployEvent(HotDeployImpl.java:227)
at com.liferay.portal.deploy.hot.HotDeployImpl.fireDeployEvent(HotDeployImpl.java:96)
at com.liferay.portal.kernel.deploy.hot.HotDeployUtil.fireDeployEvent(HotDeployUtil.java:28)
at com.liferay.portal.kernel.servlet.PluginContextListener.fireDeployEvent(PluginContextListener.java:164)
at com.liferay.portal.kernel.servlet.PluginContextListener.doPortalInit(PluginContextListener.java:154)
at com.liferay.portal.kernel.util.BasePortalLifecycle.portalInit(BasePortalLifecycle.java:44)
at com.liferay.portal.kernel.util.PortalLifecycleUtil.register(PortalLifecycleUtil.java:74)
at com.liferay.portal.kernel.util.PortalLifecycleUtil.register(PortalLifecycleUtil.java:58)
at com.liferay.portal.kernel.util.BasePortalLifecycle.registerPortalLifecycle(BasePortalLifecycle.java:54)
at com.liferay.portal.kernel.servlet.PluginContextListener.contextInitialized(PluginContextListener.java:116)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4939)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5434)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:901)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:877)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:633)
at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:1113)
at org.apache.catalina.startup.HostConfig$DeployDirectory.run(HostConfig.java:1671)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
Caused by: org.springframework.beans.NotWritablePropertyException: Invalid property 'packagesToScan' of bean class [org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean]: Bean property 'packagesToScan' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?
at org.springframework.beans.BeanWrapperImpl.setPropertyValue(BeanWrapperImpl.java:1052)
at org.springframework.beans.BeanWrapperImpl.setPropertyValue(BeanWrapperImpl.java:921)
at org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:76)
at org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:58)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1360)
... 39 more
There is a SpringHotDeployListener that tries to initialize Spring (with the library from Liferay) for every portlet app.
To turn that off for your webapp you will have to remove com.liferay.portal.deploy.hot.SpringHotDeployListener in the property hot.deploy.listeners in your portal-ext.properties.
If you use other portlet apps which make use of the Spring environment of Liferay, you will need to create an Ext Plugin and extend SpringHotDeployListener in ext-impl:
public class MySpringHotDeployListener extends SpringHotDeployListener {
protected void doInvokeDeploy(HotDeployEvent hotDeployEvent) throws Exception {
if (!hotDeployEvent.getServletContext().getServletContextName().equals("MyContextName")) {
super.doInvokeDeploy(hotDeployEvent);
}
}
// Same for doInvokeUndeploy
}
Use MySpringHotDeployListener insteand of SpringHotDeployListener in portal-ext.properties then.

Spring Batch - "job" scoped beans can not be injected into "job" or "step" scoped beans

I am using spring batch version 3.0.2.RELEASE and spring framework version 3.2.12.RELEASE. And I am trying to inject a job scoped bean to another job scoped bean.
My configuration looks like this
<bean id="beanA" class="com.trial.BeanA" scope="job" >
<property name="beanB" ref="beanB" />
</bean>
<bean id="beanB" class="com.trial.BeanB" scope="job"/>
It throws an exception with details:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'scopedTarget.beanA' defined in class path resource [trial-context.xml]: Initialization of bean failed; nested exception is org.springframework.beans.ConversionNotSupportedException: Failed to convert property value of type 'com.sun.proxy.$Proxy1 implementing com.trial.BeanB,org.springframework.beans.factory.InitializingBean,org.springframework.aop.scope.ScopedObject,java.io.Serializable,org.springframework.aop.framework.AopInfrastructureBean,org.springframework.aop.SpringProxy,org.springframework.aop.framework.Advised' to required type 'com.trial.BeanB' for property 'beanB'; nested exception is java.lang.IllegalStateException: Cannot convert value of type [com.sun.proxy.$Proxy1 implementing com.trial.BeanB,org.springframework.beans.factory.InitializingBean,org.springframework.aop.scope.ScopedObject,java.io.Serializable,org.springframework.aop.framework.AopInfrastructureBean,org.springframework.aop.SpringProxy,org.springframework.aop.framework.Advised] to required type [com.trial.BeanB] for property 'beanB': no matching editors or conversion strategy found
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:529)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:458)
at org.springframework.beans.factory.support.AbstractBeanFactory$2.getObject(AbstractBeanFactory.java:331)
at org.springframework.batch.core.scope.JobScope.get(JobScope.java:103)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:327)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:191)
at org.springframework.aop.target.SimpleBeanTargetSource.getTarget(SimpleBeanTargetSource.java:34)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:184)
at com.sun.proxy.$Proxy13.getValue(Unknown Source)
at org.springframework.batch.core.listener.CompositeJobExecutionListener.beforeJob(CompositeJobExecutionListener.java:73)
at org.springframework.batch.core.job.AbstractJob.execute(AbstractJob.java:301)
at org.springframework.batch.core.launch.support.SimpleJobLauncher$1.run(SimpleJobLauncher.java:135)
at org.springframework.core.task.SyncTaskExecutor.execute(SyncTaskExecutor.java:49)
at org.springframework.batch.core.launch.support.SimpleJobLauncher.run(SimpleJobLauncher.java:128)
Caused by: org.springframework.beans.ConversionNotSupportedException: Failed to convert property value of type 'com.sun.proxy.$Proxy1 implementing com.trial.BeanB,org.springframework.beans.factory.InitializingBean,org.springframework.aop.scope.ScopedObject,java.io.Serializable,org.springframework.aop.framework.AopInfrastructureBean,org.springframework.aop.SpringProxy,org.springframework.aop.framework.Advised' to required type 'com.trial.BeanB' for property 'beanB'; nested exception is java.lang.IllegalStateException: Cannot convert value of type [com.sun.proxy.$Proxy1 implementing com.trial.BeanB,org.springframework.beans.factory.InitializingBean,org.springframework.aop.scope.ScopedObject,java.io.Serializable,org.springframework.aop.framework.AopInfrastructureBean,org.springframework.aop.SpringProxy,org.springframework.aop.framework.Advised] to required type [com.trial.BeanB] for property 'beanB': no matching editors or conversion strategy found
at org.springframework.beans.BeanWrapperImpl.convertIfNecessary(BeanWrapperImpl.java:464)
at org.springframework.beans.BeanWrapperImpl.convertForProperty(BeanWrapperImpl.java:495)
at org.springframework.beans.BeanWrapperImpl.convertForProperty(BeanWrapperImpl.java:489)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.convertForProperty(AbstractAutowireCapableBeanFactory.java:1465)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1424)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1160)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519)
... 18 more
Caused by: java.lang.IllegalStateException: Cannot convert value of type [com.sun.proxy.$Proxy1 implementing com.trial.BeanB,org.springframework.beans.factory.InitializingBean,org.springframework.aop.scope.ScopedObject,java.io.Serializable,org.springframework.aop.framework.AopInfrastructureBean,org.springframework.aop.SpringProxy,org.springframework.aop.framework.Advised] to required type [com.trial.BeanB] for property 'beanB': no matching editors or conversion strategy found
at org.springframework.beans.TypeConverterDelegate.convertIfNecessary(TypeConverterDelegate.java:267)
at org.springframework.beans.BeanWrapperImpl.convertIfNecessary(BeanWrapperImpl.java:449)
... 24 more
Even I try to inject a "job" scoped bean to a "step" scoped bean, it fails and throws a similar exception.
How can I solve the issue?
You are using java proxying which requires interfaces, yet your BeanB doesn't implement an interface that BeanA is coded against. You need to either switch to dynamic subclassing or have BeanB implement an interface and have BeanA expect that interface.

Resources