Cannot convert value of type [org.springframework.core.env.StandardEnvironment] to required type - spring

I try to upgrade spring from 3.0 to 3.2.8, but I receive the following error
Cannot convert value of type [org.springframework.core.env.StandardEnvironment] to required type [xxx] for property 'environment': no matching editors or conversion strategy found
I guess its some name conflict to an new class StandardEnvironment, but I don't find any place that defines the property 'environment'
Any help please?

It seems that I have a function called setEnvironment which is in conflict with some spring builtin function setEnvironment which is used to set StandardEnvironment when initialize spring framework, so I changed function name to something else, so it worked. really weird problem.

Here is your issue:
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'backOfficeContext' defined in class path resource [se/softronic/appia/cache/DomainSpecificEhCacheBeanPostProcessorTest-context.xml]:
The class for bean 'backOfficeContext' contains property BackOfficeEnvironment environment
So, just change the environment property name to something another, or get rid of default-autowire="byName" and just rely on byType by default.

Related

Spring Boot Auto-Configuration of object type

I'm probably in a very wrong direction here but failing to see the obvious:
In a Camel component documentation for RabbitMQ (https://camel.apache.org/components/3.18.x/spring-rabbitmq-component.html)
, one can read that we can set auto-config property "camel.component.spring-rabbitmq.message-properties-converter" as "a org.apache.camel.component.springrabbit.MessagePropertiesConverter type".
What does this mean in practice ?
I have tried to set it as a class name (string) of a class that implements org.apache.camel.component.springrabbit.MessagePropertiesConverter : it didn't work (no error, warning or any other evidence the custom class was being used)
I have tried to set it as the name of a bean of a MessagePropertiesConverter it didn't work.
Exactly what should be in a ".properties|yaml" file that can be of "MessagePropertiesConverter type" ?

Cannot convert value of type [org.hibernate.impl.SessionFactoryImpl] to required type [com.liferay.portal.kernel.dao.orm.SessionFactory]

I got this exception!!!
Caused by: java.lang.IllegalStateException: Cannot convert value of type [org.hibernate.impl.SessionFactoryImpl] to required type [com.liferay.portal.kernel.dao.orm.SessionFactory] for property 'sessionFactory': no matching editors or conversion strategy found
at org.springframework.beans.TypeConverterDelegate.convertIfNecessary(TypeConverterDelegate.java:289)
at org.springframework.beans.TypeConverterDelegate.convertIfNecessary(TypeConverterDelegate.java:154)
at org.springframework.beans.BeanWrapperImpl.convertForProperty(BeanWrapperImpl.java:452)
... 41 more
Do you have any solution?
One of the beans that you pass sessionFactory to them require the Liferay one instead of the Hibernate one.
There are 2 possible mistakes:
You made a mistake in wiring - fix that by passing Lifray's SessionFactory (create one if you don't have one already)
The mistake is in Java class imports - fix the imports

ConversionNotSupportedException: Failed to convert property value of type 'grails.spring.BeanBuilder' to required type 'java.lang.String'

I'm working on this grails-aws plugin and get a strange error trying to run under Grails 2.3.4 and 2.3.5.
See travis build output where the tests pass for Grails 2.0.4 / 2.2.4, but fail for 2.3.4 / 2.3.5
Has something changed with grails 2.3.x in the area of reading values from config files?
Error creating bean with name 'credentialsHolder': Initialization of bean failed; nested exception is org.springframework.beans.ConversionNotSupportedException: Failed to convert property value of type 'grails.spring.BeanBuilder' to required type 'java.lang.String' for property 'accessKey'; nested exception is java.lang.IllegalStateException: Cannot convert value of type [grails.spring.BeanBuilder] to required type [java.lang.String] for property 'accessKey': no matching editors or conversion strategy found (NOTE: Stack trace has been filtered. Use --verbose to see entire trace.)
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'credentialsHolder': Initialization of bean failed; nested exception is org.springframework.beans.ConversionNotSupportedException: Failed to convert property value of type 'grails.spring.BeanBuilder' to required type 'java.lang.String' for property 'accessKey'; nested exception is java.lang.IllegalStateException: Cannot convert value of type [grails.spring.BeanBuilder] to required type [java.lang.String] for property 'accessKey': no matching editors or conversion strategy found
This is explained in this Grails JIRA - apparently the BeanBuilder invokes its closures with "delegate first" behaviour, but there was previously a bug in Groovy that meant calls that matched a static method of the containing scope ignored the resolve strategy setting and called the static method anyway. In other words the code you've previously been using only ever worked by accident. You should still be able to call the static method if you qualify it with the class name AwsPluginSupport.read(...).
Alternatively you could skip the gymnastics entirely - use literal '${....}' expressions for the bean properties and let the property placeholder mechanism pull the values out of the config for you. I.e. instead of
credentialsHolder(AWSCredentialsHolder) {
accessKey = readString("credentials.accessKey")
secretKey = readString("credentials.secretKey")
properties = readString("credentials.properties")
}
use
credentialsHolder(AWSCredentialsHolder) {
accessKey = '${grails.plugin.aws.credentials.accessKey}'
secretKey = '${grails.plugin.aws.credentials.secretKey}'
properties = '${grails.plugin.aws.credentials.properties}'
}
Note that it's important that these are single quoted strings (so the value is an expression including ${} that Spring can resolve) and not double quoted GStrings (which would [fail to] be resolved by Groovy at parse time).
Pull request submitted as a fix for this issue.

Intellij incorrectly highlighting error in bean definition with spring

Could not autowire bean should be off type ..NamedPArameterJDBCTemplate
Which is wrong on two counts ... ?
There's a space at the beginning of your class attribute value in your XML file.

2 beans with same name but in different packages; how to autowire them?

I have an application that has 2 beans with the same name, but which are in different packages. My Spring application fails because it cannot decide on which bean to take. Is there any solution for this? The beans do not currently implement specific interfaces.
See below an edited example of the exception:
Caused by:
org.springframework.context.annotation.ConflictingBeanDefinitionException:
Annotation-specified bean name 'dataTransferHandler' for bean class
[aaaaa.ws.handler.DataTransferHandler] conflicts with existing,
non-compatible bean definition of same name and class
[bbbbb.ws.handler.DataTransferHandler]
You will have to give your beans different names - if multiple beans are defined with the same name, then the one defined later will override the one defined earlier - so in your case only one bean will exist with the name of dataTransferHandler.
You can give these two beans different names, so that both can exist and you can inject in the correct one either using:
#AutoWired #Qualifier("dataTransferHandler")
OR
#Resource(name="dataTransferHandler")
You can give attribute primary="true" to the bean defination you want to have the preference when autowired. But the bean names must be different. There is no solution for same bean name.
At run-time when you will get the autowired class then the primary true bean will get the preference for autowiring. Hope this helps you. Cheers.
I asked another question regarding the same problem, and there is a solution that doesn't require using the #Qualifier annotation: if both of your DataTransferHandler classes have a #Component annotation, you can simply add a String argument to one of their constructions (i.e. #Component("Foo")), and that should solve the problem without needing additional changes.
See User9123's answer on my question for more details.

Resources