Translate

lunes, 30 de abril de 2012

MongoDB Error: java.lang.NoSuchFieldError: socketKeepAlive

Realizando unos tests de Junit con ANT, usando la tarea , sobre la aplicación que estamos creando que utiliza MongoDB nos apareció el siguiente error poco descriptivo:

 

    [junit] Grave: Caught exception while allowing TestExecutionListener [org.springframework.test.context.support.DependencyInjectionTestExecutionListener@1c81b84] to prepare test instance [com.xxxxx.xxxx.integration.ContentTemplateIntegrationTest@7c329d]
    [junit] java.lang.IllegalStateException: Failed to load ApplicationContext
    [junit]  at org.springframework.test.context.TestContext.getApplicationContext(TestContext.java:157)
    [junit]  at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.injectDependencies(DependencyInjectionTestExecutionListener.java:109)
    [junit]  at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.prepareTestInstance(DependencyInjectionTestExecutionListener.java:75)
    [junit]  at org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:321)
    [junit]  at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTest(SpringJUnit4ClassRunner.java:211)
    [junit]  at org.springframework.test.context.junit4.SpringJUnit4ClassRunner$1.runReflectiveCall(SpringJUnit4ClassRunner.java:288)
    [junit]  at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
    [junit]  at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.methodBlock(SpringJUnit4ClassRunner.java:290)
    [junit]  at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:231)
    [junit]  at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47)
    [junit]  at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
    [junit]  at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
    [junit]  at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
    [junit]  at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
    [junit]  at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
    [junit]  at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
    [junit]  at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:71)
    [junit]  at org.junit.runners.ParentRunner.run(ParentRunner.java:300)
    [junit]  at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:174)
    [junit]  at junit.framework.JUnit4TestAdapter.run(JUnit4TestAdapter.java:39)
    [junit]  at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.run(JUnitTestRunner.java:518)
    [junit]  at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.launch(JUnitTestRunner.java:1052)
    [junit]  at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.main(JUnitTestRunner.java:906)
    [junit] Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mongo': Cannot create inner bean '(inner bean)' of type [org.springframework.data.mongodb.core.MongoOptionsFactoryBean] while setting bean property 'mongoOptions'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)': Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.springframework.data.mongodb.core.MongoOptionsFactoryBean]: Constructor threw exception; nested exception is java.lang.NoSuchFieldError: socketKeepAlive
    [junit]  at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveInnerBean(BeanDefinitionValueResolver.java:281)
    [junit]  at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:125)
    [junit]  at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1360)
    [junit]  at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1118)
    [junit]  at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:517)
    [junit]  at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
    [junit]  at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:294)
    [junit]  at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225)
    [junit]  at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:291)
    [junit]  at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)
    [junit]  at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:567)
    [junit]  at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:913)
    [junit]  at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:464)
    [junit]  at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:103)
    [junit]  at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:1)
    [junit]  at org.springframework.test.context.support.DelegatingSmartContextLoader.loadContext(DelegatingSmartContextLoader.java:228)
    [junit]  at org.springframework.test.context.TestContext.loadApplicationContext(TestContext.java:124)
    [junit]  at org.springframework.test.context.TestContext.getApplicationContext(TestContext.java:148)
    [junit]  ... 22 more
    [junit] Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)': Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.springframework.data.mongodb.core.MongoOptionsFactoryBean]: Constructor threw exception; nested exception is java.lang.NoSuchFieldError: socketKeepAlive
    [junit]  at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:997)
    [junit]  at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:943)
    [junit]  at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:485)
    [junit]  at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
    [junit]  at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveInnerBean(BeanDefinitionValueResolver.java:270)
    [junit]  ... 39 more
    [junit] Caused by: org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.springframework.data.mongodb.core.MongoOptionsFactoryBean]: Constructor threw exception; nested exception is java.lang.NoSuchFieldError: socketKeepAlive
    [junit]  at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:162)
    [junit]  at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:76)
    [junit]  at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:990)
    [junit]  ... 43 more
    [junit] Caused by: java.lang.NoSuchFieldError: socketKeepAlive
    [junit]  at org.springframework.data.mongodb.core.MongoOptionsFactoryBean.(MongoOptionsFactoryBean.java:64)
    [junit]  at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    [junit]  at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
    [junit]  at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    [junit]  at java.lang.reflect.Constructor.newInstance(Constructor.java:525)
    [junit]  at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:147)
    [junit]  ... 45 more
    [junit] Tests run: 2, Failures: 0, Errors: 2, Time elapsed: 1,098 sec


Esto se debe a la configuración de la conexión de la aplicación con MongoDB en la que no detecta el parámetro socket-keep-alive
 

 <mongo:options connections-per-host="8"
                    threads-allowed-to-block-for-connection-multiplier="4"
                    connect-timeout="1000"
                    max-wait-time="1500"
                    auto-connect-retry="true"
                    socket-keep-alive="true"
                    socket-timeout="1500"
                    slave-ok="true"
                    write-number="1"
                    write-timeout="0"
                    write-fsync="true"/>

El error es poco descriptivo porque al principio creíamos que era un problema de versiones de los distintas librerías de MongoDB y de Spring Data JPA, pero en realidad el error se produjo porque la librería JAR de conexión de con MongoDB no estaba correctamente importada en el POM del proyecto.

 Una vez importado el jar mongo-2.7.3.jar todo funcionó correctamente y los tests pasaron correctamente.

miércoles, 18 de abril de 2012

java.lang.NoClassDefFoundError: flex2/tools/Compiler

Este error me ha ocurrido configurando un entono nuevo en eclipse de mis proyectos flex. El error se produce cuando lanzo un script para la compilación del proyecto flex con las tareas de Apache Ant, concretamente con la tarea mxmlc


    [mxmlc] java.lang.NoClassDefFoundError: flex2/tools/Compiler
    [mxmlc] Caused by: java.lang.ClassNotFoundException: flex2.tools.Compiler
    [mxmlc] at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
    [mxmlc] at java.security.AccessController.doPrivileged(Native Method)
    [mxmlc] at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
    [mxmlc] at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
    [mxmlc] at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
    [mxmlc] at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
    [mxmlc] Could not find the main class: flex2.tools.Compiler.  Program will exit.
    [mxmlc] Exception in thread "main" 


El problema consistía en que tenía ubicada la ruta de la máquina virtual de Java en una unidad distinta de disco distinta de la que se está compilando la aplicación.

En mi caso la ruta de la máquina virtual estaba en d:\java\jdks y el proyecto que se iba a compilar estaba en c:\trabajo\wokspace\ProyectoPrueba.

Una vez que cambié la jdk a un ruta en la misma unidad el problema no se reprodujo