constant error with bean name - java

recently I decided to play with Spring. I did some tutorials and everything seems fine until the moment I am trying to use multiple properties files. As Internet says, it is enough to do something like
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="ignoreUnresolvablePlaceholders" value="true"/>
<property name="ignoreResourceNotFound" value="true"/>
<property name="location">
<list>
<value>classpath:readData.properties</value>
<value>classpath:sendMail.properties</value>
</list>
</property>
</bean>
Well, unfortunately It does not work. Surprisingly this version works (for one properties folder):
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location">
<value>classpath:readData.properties</value>
</property>
</bean>
The Console says as follows:
Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.beans.factory.config.PropertyPlaceholderConfigurer#0' defined in class path resource [Beans.xml]: Initialization of bean failed; nested exception is org.springframework.beans.TypeMismatchException: Failed to convert property value of type 'java.util.ArrayList' to required type 'org.springframework.core.io.Resource' for property 'location'; nested exception is java.lang.IllegalArgumentException: Cannot convert value of type [java.util.ArrayList] to required type [org.springframework.core.io.Resource] for property 'location': PropertyEditor [org.springframework.core.io.ResourceEditor] returned inappropriate value of type [java.util.ArrayList]
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: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:198)
at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:657)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:461)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83)
at corrected_reminder.Reminder.main(Reminder.java:25)
Caused by: org.springframework.beans.TypeMismatchException: Failed to convert property value of type 'java.util.ArrayList' to required type 'org.springframework.core.io.Resource' for property 'location'; nested exception is java.lang.IllegalArgumentException: Cannot convert value of type [java.util.ArrayList] to required type [org.springframework.core.io.Resource] for property 'location': PropertyEditor [org.springframework.core.io.ResourceEditor] returned inappropriate value of type [java.util.ArrayList]
at org.springframework.beans.BeanWrapperImpl.convertIfNecessary(BeanWrapperImpl.java:468)
at org.springframework.beans.BeanWrapperImpl.convertForProperty(BeanWrapperImpl.java:494)
at org.springframework.beans.BeanWrapperImpl.convertForProperty(BeanWrapperImpl.java:488)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.convertForProperty(AbstractAutowireCapableBeanFactory.java:1433)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1392)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1128)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519)
... 10 more
Caused by: java.lang.IllegalArgumentException: Cannot convert value of type [java.util.ArrayList] to required type [org.springframework.core.io.Resource] for property 'location': PropertyEditor [org.springframework.core.io.ResourceEditor] returned inappropriate value of type [java.util.ArrayList]
at org.springframework.beans.TypeConverterDelegate.convertIfNecessary(TypeConverterDelegate.java:260)
at org.springframework.beans.BeanWrapperImpl.convertIfNecessary(BeanWrapperImpl.java:448)
... 16 more
Could anyone help me?
Edit
#Denis Makarskiy
I have tried it many times, but without satisfying results. Now I have
Exception in thread "main" org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Cannot locate BeanDefinitionDecorator for element [property-placeholder]
Offending resource: class path resource [Beans.xml]

You are using multiple properties file, use "locations" instead of "location". For single properties, you can use "location".
check the api doc:
https://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/core/io/support/PropertiesLoaderSupport.html#setLocations-org.springframework.core.io.Resource...-

You can use context:property-placeholder tag to specify multiple property files.
Example:
<context:property-placeholder location="readData.properties,
sendMail.properties"/>
Don't forget to add context schema to the beans tag, like this:
<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.1.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.1.xsd>

Related

Weblogic and Spring JMS configuration throws java.lang.IllegalStateException

