I'm trying to get the Fixtures plugin working for my unit tests but every time I make it load data, I always get a BeanCreationException.
Here's how the setup method in my Spec looks like:
def fixtureLoader = new FixtureLoader(grailsApplication)
def setup() {
fixtureLoader.load {
person(Person, firstName: 'Juan', lastName: 'dela Cruz')
}
}
Every time I run any test I get:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'person': Initialization of bean failed; nested exception is java.lang.NullPointerException: Cannot invoke method getDomainClass() on null object
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:547)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:475)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:302)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:298)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:703)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:760)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:482)
at org.codehaus.groovy.grails.commons.spring.DefaultRuntimeSpringConfiguration.getApplicationContext(DefaultRuntimeSpringConfiguration.java:156)
at grails.spring.BeanBuilder.createApplicationContext(BeanBuilder.java:593)
at grails.plugin.fixtures.builder.FixtureBuilder.createApplicationContext(FixtureBuilder.groovy:140)
at grails.plugin.fixtures.Fixture.load(Fixture.groovy:43)
at grails.plugin.fixtures.FixtureLoader.load(FixtureLoader.groovy:50)
at demo.SampleSpec.setup(SampleSpec.groovy:16)
Caused by: java.lang.NullPointerException: Cannot invoke method getDomainClass() on null object
at grails.plugin.fixtures.builder.processor.FixtureBeanPostProcessor.getDomainClass(FixtureBeanPostProcessor.groovy:136)
at grails.plugin.fixtures.builder.processor.FixtureBeanPostProcessor.postProcessAfterInitialization(FixtureBeanPostProcessor.groovy:40)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsAfterInitialization(AbstractAutowireCapableBeanFactory.java:421)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1558)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:539)
... 14 more
Related
I have got a Grails 3.3.5 application with several Unit tests. While I run this tests individually they run as expected, but when I run a general test-app the tests fails with this message:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.grails.beans.ConstraintsEvaluator': Cannot resolve reference to bean 'grailsDomainClassMappingContext' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'grailsDatastore': Bean instantiation via constructor failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.grails.datastore.mapping.simple.SimpleMapDatastore]: Constructor threw exception; nested exception is org.springframework.core.convert.ConverterNotFoundException: No converter found capable of converting from type [java.lang.String] to type [java.util.Map<?, ?>]
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.ConstructorResolver.resolveConstructorArguments(ConstructorResolver.java:648)
at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:145)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1197)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1099)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:513)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:312)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:308)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:761)
at org.grails.testing.GrailsUnitTest$Trait$Helper.defineBeans(GrailsUnitTest.groovy:100)
at org.grails.testing.gorm.spock.DataTestSetupSpecInterceptor.setupDataTestBeans(DataTestSetupSpecInterceptor.groovy:50)
at org.grails.testing.gorm.spock.DataTestSetupSpecInterceptor.configureDataTest(DataTestSetupSpecInterceptor.groovy:85)
at org.grails.testing.gorm.spock.DataTestSetupSpecInterceptor.intercept(DataTestSetupSpecInterceptor.groovy:43)
at org.spockframework.runtime.extension.MethodInvocation.proceed(MethodInvocation.java:87)
at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecuter.runTestClass(JUnitTestClassExecuter.java:114)
at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecuter.execute(JUnitTestClassExecuter.java:57)
at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassProcessor.processTestClass(JUnitTestClassProcessor.java:66)
at org.gradle.api.internal.tasks.testing.SuiteTestClassProcessor.processTestClass(SuiteTestClassProcessor.java:51)
at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:35)
at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
at org.gradle.internal.dispatch.ContextClassLoaderDispatch.dispatch(ContextClassLoaderDispatch.java:32)
at org.gradle.internal.dispatch.ProxyDispatchAdapter$DispatchingInvocationHandler.invoke(ProxyDispatchAdapter.java:93)
at org.gradle.api.internal.tasks.testing.worker.TestWorker.processTestClass(TestWorker.java:109)
at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:35)
at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
at org.gradle.internal.remote.internal.hub.MessageHubBackedObjectConnection$DispatchWrapper.dispatch(MessageHubBackedObjectConnection.java:147)
at org.gradle.internal.remote.internal.hub.MessageHubBackedObjectConnection$DispatchWrapper.dispatch(MessageHubBackedObjectConnection.java:129)
at org.gradle.internal.remote.internal.hub.MessageHub$Handler.run(MessageHub.java:404)
at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:63)
at org.gradle.internal.concurrent.StoppableExecutorImpl$1.run(StoppableExecutorImpl.java:46)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'grailsDatastore': Bean instantiation via constructor failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.grails.datastore.mapping.simple.SimpleMapDatastore]: Constructor threw exception; nested exception is org.springframework.core.convert.ConverterNotFoundException: No converter found capable of converting from type [java.lang.String] to type [java.util.Map<?, ?>]
at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:279)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1197)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1099)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:513)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:312)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:308)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:372)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1177)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1071)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:513)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:312)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:308)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:351)
... 36 more
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.grails.datastore.mapping.simple.SimpleMapDatastore]: Constructor threw exception; nested exception is org.springframework.core.convert.ConverterNotFoundException: No converter found capable of converting from type [java.lang.String] to type [java.util.Map<?, ?>]
at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:154)
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:122)
at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:271)
... 54 more
Caused by: org.springframework.core.convert.ConverterNotFoundException: No converter found capable of converting from type [java.lang.String] to type [java.util.Map<?, ?>]
at org.springframework.core.convert.support.GenericConversionService.handleConverterNotFound(GenericConversionService.java:324)
at org.springframework.core.convert.support.GenericConversionService.convert(GenericConversionService.java:206)
at org.springframework.core.convert.support.GenericConversionService.convert(GenericConversionService.java:187)
at org.springframework.core.env.AbstractPropertyResolver.convertValueIfNecessary(AbstractPropertyResolver.java:266)
at org.springframework.core.env.PropertySourcesPropertyResolver.getProperty(PropertySourcesPropertyResolver.java:87)
at org.springframework.core.env.PropertySourcesPropertyResolver.getProperty(PropertySourcesPropertyResolver.java:66)
at org.springframework.core.env.AbstractPropertyResolver.getProperty(AbstractPropertyResolver.java:169)
at org.springframework.core.env.AbstractEnvironment.getProperty(AbstractEnvironment.java:542)
at org.grails.datastore.mapping.core.connections.AbstractConnectionSources.getConnectionSourceNames(AbstractConnectionSources.groovy:52)
at org.grails.datastore.mapping.core.connections.InMemoryConnectionSources.<init>(InMemoryConnectionSources.groovy:24)
at org.grails.datastore.mapping.core.connections.ConnectionSourcesInitializer.create(ConnectionSourcesInitializer.groovy:28)
at org.grails.datastore.mapping.simple.SimpleMapDatastore.<init>(SimpleMapDatastore.java:117)
at org.grails.datastore.mapping.simple.SimpleMapDatastore.<init>(SimpleMapDatastore.java:178)
at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:142)
... 56 more
Here's one of the unit test that works as expected when runned individually but fails with the global test:
package my.package
import grails.testing.gorm.DomainUnitTest
import spock.lang.Specification
class CapituloSpec extends Specification implements DomainUnitTest<Capitulo> {
void "test id cannot be null"() {
when:
domain.id = null
then:
!domain.validate(['id'])
domain.errors['id'].code == 'nullable'
}
void "test titulo cannot be null or blank"() {
when:
domain.titulo = null
then:
!domain.validate(['titulo'])
domain.errors['titulo'].code == 'nullable'
when:
domain.titulo = ''
then:
!domain.validate(['titulo'])
domain.errors['titulo'].code == 'blank'
}
void "test titulo maxSize"() {
when: "titulo is 101 characters length"
domain.titulo = 'a' * 101
then: "titulo validation fails"
!domain.validate(['titulo'])
domain.errors['titulo'].code == 'maxSize.exceeded'
when: "titulo is 100 characters length"
domain.titulo = 'a' * 100
then: "titulo validation succeed"
domain.validate(['titulo'])
}
void "test capitulo ok"() {
when:
domain.id = 1
domain.titulo = "Test"
then:
domain.validate()
}
}
How can I solve this problems and run my tests together and not individually.
EDIT: I forgot to mention that I'm using two datasources, one default to save almost all the application data, and another one to save only 6 domains shared with another application.
Finally I've found a way to avoid the errors and run all the tests together. I must configure the datasource in all the tests using the doWithSpring closure.
First I made a Trait to configure the datasource using the applicationContext and the datasource name (if not given use the 'default' datasource):
package my.package
import groovy.transform.CompileStatic
import org.springframework.context.ConfigurableApplicationContext
import org.springframework.core.convert.support.ConfigurableConversionService
import org.springframework.core.convert.converter.Converter
#CompileStatic
trait MultiDatasourceTest {
def configDatasource(ConfigurableApplicationContext applicationContext, String datasource = "default") {
System.setProperty("grails.gorm.connections", datasource)
ConfigurableConversionService conversionService = applicationContext.getEnvironment().getConversionService()
conversionService.addConverter(new StringToMapConverter())
}
}
class StringToMapConverter implements Converter<String, Map> {
#Override
Map convert(String source) {
source.split(",").collectEntries({
[(it):it]
})
}
}
Next I must add the trait to all my tests and call the configDatasource with the application context and the datasource name, if it's not the default one.
Default datasource:
package my.package
import grails.testing.gorm.DomainUnitTest
import org.springframework.context.ConfigurableApplicationContext
import spock.lang.Specification
class CapituloSpec extends Specification implements DomainUnitTest<Capitulo>, MultiDatasourceTest {
#Override
Closure doWithSpring() {
return {
configDatasource(application.mainContext as ConfigurableApplicationContext)
}
}
void "test id cannot be null"() {
when:
domain.id = null
then:
!domain.validate(['id'])
domain.errors['id'].code == 'nullable'
}
// More tests
}
Another datasource:
package my.package
import grails.testing.gorm.DomainUnitTest
import org.springframework.context.ConfigurableApplicationContext
import spock.lang.Specification
class DocumentoTeoSpec extends Specification implements DomainUnitTest<DocumentoTeo>, MultiDatasourceTest {
#Override
Closure doWithSpring() {
return {
configDatasource(application.mainContext as ConfigurableApplicationContext, "sede")
}
}
void "test numeroExpediente cannot be null or blank"() {
when:
domain.numeroExpediente = null
then:
!domain.validate(['numeroExpediente'])
domain.errors['numeroExpediente'].code == 'nullable'
when:
domain.numeroExpediente = ''
then:
!domain.validate(['numeroExpediente'])
domain.errors['numeroExpediente'].code == 'blank'
when: "numeroExpediente is 21 characters long"
domain.numeroExpediente = 'a' * 21
then: "numeroExpediente validation fails"
!domain.validate(['numeroExpediente'])
domain.errors['numeroExpediente'].code == 'maxSize.exceeded'
when: "numeroExpediente is 20 characters long"
domain.numeroExpediente = 'a' * 20
then: "numeroExpediente validation succeed"
domain.validate(['numeroExpediente'])
}
// More tests
}
I have the following code in Grails:
public LibraryItem createLibraryItemWithValues(ProjectItem projectItem) {
def libraryitem = new LibraryItem ()
libraryitem.name = projectItem.name
libraryitem.itemtype = projectItem.itemtype.itemtype
libraryitem.description = projectItem.description
List<LibraryCategoryValue> libCatValues = new ArrayList<LibraryCategoryValue>();
for (def pcv : projectItem.categoryvalues) {
libCatValues.add(pcv.librarycategoryvalue);
}
if (libraryitem.id != null && !libraryitem.isAttached()) {
libraryitem.attach()
}
libCatValues.each{
it.addToLibraryitems(libraryitem)
}
return libraryitem.save()
}
The class LibraryCategoryValue
package ch.fhnw.accelerom.project.library
import ch.fhnw.accelerom.project.ItemType
import ch.fhnw.accelerom.project.TranslatableObject
class LibraryCategoryValue extends TranslatableObject {
SortedSet<LibraryItem> libraryitems
static belongsTo = [librarycategory:LibraryCategory]
static hasMany = [libraryitems: LibraryItem]
static constraints = {
}
}
My problem is, that I get the exception "IndexOutOfBoundsException" with the detailMessage "Index:1, Size 0" and suppressedExceptions "Collections$UnmodifiableRandomAccessList" with Value "size = 0" when I run this code in the service but there is no exception, when I run this code in the controller. The exception comes from the command it.addToLibraryitems(libraryitem), respektive, when I comment this line, than no exception occur. Can someone give me a hint, what the problem could be?
Thanks in advance.
Edit:
I now initialized libraryitems in the class with
SortedSet<LibraryItem> libraryitems = []
but now I get the following error when I start the application
ERROR context.GrailsContextLoader - Error initializing the application: Error creating bean with name 'transactionManagerPostProcessor': Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManager': Cannot resolve reference to bean 'sessionFactory' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory': Invocation of init method failed; nested exception is org.hibernate.InstantiationException: could not instantiate test objectch.fhnw.accelerom.project.library.LibraryCategoryValue
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManagerPostProcessor': Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManager': Cannot resolve reference to bean 'sessionFactory' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory': Invocation of init method failed; nested exception is org.hibernate.InstantiationException: could not instantiate test objectch.fhnw.accelerom.project.library.LibraryCategoryValue
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.factory.BeanCreationException: Error creating bean with name 'transactionManager': Cannot resolve reference to bean 'sessionFactory' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory': Invocation of init method failed; nested exception is org.hibernate.InstantiationException: could not instantiate test objectch.fhnw.accelerom.project.library.LibraryCategoryValue
... 4 more
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory': Invocation of init method failed; nested exception is org.hibernate.InstantiationException: could not instantiate test objectch.fhnw.accelerom.project.library.LibraryCategoryValue
... 4 more
Caused by: org.hibernate.InstantiationException: could not instantiate test objectch.fhnw.accelerom.project.library.LibraryCategoryValue
... 4 more
Caused by: java.lang.reflect.InvocationTargetException
... 4 more
Caused by: org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast object '[]' with class 'java.util.ArrayList' to class 'java.util.SortedSet' due to: groovy.lang.GroovyRuntimeException: Could not find matching constructor for: java.util.SortedSet()
at ch.fhnw.accelerom.project.library.LibraryCategoryValue.<init>(LibraryCategoryValue.groovy:7)
... 4 more
Edit 2:
I also tried to initialize libraryitems with
SortedSet<LibraryItem> libraryitems = new TreeSet<LibraryItem>()
But then I'm back on the first exception "IndexOutOfBoundsException". I'm so wondering, why there is no problem, when this code is in the controller. What's the difference between a service and a controller in this case?
Try using a transactional service method:
import grails.transaction.Transactional
class LibraryService {
#Transactional
public LibraryItem createLibraryItemWithValues(ProjectItem projectItem) {
def libraryitem = new LibraryItem()
libraryitem.name = projectItem.name
libraryitem.itemtype = projectItem.itemtype.itemtype
libraryitem.description = projectItem.description
projectItem.categoryvalues*.librarycategoryvalue.each {
it.addToLibraryitems(libraryitem)
}
return libraryitem.save()
}
}
Since you're creating a new LibraryItem it's ID will always be null until you save it. In most cases you don't need to use attach(), so I removed all of that code.
I am tyring to configure login using twitter in my grails application
getting this stack trace when i do run-app
Server running. Browse to http://localhost:8080/TestOAuth
Error initializing the application: Error creating bean with name 'uk.co.desirableobjects.oauth.scribe.OauthController': Initialization of bean failed;<br/>
nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'oauthService': Invocation of init method failed; nested exception is uk.co.desirableobjects.oauth.scribe.exception.InvalidOauthProviderException: [:] is not a Class <br/>
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'uk.co.desirableobjects.oauth.scribe.OauthController': Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'oauthService': Invocation of init method failed; nested exception is uk.co.desirableobjects.oauth.scribe.exception.InvalidOauthProviderException: [:] is not a Class
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
at java.util.concurrent.FutureTask.run(FutureTask.java:166)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
at java.lang.Thread.run(Thread.java:722) <br/>
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'oauthService': Invocation of init method failed; nested exception is uk.co.desirableobjects.oauth.scribe.exception.InvalidOauthProviderException: [:] is not a Class
... 5 more <br/>
Caused by: uk.co.desirableobjects.oauth.scribe.exception.InvalidOauthProviderException: [:] is not a Class
at uk.co.desirableobjects.oauth.scribe.OauthService.afterPropertiesSet(OauthService.groovy:48)
... 5 more
| Error Forked Grails VM exited with error
this is what i configured for twitter
oauth {
providers {
twitter {
api = 'TwitterApi'
key = 'i have my key here'
secret = 'i have my secrete key here'
successUri = '/success.gsp'
failureUri = '/fail.gsp'
}
}
debug = true
}
The provider API is a class (from scribe API) instead of String, which has to be referred in the config.
import org.scribe.builder.api.TwitterApi
oauth {
providers {
twitter {
api = TwitterApi
key = 'i have my key here'
secret = 'i have my secrete key here'
successUri = '/success.gsp'
failureUri = '/fail.gsp'
}
}
debug = true
}
I am in the process of upgrading an app from Grails 1.3.9 to Grails 2.2.1. When I issue the run-app command, I get a long stacktrace that begins with this error and then more or less repeats it for about 400 lines:
2013-03-07 13:32:11.364 ERROR [ StackTrace] Full Stack Trace:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManagerPostProcessor': Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManager': Cannot resolve reference to bean 'sessionFactory' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory': Invocation of init method failed; nested exception is org.hibernate.MappingException: property [sponsoringManager] not found on entity [com.mycompany.myapp.ManagerDelegate]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:527)
at org.codehaus.groovy.grails.commons.spring.ReloadAwareAutowireCapableBeanFactory.doCreateBean(ReloadAwareAutowireCapableBeanFactory.java:118)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:294)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:291)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
at org.springframework.context.support.AbstractApplicationContext.registerBeanPostProcessors(AbstractApplicationContext.java:713)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:457)
at org.codehaus.groovy.grails.commons.spring.DefaultRuntimeSpringConfiguration.getApplicationContext(DefaultRuntimeSpringConfiguration.java:153)
at org.codehaus.groovy.grails.commons.spring.GrailsRuntimeConfigurator.configure(GrailsRuntimeConfigurator.java:170)
at org.codehaus.groovy.grails.commons.spring.GrailsRuntimeConfigurator.configure(GrailsRuntimeConfigurator.java:127)
at org.codehaus.groovy.grails.web.context.GrailsConfigUtils.configureWebApplicationContext(GrailsConfigUtils.java:121)
at org.codehaus.groovy.grails.web.context.GrailsContextLoader.initWebApplicationContext(GrailsContextLoader.java:107)
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:111)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4791)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5285)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
at java.util.concurrent.FutureTask.run(FutureTask.java:138)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:662)
I think the pertinent part is this:
org.hibernate.MappingException: property [sponsoringManager] not found on entity [com.mycompany.myapp.ManagerDelegate]
Here's the code for the ManagerDelegate domain class, which is a many to many join class:
package com.mycompany.myapp
class ManagerDelegate extends Base implements Serializable {
static belongsTo = [sponsoringManager:User, delegate:User]
boolean equals(other) {
if (!(other instanceof ManagerDelegate)) {
return false
}
other.sponsoringManager.id == sponsoringManager.id && other.delegate.id == delegate.id
}
static mapping = {
id composite: [
'sponsoringManager',
'delegate'
]
version false
}
}
As you can see, ManagerDelegate does contain a sponsoringManager property which is declared in the belongsTo statement. This worked perfectly in Grails 1.3.9.
Here is the User class:
class User {
static hasMany = [sponsoringManagers: ManagerDelegate, delegates: ManagerDelegate]
static mappedBy = [sponsoringManagers: "delegate", delegates: "sponsoringManager"]
static mapping = {
id generator: 'uuid'
sponsoringManagers cascade: 'all-delete-orphan'
delegates cascade: 'all-delete-orphan'
}
...
}
When I try to access the app from my browser, nothing is displayed and no log output is produced.
I'm trying to expose a webservice via grails & cxf grails plugin.
this is the skeleton of the webservice:
class IssueService {
static expose=['cxf']
def List issueList(){
def list = Issue.list()
return list
}
def Issue singleIssue(id){
def currentIssue = Issue.findById(id)
return currentIssue
}
}
the method "singleIssue" works correctly but the method "issueList" throws a jaxb marshall exception
org.apache.cxf.interceptor.Fault: Marshalling Error: java.util.ArrayList is not known to this context
at org.apache.cxf.jaxb.JAXBEncoderDecoder.marshall(JAXBEncoderDecoder.java:159)
at org.apache.cxf.jaxb.io.DataWriterImpl.write(DataWriterImpl.java:169)
at org.apache.cxf.interceptor.AbstractOutDatabindingInterceptor.writeParts(AbstractOutDatabindingInterceptor.java:105)
at org.apache.cxf.interceptor.BareOutInterceptor.handleMessage(BareOutInterceptor.java:68)
at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:236)
at org.apache.cxf.interceptor.OutgoingChainInterceptor.handleMessage(OutgoingChainInterceptor.java:74)
at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:236)
at org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiationObserver.java:104)
at org.apache.cxf.transport.servlet.ServletDestination.invoke(ServletDestination.java:99)
at org.apache.cxf.transport.servlet.ServletController.invokeDestination(ServletController.java:452)
at org.apache.cxf.transport.servlet.ServletController.invoke(ServletController.java:159)
at org.apache.cxf.transport.servlet.AbstractCXFServlet.invoke(AbstractCXFServlet.java:220)
at org.apache.cxf.transport.servlet.AbstractCXFServlet.doGet(AbstractCXFServlet.java:158)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:707)
at org.apache.cxf.transport.servlet.AbstractCXFServlet.service(AbstractCXFServlet.java:211)
at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:502)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1124)
at org.codehaus.groovy.grails.web.mapping.filter.UrlMappingsFilter.processFilterChain(UrlMappingsFilter.java:263)
at org.codehaus.groovy.grails.web.mapping.filter.UrlMappingsFilter.doFilterInternal(UrlMappingsFilter.java:205)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1115)
at org.codehaus.groovy.grails.web.sitemesh.GrailsPageFilter.obtainContent(GrailsPageFilter.java:221)
at org.codehaus.groovy.grails.web.sitemesh.GrailsPageFilter.doFilter(GrailsPageFilter.java:126)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1115)
at org.codehaus.groovy.grails.web.servlet.filter.GrailsReloadServletFilter.doFilterInternal(GrailsReloadServletFilter.java:101)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1115)
at org.codehaus.groovy.grails.web.servlet.mvc.GrailsWebRequestFilter.doFilterInternal(GrailsWebRequestFilter.java:65)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1115)
at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:96)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:236)
at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:167)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1115)
at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:361)
at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:181)
at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:766)
at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:417)
at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
at org.mortbay.jetty.Server.handle(Server.java:324)
at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:534)
at org.mortbay.jetty.HttpConnection$RequestHandler.headerComplete(HttpConnection.java:864)
at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:533)
at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:207)
at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:403)
at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:409)
at org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:522)
Caused by: javax.xml.bind.MarshalException
- with linked exception:
[javax.xml.bind.JAXBException: java.util.ArrayList is not known to this context]
at com.sun.xml.bind.v2.runtime.MarshallerImpl.write(MarshallerImpl.java:318)
at com.sun.xml.bind.v2.runtime.MarshallerImpl.marshal(MarshallerImpl.java:244)
at javax.xml.bind.helpers.AbstractMarshallerImpl.marshal(AbstractMarshallerImpl.java:75)
at org.apache.cxf.jaxb.JAXBEncoderDecoder.writeObject(JAXBEncoderDecoder.java:444)
at org.apache.cxf.jaxb.JAXBEncoderDecoder.marshall(JAXBEncoderDecoder.java:138)
... 48 more
Caused by: javax.xml.bind.JAXBException: java.util.ArrayList is not known to this context
at com.sun.xml.bind.v2.runtime.XMLSerializer.reportError(XMLSerializer.java:246)
at com.sun.xml.bind.v2.runtime.XMLSerializer.reportError(XMLSerializer.java:261)
at com.sun.xml.bind.v2.runtime.ElementBeanInfoImpl$1.serializeBody(ElementBeanInfoImpl.java:144)
at com.sun.xml.bind.v2.runtime.ElementBeanInfoImpl$1.serializeBody(ElementBeanInfoImpl.java:189)
at com.sun.xml.bind.v2.runtime.ElementBeanInfoImpl.serializeBody(ElementBeanInfoImpl.java:315)
at com.sun.xml.bind.v2.runtime.ElementBeanInfoImpl.serializeRoot(ElementBeanInfoImpl.java:322)
at com.sun.xml.bind.v2.runtime.ElementBeanInfoImpl.serializeRoot(ElementBeanInfoImpl.java:72)
at com.sun.xml.bind.v2.runtime.XMLSerializer.childAsRoot(XMLSerializer.java:494)
at com.sun.xml.bind.v2.runtime.MarshallerImpl.write(MarshallerImpl.java:315)
... 52 more
Caused by: javax.xml.bind.JAXBException: java.util.ArrayList is not known to this context
at com.sun.xml.bind.v2.runtime.JAXBContextImpl.getBeanInfo(JAXBContextImpl.java:621)
at com.sun.xml.bind.v2.runtime.ElementBeanInfoImpl$1.serializeBody(ElementBeanInfoImpl.java:141)
... 58 more
Similar exception is trown also if i make the method return an array of Issue Objects
to further clarify the problem:
package it.weservice.tools.bts
class TestService {
static expose=['cxf']
String[] testMethod(){
def result = ["string1", "string2"]
return result as String[]
}
}
returns
org.apache.cxf.interceptor.Fault: Marshalling Error: [Ljava.lang.String; is not known to this context
I solved the problem exposing explicitly the webservice via
static expose=['cxfjax']
and by annotating the methods I want to expose with the #WebMethod annotation
Saluti