35

I have just migrated Spring 3.0.5 to 3.1 GA. I faced runtime error during initialization:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor#0': Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in ServletContext resource [/WEB-INF/spring/infrastructure-config.xml]: Initialization of bean failed; nested exception is java.lang.NoSuchFieldError: NULL
...
Caused by: java.lang.NoSuchFieldError: NULL
    at org.springframework.expression.TypedValue.<clinit>(TypedValue.java:32)
    at org.springframework.expression.spel.support.StandardEvaluationContext.setRootObject(StandardEvaluationContext.java:85)
    at org.springframework.expression.spel.support.StandardEvaluationContext.<init>(StandardEvaluationContext.java:74)
    at org.springframework.context.expression.StandardBeanExpressionResolver.evaluate(StandardBeanExpressionResolver.java:124)
    at org.springframework.beans.factory.support.AbstractBeanFactory.evaluateBeanDefinitionString(AbstractBeanFactory.java:1299)
    at org.springframework.beans.factory.support.BeanDefinitionValueResolver.evaluate(BeanDefinitionValueResolver.java:210)
    at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:182)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1360)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1118)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:517)
    ... 39 more

Here is my xml.

<bean id="entityManagerFactory"
    class="org.springframework.orm.jpa.LocalEntityManagerFactoryBean">
    <property name="persistenceUnitName" value="MyPersistenceUnit" />
  </bean>

What is this java.lang.NoSuchFieldError: NULL about? Have no issue with 3.0.5.

Bozho
  • 588,226
  • 146
  • 1,060
  • 1,140
Lee Chee Kiam
  • 11,450
  • 10
  • 65
  • 87

2 Answers2

56

This means there is a version mismatch--most likely with spring classes. So make sure all your spring jars are 3.1.0. Especially spring-expression. (Also upgrade your JPA provider (hibernate?) if it doesn't work after fixing spring)

Kimball Robinson
  • 3,287
  • 9
  • 47
  • 59
Bozho
  • 588,226
  • 146
  • 1,060
  • 1,140
  • 3
    Yes, you are right. I use Spring Flex which refers to all version. After I ensure all spring jars are 3.1.0, the error is gone. BTW, how do you know *java.lang.NoSuchFieldError: NULL* is version mismatch issue? – Lee Chee Kiam Dec 14 '11 at 09:11
  • 4
    it means a class was compiled with the field in place, but at runtime it doesn't find it – Bozho Dec 14 '11 at 09:24
  • 4
    Thanks, that helped me too, I had the problem after using Spring 3.1.0. A look in the maven dependencies in netbeans 7.1 showed that spring-expression version 3.0.6 was there! Forcing the correct dependency by adding it to the pom.xml file solved the problem. – Tilman Hausherr Jan 09 '12 at 14:09
1

It may help you. Upgrading from Spring 3.0.3.RELEASE results in: java.lang.NoSuchFieldError: USER_DECLARED_METHODS

Earlier I had like this

<dependencies>
<!-- Spring 3 dependencies -->
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-core</artifactId>
    <version>3.1.2.RELEASE</version>
</dependency>
...
</dependencies>

Then I added

<dependencies>
<!-- Spring 3 dependencies -->
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-core</artifactId>
    <version>3.1.2.RELEASE</version>
    <exclusions>
        <exclusion>
            <groupId>org.springframework</groupId>
            <artifactId>spring-core</artifactId>
        </exclusion>
    </exclusions>
</dependency>
...

</dependencies>
Community
  • 1
  • 1
SK.
  • 1,390
  • 2
  • 28
  • 59