Converting EJB MDB application to Spring base JMS service.
JMS Queue configuration is in Weblogic server.
Have following in configuration in applicationContext 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"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee.xsd">
<bean id="vTMessageQueueListener" class="com.collection.mom.sink.EventMessageBean" />
<bean id="queueConnectionFactory" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiTemplate">
<ref bean="jndiTemplate" />
</property>
<property name="jndiName">
<value>/jms/FilingTopicConnFact</value>
</property>
</bean>
<bean id="jmsDestinationResolver"
class="org.springframework.jms.support.destination.JndiDestinationResolver">
<property name="jndiTemplate">
<ref bean="jndiTemplate" />
</property>
<property name="cache">
<value>true</value>
</property>
</bean>
<bean id="QueueTemplate" class="org.springframework.jms.core.JmsTemplate">
<property name="connectionFactory">
<ref bean="queueConnectionFactory" />
</property>
<property name="destinationResolver">
<ref bean="jmsDestinationResolver" />
</property>
</bean>
<bean id="SMMessageQueue" class="org.springframework.jndi.JndiObjectFactoryBean">
<!--<property name="jndiTemplate">
<ref bean="jndiTemplate" />
</property>-->
<property name="jndiName">
<value>com/vx/jms/vTMessageQueue</value>
</property>
</bean>
<bean id="V3JMSlistener" class="org.springframework.jms.listener.DefaultMessageListenerContainer">
<property name="concurrentConsumers" value="5" />
<property name="connectionFactory" ref="queueConnectionFactory" />
<property name="destinationName" ref="SMMessageQueue"/>
<property name="messageListener" ref="vTMessageQueueListener" />
</bean>
</beans>
.
<HTTP> <BEA-101162> <User defined listener org.springframework.web.context.ContextLoaderListener failed: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'V3JMSlistener' defined in class path resource [SpringJMSContext.xml]: Initialization of bean failed; nested exception is org.springframework.beans.ConversionNotSupportedException: Failed to convert property value of type 'weblogic.jms.common.DestinationImpl' to required type 'java.lang.String' for property 'destinationName'; nested exception is java.lang.IllegalStateException: Cannot convert value of type 'weblogic.jms.common.DestinationImpl' to required type 'java.lang.String' for property 'destinationName': no matching editors or conversion strategy found.
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'V3JMSlistener' defined in class path resource [SpringJMSContext.xml]: Initialization of bean failed; nested exception is org.springframework.beans.ConversionNotSupportedException: Failed to convert property value of type 'weblogic.jms.common.DestinationImpl' to required type 'java.lang.String' for property 'destinationName'; nested exception is java.lang.IllegalStateException: Cannot convert value of type 'weblogic.jms.common.DestinationImpl' to required type 'java.lang.String' for property 'destinationName': no matching editors or conversion strategy found
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:584)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:498)
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:320)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:318)
Truncated. see log file for complete stacktrace
Caused By: org.springframework.beans.ConversionNotSupportedException: Failed to convert property value of type 'weblogic.jms.common.DestinationImpl' to required type 'java.lang.String' for property 'destinationName'; nested exception is java.lang.IllegalStateException: Cannot convert value of type 'weblogic.jms.common.DestinationImpl' to required type 'java.lang.String' for property 'destinationName': no matching editors or conversion strategy found
at org.springframework.beans.AbstractNestablePropertyAccessor.convertIfNecessary(AbstractNestablePropertyAccessor.java:590)
at org.springframework.beans.AbstractNestablePropertyAccessor.convertForProperty(AbstractNestablePropertyAccessor.java:604)
at org.springframework.beans.BeanWrapperImpl.convertForProperty(BeanWrapperImpl.java:219)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.convertForProperty(AbstractAutowireCapableBeanFactory.java:1697)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1653)
Truncated. see log file for complete stacktrace
Caused By: java.lang.IllegalStateException: Cannot convert value of type 'weblogic.jms.common.DestinationImpl' to required type 'java.lang.String' for property 'destinationName': no matching editors or conversion strategy found
at org.springframework.beans.TypeConverterDelegate.convertIfNecessary(TypeConverterDelegate.java:299)
at org.springframework.beans.AbstractNestablePropertyAccessor.convertIfNecessary(AbstractNestablePropertyAccessor.java:585)
at org.springframework.beans.AbstractNestablePropertyAccessor.convertForProperty(AbstractNestablePropertyAccessor.java:604)
at org.springframework.beans.BeanWrapperImpl.convertForProperty(BeanWrapperImpl.java:219)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.convertForProperty(AbstractAutowireCapableBeanFactory.java:1697)
Truncated. see log file for complete stacktrace
Any help will be appreciated!!!
Use
<property name="destination" ref="SMMessageQueue"/>
instead of destinationName.
Spring can resolve a destination from its name but since you have the destination, you should inject that directly.

Configure Spring Bean using XML through Property other than String (using Properties File)

