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

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.

Related

Using spring-data-mongodb and spring-data-neo4j together

How can I use spring-data-mongodb and spring-data-neo4j in the same spring-boot application?
I can easily use one or the other following the "getting started" guides, but as soon as I try to add Neo4J to a MongoDB application then I get runtime errors such as:
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'application': Unsatisfied dependency expressed through field 'repository'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'bookRepository': Invocation of init method failed; nested exception is org.springframework.data.mapping.PropertyReferenceException: No property findAll found for type MongoBook!
I've setup a minimal example at https://github.com/afaulconbridge/myspring-mongo-neo
You can try this project which uses JPA and Neo4J together. The structure should technically work with Mongo as well. Be aware though that Mongo doesn't support the concept of transactions so you may not have to define an explicit transaction manager for each Spring Data project.
As #manish pointed out, you need to make Spring Data MongoDB and Spring Data Neo4J scan separate packages. i.e.
#EnableMongoRepositories(basePackageClasses=MongoBook.class)
#EnableNeo4jRepositories(basePackageClasses=NeoAuthor.class)
I've updated the example project at https://github.com/afaulconbridge/myspring-mongo-neo with a solution.
You should be able to use excludeFilters and includeFilters parameters respectively even in the same package (in most cases includeFilters is enough)
#EnableMongoRepositories(basePackageClasses=MongoBook.class,
includeFilters ={#ComponentScan.Filter(type = FilterType.ASSIGNABLE_TYPE,
classes = {MongoRepository.class}))
#EnableNeo4jRepositories(basePackageClasses=NeoAuthor.class,
includeFilters ={#ComponentScan.Filter(type = FilterType.ASSIGNABLE_TYPE,
classes = {NeoRepository.class}))
from includeFilters() description
Specifies which types are eligible for component scanning. Further
narrows the set of candidate components from everything in {#basePackages()} to everything in the base packages that matches the given filter or filters.

#Value not resolving using <context:property-placeholder location=" />

Hey guys I have a problem. I'm using Spring and I have a class with an injected boolean
protected boolean ignoreVisibleFlag;
I have verified that indeed that property lives in my properties file:
and I have verified that I have this in my Application Context XML:
<context:property-placeholder location="classpath.properties" />
However I still get the following stack trace:
Caused by: org.springframework.beans.TypeMismatchException: Failed to convert value of type 'java.lang.String' to required type 'boolean'; nested exception is java.lang.IllegalArgumentException: Invalid boolean value
at org.springframework.beans.TypeConverterSupport.doConvert(TypeConverterSupport.java:77)
Any ideas?
From past experience using primitive wasn't able to handle the casting from string (as read) to boolean.
What you need to do is use Object instead of the primitive which will enable the conversion process from String to boolean.
#Value("${mojo.ignoreAlertsVisibleFlag}")
protected Boolean ignoreVisibleFlag;
M. Deinum's fix worked. I needed to add the to my dispatcher servlet.

Grails 2.4.3 Upgrade - Spring Security ACl - SpelExpressionParser

Getting the below error while running the app, no issues during compile. Kindly help, how to fix this issue.
ERROR [localhost-startStop-1] 2014-09-26 19:19:19,050 org.codehaus.groovy.grails.web.context.GrailsContextLoaderListener.error(213) : Error initializing the application: Error creating bean with name 'flowBuilderServices': Initialization of bean failed; nested exception is org.springframework.beans.ConversionNotSupportedException: Failed to convert property value of type 'org.springframework.expression.spel.standard.SpelExpressionParser' to required type 'org.springframework.binding.expression.ExpressionParser' for property 'expressionParser'; nested exception is java.lang.IllegalStateException: Cannot convert value of type [org.springframework.expression.spel.standard.SpelExpressionParser] to required type [org.springframework.binding.expression.ExpressionParser] for property 'expressionParser': no matching editors or conversion strategy found
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'flowBuilderServices': Initialization of bean failed; nested exception is org.springframework.beans.ConversionNotSupportedException: Failed to convert property value of type 'org.springframework.expression.spel.standard.SpelExpressionParser' to required type 'org.springframework.binding.expression.ExpressionParser' for property 'expressionParser'; nested exception is java.lang.IllegalStateException: Cannot convert value of type [org.springframework.expression.spel.standard.SpelExpressionParser] to required type [org.springframework.binding.expression.ExpressionParser] for property 'expressionParser': no matching editors or conversion strategy found
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:745)
Caused by: org.springframework.beans.ConversionNotSupportedException: Failed to convert property value of type 'org.springframework.expression.spel.standard.SpelExpressionParser' to required type 'org.springframework.binding.expression.ExpressionParser' for property 'expressionParser'; nested exception is java.lang.IllegalStateException: Cannot convert value of type [org.springframework.expression.spel.standard.SpelExpressionParser] to required type [org.springframework.binding.expression.ExpressionParser] for property 'expressionParser': no matching editors or conversion strategy found
... 4 more
Caused by: java.lang.IllegalStateException: Cannot convert value of type [org.springframework.expression.spel.standard.SpelExpressionParser] to required type [org.springframework.binding.expression.ExpressionParser] for property 'expressionParser': no matching editors or conversion strategy found
What plugins are you using? I was getting the same exception when upgrading to Grails 2.4.3 and just narrowed it down (it wasn't easy) to the fact that the Grails WebFlow plugin and the ACL plugin both setup a bean named expressionParser, but each plugin is using a different class... one is overwriting the other during Grails initialization of spring beans. By renaming the web flow plugin's expressionParser to flowExpressionParser in the WebFlowPluginSupport.groovy file, I was able to get around this exception. You could search in your plugins directory for 'expressionParser' and see if you have >1 plugin using it.
I have let the webflow plugin folks know, and a bit more detail here.
https://jira.grails.org/browse/GPWEBFLOW-109

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

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

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.

Resources