lang.IllegalAccessError: tried to access method

原文链接: https://my.oschina.net/u/1377774/blog/534143

运行得好好的程序,在pom.xml加入了一些其它jar包依赖后,突然无法启动(启动方式是创建一个Spring Application Context):

Exception in thread "main" java.lang.IllegalAccessError: tried to access method 
org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingletonMutex()Ljava/lang/Object;
 from class 
org.springframework.context.event.AbstractApplicationEventMulticaster 
  at 
org.springframework.context.event.AbstractApplicationEventMulticaster.setBeanFactory(AbstractApplicationEventMulticaster.java:84)
  at 
org.springframework.context.event.SimpleApplicationEventMulticaster.(SimpleApplicationEventMulticaster.java:60) 
  at 
org.springframework.context.support.AbstractApplicationContext.initApplicationEventMulticaster(AbstractApplicationContext.java:667)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:471)
    at org.springframework.context.support.ClassPathXmlApplicationContext.(ClassPathXmlApplicationContext.java:139)
    at org.springframework.context.support.ClassPathXmlApplicationContext.(ClassPathXmlApplicationContext.java:83)
......


网上类似错误还有:(转自http://www.cnblogs.com/coveted/archive/2012/03/06/2381757.html)

Caused by: java.lang.IllegalAccessError: tried to access method org.springframework.core.GenericTypeResolver.getTypeVariableMap(Ljava/lang/Class;)Ljava/util/Map; from class org.springframework.data.util.ClassTypeInformation
    at org.springframework.data.util.ClassTypeInformation.(ClassTypeInformation.java:96)
    at org.springframework.data.util.ClassTypeInformation.(ClassTypeInformation.java:42)
    at org.springframework.data.repository.core.support.AbstractRepositoryMetadata.(AbstractRepositoryMetadata.java:43)
    at org.springframework.data.repository.core.support.DefaultRepositoryMetadata.(DefaultRepositoryMetadata.java:41)
    at org.springframework.data.repository.core.support.RepositoryFactorySupport.getRepositoryMetadata(RepositoryFactorySupport.java:154)
    at org.springframework.data.repository.core.support.RepositoryFactorySupport.getRepository(RepositoryFactorySupport.java:125)
    at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.getObject(RepositoryFactoryBeanSupport.java:114)
    at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.getObject(RepositoryFactoryBeanSupport.java:38)
    at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.doGetObjectFromFactoryBean(FactoryBeanRegistrySupport.java:142)
    ... 34 more
    
    原因是spring-data-jpa.jar的版本和spring-data-commons-core.jar的版本不匹配所造成的,spring-data-commons-core.jar的版本过高了.
在发生异常的时候我的版本是:spring-data-jpa-1.0.2.RELEASE.jar和spring-data-commons-core-1.3.0.M1.jar
更改后:spring-data-jpa-1.0.2.RELEASE.jar和spring-data-commons-core-1.1.0.RELEASE.jar (OK)

还有:java.lang.AbstractMethodError: org.springframework.data.jpa.repository.config.SimpleJpaRepositoryConfiguration.getRepositoryBaseInterface()Ljava/lang/Class;

原因:加入的spring-data-jedis包中引入了另外一个版本的spring-core,与现有冲突。

解决:在pom中exclude新版本的spring-core。

转载于:https://my.oschina.net/u/1377774/blog/534143

你可能感兴趣的:(lang.IllegalAccessError: tried to access method)