I have a Spring Bean defined as:
<bean id="loyaltyPointsExpiringJobTrigger" class="org.springframework.scheduling.quartz.CronTriggerFactoryBean">
<property name="name" value="Loyalty Points Expiring Job Trigger" />
<property name="jobDetail" ref="loyaltyPointsExpiringJobDetail" />
<property name="cronExpression" value="${prop.loyalty.expiring.points.job.cron}"/>
<property name="timeZone" value="${prop.loyalty.expiring.points.timezone}"/>
</bean>
However, the property prop.loyalty.expiring.points.timezone is causing TypeMismatchException with the message:
org.springframework.beans.TypeMismatchException: Failed to convert property value of type 'java.lang.String' to required type 'java.util.TimeZone' for property 'timeZone'; nested exception is java.lang.IllegalArgumentException: Invalid time zone specification '${prop.loyalty.expiring.points.timezone}'
Please guide.
It is straightforward, you may need to define a bean for your timeZone object, and find out a constructor that uses string, pass the required values.

Why Spring circular reference for Autowire issue on Production Environment Only?

#All please read my question tiltle i already solve this
Spring circular reference working on Local , UAT , DEMO , STAGGING environment But not on Production Environment only.
all environment having same configuration
1 JDK : 1.7.0.79
2.Tomcat 7.0
applicationContext.xml
<?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:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:p="http://www.springframework.org/schema/p" xmlns:jee="http://www.springframework.org/schema/jee"
xmlns:task="http://www.springframework.org/schema/task"
xsi:schemaLocation="http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.2.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd
http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-3.2.xsd
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.2.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd">
<context:component-scan base-package="in.test.server">
</context:component-scan>
<context:annotation-config />
<tx:annotation-driven transaction-manager="transactionManager" />
<bean id="applicationProperties"
class="org.springframework.beans.factory.config.PropertiesFactoryBean">
<property name="locations">
<list>
<value>classpath*:mail.properties</value>
<value>classpath*:document_storage.properties</value>
<value>classpath*:ekyc.properties</value>
<value>classpath*:application_config.properties</value>
<value>classpath*:messages.properties</value>
<value>classpath*:invitation_codes.properties</value>
<value>classpath*:capitalraise.properties</value>
</list>
</property>
</bean>
<bean id="propertyConfigurer"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="ignoreUnresolvablePlaceholders" value="true" />
<property name="locations">
<list>
<value>classpath*:mail.properties</value>
<value>classpath*:application_config.properties</value>
</list>
</property>
</bean>
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver" />
<property name="url" value="jdbc:mysql://localhost:3306/testdb_trunk" />
<property name="username" value="root" />
<property name="password" value="root" />
<property name="minIdle" value="10" />
<property name="initialSize" value="10" />
<property name="validationQuery" value="SELECT 1 FROM DUAL"/>
</bean>
<bean id="sessionFactory"
class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="packagesToScan" value="in.grex.server.datamodel" />
<property name="hibernateProperties">
<props>
<prop key="hibernate.hbm2ddl.auto">update</prop>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
</props>
</property>
</bean>
<bean id="transactionManager"
class="org.springframework.orm.hibernate4.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<bean id="mailSender" class="org.springframework.mail.javamail.JavaMailSenderImpl">
<property name="host" value="smtp.gmail.com" />
<property name="port" value="587" />
<property name="username" value="${mail.mailAccount}" />
<property name="password" value="${mail.mailAccountPassword}" />
<property name="javaMailProperties">
<props>
<prop key="mail.smtp.auth">true</prop>
<prop key="mail.smtp.starttls.enable">true</prop>
</props>
</property>
</bean>
<bean id="mailUtil" class="in.grex.server.common.util.MailUtil">
<property name="mailSender" ref="mailSender" />
</bean>
<!-- Bean for dozer mapper. -->
<bean id="mapper" class="org.dozer.DozerBeanMapper" scope="singleton">
<property name="mappings">
<list>
<bean class="in.grex.server.dto.mapper.GrexDozerMapper" />
</list>
</property>
</bean>
<!-- Bean for dozer searchmapper. -->
<bean id="searchMapper" class="org.dozer.DozerBeanMapper" scope="singleton">
<property name="mappings">
<list>
<bean class="in.grex.server.dto.mapper.GrexDozerSearchMapper" />
</list>
</property>
</bean>
</beans>
StackTrace
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSearchService': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private in.grex.server.dto.mapper.CustomGrexMapper in.grex.server.search.DataSearchServiceImpl.customGrexMapper; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'customGrexMapper': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private in.grex.server.services.organizationassociation.OrganizationAssociationService in.grex.server.dto.mapper.CustomGrexMapperImpl.organizationAssociationService; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'organizationAssociationService': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private in.grex.server.services.organization.OrganizationService in.grex.server.services.organizationassociation.OrganizationAssociationServiceImpl.organizationService; nested exception is org.springframework.beans.factory.BeanCurrentlyInCreationException: Error creating bean with name 'organizationService': Bean with name 'organizationService' has been injected into other beans [utilityService,organizationUserService,companyService,messageService,investorService] in its raw version as part of a circular reference, but has eventually been wrapped. This means that said other beans do not use the final version of the bean. This is often the result of over-eager type matching - consider using 'getBeanNamesOfType' with the 'allowEagerInit' flag turned off, for example.
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:289)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1146)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:458)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:296)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:293)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:628)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:932)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:479)
at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:410)
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:306)
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:112)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4994)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5492)
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:649)
at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:1081)
at org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:1877)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
at java.util.concurrent.FutureTask.run(FutureTask.java:262)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:744)
Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: private in.grex.server.dto.mapper.CustomGrexMapper in.grex.server.search.DataSearchServiceImpl.customGrexMapper; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'customGrexMapper': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private in.grex.server.services.organizationassociation.OrganizationAssociationService in.grex.server.dto.mapper.CustomGrexMapperImpl.organizationAssociationService; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'organizationAssociationService': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private in.grex.server.services.organization.OrganizationService in.grex.server.services.organizationassociation.OrganizationAssociationServiceImpl.organizationService; nested exception is org.springframework.beans.factory.BeanCurrentlyInCreationException: Error creating bean with name 'organizationService': Bean with name 'organizationService' has been injected into other beans [utilityService,organizationUserService,companyService,messageService,investorService] in its raw version as part of a circular reference, but has eventually been wrapped. This means that said other beans do not use the final version of the bean. This is often the result of over-eager type matching - consider using 'getBeanNamesOfType' with the 'allowEagerInit' flag turned off, for example.
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:517)
at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:87)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:286)
... 26 more
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'customGrexMapper': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private in.grex.server.services.organizationassociation.OrganizationAssociationService in.grex.server.dto.mapper.CustomGrexMapperImpl.organizationAssociationService; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'organizationAssociationService': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private in.grex.server.services.organization.OrganizationService in.grex.server.services.organizationassociation.OrganizationAssociationServiceImpl.organizationService; nested exception is org.springframework.beans.factory.BeanCurrentlyInCreationException: Error creating bean with name 'organizationService': Bean with name 'organizationService' has been injected into other beans [utilityService,organizationUserService,companyService,messageService,investorService] in its raw version as part of a circular reference, but has eventually been wrapped. This means that said other beans do not use the final version of the bean. This is often the result of over-eager type matching - consider using 'getBeanNamesOfType' with the 'allowEagerInit' flag turned off, for example.
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:289)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1146)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:458)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:296)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:293)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:912)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:855)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:770)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:489)
... 28 more
Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: private in.grex.server.services.organizationassociation.OrganizationAssociationService in.grex.server.dto.mapper.CustomGrexMapperImpl.organizationAssociationService; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'organizationAssociationService': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private in.grex.server.services.organization.OrganizationService in.grex.server.services.organizationassociation.OrganizationAssociationServiceImpl.organizationService; nested exception is org.springframework.beans.factory.BeanCurrentlyInCreationException: Error creating bean with name 'organizationService': Bean with name 'organizationService' has been injected into other beans [utilityService,organizationUserService,companyService,messageService,investorService] in its raw version as part of a circular reference, but has eventually been wrapped. This means that said other beans do not use the final version of the bean. This is often the result of over-eager type matching - consider using 'getBeanNamesOfType' with the 'allowEagerInit' flag turned off, for example.
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:517)
at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:87)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:286)
... 39 more
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'organizationAssociationService': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private in.grex.server.services.organization.OrganizationService in.grex.server.services.organizationassociation.OrganizationAssociationServiceImpl.organizationService; nested exception is org.springframework.beans.factory.BeanCurrentlyInCreationException: Error creating bean with name 'organizationService': Bean with name 'organizationService' has been injected into other beans [utilityService,organizationUserService,companyService,messageService,investorService] in its raw version as part of a circular reference, but has eventually been wrapped. This means that said other beans do not use the final version of the bean. This is often the result of over-eager type matching - consider using 'getBeanNamesOfType' with the 'allowEagerInit' flag turned off, for example.
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:289)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1146)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:458)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:296)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:293)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:912)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:855)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:770)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:489)
... 41 more
Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: private in.grex.server.services.organization.OrganizationService in.grex.server.services.organizationassociation.OrganizationAssociationServiceImpl.organizationService; nested exception is org.springframework.beans.factory.BeanCurrentlyInCreationException: Error creating bean with name 'organizationService': Bean with name 'organizationService' has been injected into other beans [utilityService,organizationUserService,companyService,messageService,investorService] in its raw version as part of a circular reference, but has eventually been wrapped. This means that said other beans do not use the final version of the bean. This is often the result of over-eager type matching - consider using 'getBeanNamesOfType' with the 'allowEagerInit' flag turned off, for example.
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:517)
at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:87)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:286)
... 52 more
Caused by: org.springframework.beans.factory.BeanCurrentlyInCreationException: Error creating bean with name 'organizationService': Bean with name 'organizationService' has been injected into other beans [utilityService,organizationUserService,companyService,messageService,investorService] in its raw version as part of a circular reference, but has eventually been wrapped. This means that said other beans do not use the final version of the bean. This is often the result of over-eager type matching - consider using 'getBeanNamesOfType' with the 'allowEagerInit' flag turned off, for example.
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:548)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:458)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:296)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:293)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:912)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:855)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:770)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:489)
... 54 more
I had exactly this problem a while ago. Spring is a bit random in the order it wires dependencies, so in some cases an application would start... and in production it would fail with this error.
The problem was a really bad practice promoted by spring until a year or two ago... the problem? Use setter / #Autowired on fields for injection rather than constructor injection. The issue we had, was that we were slowly migrating the configuration to constructor injection, and we opened ourselves to this issue, as we had a mix of the two. The issue depends on which bean is instantiated first. I cannot remember properly now, but I think that if the bean using constructor injection is instantiated first, the error would appear, but if bean using setter injection was instantiated first, the the error would happen. In this case, we should have done all of the work in one go. When everything uses constructor injection, the issue can be replicated in all environments.
The solution is simple: dependency cycles are a symptom of an issue with the design of the classes. You have to find what the cycle is and cut it. It's not a problem with Spring, but rather one within your application.
Just now i have faced this issue and resolved by moving the required methods into one class and exposed it using #service annotation hence the issue has been resolved. This approach might be naive but solves the problem.
Class with all the methods/functions needed:
# Service
public class Class1
{
/% Method 1 %/
/% Method 2 %/
/% Method 3 %/
/% Method 4 %/
}
Autowired Class 1.
public class Class2
{
# Autowired
private Class1 class1;
/% class1.Method1() %/
/% class1.Method1() %/
.
.
.
}
Use #Lazy annotation for constructor dependency injection.

