Mongodb IllegalAccessException

时间:2015-06-19 05:24:31

标签: java spring mongodb

嗨我在sping中有这个配置。

启动webapplication后会弹出以下异常:

07:04:54,336 DEBUG ctory.support.DefaultListableBeanFactory:221 - 创建单例bean'mongo'的共享实例

07:04:54,336 DEBUG ctory.support.DefaultListableBeanFactory:450 - 创建bean'mongo'的实例

07:04:54,337 DEBUG ctory.support.DefaultListableBeanFactory:523 - 急切地缓存bean'mongo'以允许解析潜在的循环引用

07:04:54,342 DEBUG ctory.support.DefaultListableBeanFactory:1616 - 在名为'mongo'的bean上调用afterPropertiesSet()

07:04:54,364 WARN context.support.XmlWebApplicationContext:487 - 上下文初始化期间遇到异常 - 取消刷新尝试 org.springframework.beans.factory.BeanCreationException:创建名为'mongo'的bean时出错:init方法的调用失败;嵌套异常是java.lang.IllegalAccessError:试图从com.mongodb.Bytes类中访问方法org.bson.types.ObjectId。(III)V

at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1574)

at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:539)

at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476)

at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:303)

at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)

at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:299)

at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)

at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:736)

at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:757)

at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:480)

at org.springframework.web.servlet.FrameworkServlet.configureAndRefreshWebApplicationContext(FrameworkServlet.java:663)

at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:629)

at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:677)

at org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:548)

at org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:489)

at org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:136)
at javax.servlet.GenericServlet.init(GenericServlet.java:158)

at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1241)

at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1154)
at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1041)

at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:4944)

at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5230)

at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:725)

at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:701)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:714)

at org.apache.catalina.startup.HostConfig.deployDescriptor(HostConfig.java:581)

at org.apache.catalina.startup.HostConfig$DeployDescriptor.run(HostConfig.java:1683)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)

at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)

at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)

at java.lang.Thread.run(Thread.java:745)

引起:java.lang.IllegalAccessError:尝试从类com.mongodb.Bytes访问方法org.bson.types.ObjectId。(III)V     在com.mongodb.Bytes。(Bytes.java:219)     在com.mongodb.MongoOptions.reset(MongoOptions.java:75)     在com.mongodb.MongoOptions。(MongoOptions.java:37)

at org.springframework.data.mongodb.core.MongoFactoryBean.createInstance(MongoFactoryBean.java:141)

at org.springframework.data.mongodb.core.MongoFactoryBean.createInstance(MongoFactoryBean.java:45)

at org.springframework.beans.factory.config.AbstractFactoryBean.afterPropertiesSet(AbstractFactoryBean.java:134)

at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1633)

at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1570)
... 32 more

代码

有没有人有线索,有什么不对?

1 个答案:

答案 0 :(得分:11)

解决:

Maven依赖

    <dependency>
        <groupId>org.springframework.data</groupId>
        <artifactId>spring-data-mongodb</artifactId>
        <version>1.7.0.RELEASE</version>
    </dependency>

自动包含mongodb驱动程序2.13.0

我有依赖

<dependency>
    <groupId>org.mongodb</groupId>
    <artifactId>mongodb-driver</artifactId>
    <version>3.0.2</version>
</dependency>

导致IllegalAccessError。