Spring #Value Could not resolve placeholder in string value

Have the context spring conf like this, I have 2 property-placeholder in my context.
<?xml version="1.0" encoding="UTF-8"?>
<beans>
<context:annotation-config/>
<context:component-scan base-package="com.xxx.app.xxx"/>
<context:property-placeholder location="classpath:em-management.properties"/>
<context:property-placeholder location="file:///opt/ass/swp/conf/platform.properties"/>
</beans>
When I run the code, met this error:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'CMClient': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private java.lang.String com.xxxx.app.xxxx.xx.client.CMClient.washost; nested exception is java.lang.IllegalArgumentException: Could not resolve placeholder 'com.ibm.CORBA.securityServerHost' in string value "${com.ibm.CORBA.securityServerHost}"
Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: private java.lang.String com.xxxx.app.xxx.xxx.client.CMClient.washost; nested exception is java.lang.IllegalArgumentException: Could not resolve placeholder 'com.ibm.CORBA.securityServerHost' in string value "${com.ibm.CORBA.securityServerHost}"
Caused by: java.lang.IllegalArgumentException: Could not resolve placeholder 'com.ibm.CORBA.securityServerHost' in string value "${com.ibm.CORBA.securityServerHost}"
how to solve this issue?
I found the solution for this particular problem,just append ignore-unresolvable="true" to each line.
<context:property-placeholder location="classpath:em-management.properties" ignore-unresolvable="true"/>
<context:property-placeholder location="file:///opt/ass/swp/conf/platform.properties" ignore-unresolvable="true"/>
Don't use multiple <context:property-placeholder/> tags, refer below code for the same and also make sure you have a key "com.ibm.CORBA.securityServerHost" with a value in either of your property file.
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location">
<list>
<value>classpath:em-management.properties</value>
<value>file:///opt/ass/swp/conf/platform.properties</value>
</list>
</property>
<property name="ignoreUnresolvablePlaceholders" value="true"/>
</bean>

Spring Batch: SimpleJobRepository - Example not working

I been trying to get the Spring Batch Hello World 3 example running from
http://jroller.com/0xcafebabe/entry/spring_batch_hello_world_3
I was missing some jars and someone helped me out and got the project working better but I still have a error.. can someone please help me out:
Here is my applicationContext.xml
<?xml version="1.0" encoding="UTF-8"?>
<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-2.5.xsd">
<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.SimpleJobRepository">
<constructor-arg>
<bean class="org.springframework.batch.core.repository.dao.MapJobInstanceDao"/>
</constructor-arg>
<constructor-arg>
<bean class="org.springframework.batch.core.repository.dao.MapJobExecutionDao" />
</constructor-arg>
<constructor-arg>
<bean class="org.springframework.batch.core.repository.dao.MapStepExecutionDao"/>
</constructor-arg>
<constructor-arg>
<bean class="org.springframework.batch.core.repository.dao.MapExecutionContextDao"/>
</constructor-arg>
</bean>
</beans>
This is the error I am getting on the console
INFO: Destroying singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory#48ff2413: defining beans [jobLauncher,jobRepository,transactionManager,step,itemReader,lineTokenizer,fieldSetMapper,itemWriter,lineAggregator,simpleJob]; root of factory hierarchy
Oct 27, 2011 1:59:46 PM org.springframework.batch.core.launch.support.CommandLineJobRunner start
SEVERE: Job Terminated in error:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'step' defined in class path resource [itemOrientedJob.xml]: 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 [itemOrientedJob.xml]: Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'lineTokenizer' of bean class [org.springframework.batch.item.file.FlatFileItemReader]: Bean property 'lineTokenizer' 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.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:328)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:106)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1325)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1086)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:517)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
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.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83)
at org.springframework.batch.core.launch.support.CommandLineJobRunner.start(CommandLineJobRunner.java:190)
at org.springframework.batch.core.launch.support.CommandLineJobRunner.main(CommandLineJobRunner.java:254)
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'itemReader' defined in class path resource [itemOrientedJob.xml]: Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'lineTokenizer' of bean class [org.springframework.batch.item.file.FlatFileItemReader]: Bean property 'lineTokenizer' 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:1361)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1086)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:517)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
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.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:322)
... 16 more
Caused by: org.springframework.beans.NotWritablePropertyException: Invalid property 'lineTokenizer' of bean class [org.springframework.batch.item.file.FlatFileItemReader]: Bean property 'lineTokenizer' 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:1358)
... 24 more
Looks like the API of SimpleJobRepository has changed between 1.1.2 and 1.1.3 (bad moment to introduce backward incompatible change IMHO).
The tutorial you are following uses Spring Batch 1.1.1 where the class above had a constructor with three parameters. Now it has four. The extra parameter is ExecutionContextDao.
Here is my completely untested solution:
<bean id="jobRepository" class="org.springframework.batch.core.repository.support.SimpleJobRepository">
<constructor-arg>
<bean class="org.springframework.batch.core.repository.dao.MapJobInstanceDao"/>
</constructor-arg>
<constructor-arg>
<bean class="org.springframework.batch.core.repository.dao.MapJobExecutionDao" />
</constructor-arg>
<constructor-arg>
<bean class="org.springframework.batch.core.repository.dao.MapStepExecutionDao"/>
</constructor-arg>
<constructor-arg> <!-- Extra constructor argument -->
<bean class="org.springframework.batch.core.repository.dao.MapExecutionContextDao"/>
</constructor-arg>
</bean>
Never used Spring Batch, but perhaps you can use more recent tutorial (I don't recommend downgrading to 1.x)?

Categories