java - Spring mongodb 异常 HTTP Status 500 - 过滤器执行抛出异常

标签 java mongodb spring-mvc spring-security tomcat7

我正在使用 mongoDB 和 spring mvc 和 tomcat7,只要添加此代码,我就会遇到异常。

我查过谷歌,但找不到任何东西。该应用程序在没有 monogDB 的情况下工作正常,但是当我运行 monogDB 测试时它很好。

monogDB位于不同的服务器上,tomcat位于不同的服务器上

错误

type Exception report

message Filter execution threw an exception

description The server encountered an internal error that prevented it from      fulfilling this request.

exception

javax.servlet.ServletException: Filter execution threw an exception

root cause

java.lang.NoSuchMethodError: com.mongodb.MongoOptions.<init>(Lcom/mongodb/MongoClientOptions;)V
    com.mongodb.MongoClient.<init>(MongoClient.java:138)
    com.mongodb.MongoClient.<init>(MongoClient.java:126)
    com.mongodb.MongoClient.<init>(MongoClient.java:115)
    org.krams.commerce.login.UserDAO.internalDatabase(UserDAO.java:65)
    org.krams.commerce.login.UserDAO.searchDatabase(UserDAO.java:24)
    org.krams.commerce.login.CustomAuthenticationManager.authenticate(CustomAuthenticationManager.java:42)
    org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter.attemptAuthentication(UsernamePasswordAuthenticationFilter.java:97)
    org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:199)
    org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:380)
    org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:105)
    org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:380)
    org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:79)
    org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:380)
    org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:169)
    org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:237)
    org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:167)

note The full stack trace of the root cause is available in the Apache Tomcat/7.0.42 logs.

pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>org.krams.tutorial</groupId>
  <artifactId>commerce</artifactId>
  <packaging>war</packaging>
  <version>1.0.0-SNAPSHOT</version>
  <name>commerce</name>
  <url>http://maven.apache.org</url>



  <dependencies>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.8.1</version>
        <type>jar</type>
        <scope>compile</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-web</artifactId>
        <version>3.0.5.RELEASE</version>
        <type>jar</type>
        <scope>compile</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-core</artifactId>
        <version>3.0.5.RELEASE</version>
        <type>jar</type>
        <scope>compile</scope>
    </dependency>
    <dependency>
        <groupId>log4j</groupId>
        <artifactId>log4j</artifactId>
        <version>1.2.14</version>
        <type>jar</type>
        <scope>compile</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-tx</artifactId>
        <version>3.0.5.RELEASE</version>
        <type>jar</type>
        <scope>compile</scope>
    </dependency>
    <dependency>
        <groupId>jstl</groupId>
        <artifactId>jstl</artifactId>
        <version>1.1.2</version>
        <type>jar</type>
        <scope>compile</scope>
    </dependency>
    <dependency>
        <groupId>taglibs</groupId>
        <artifactId>standard</artifactId>
        <version>1.1.2</version>
        <type>jar</type>
        <scope>compile</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-webmvc</artifactId>
        <version>3.0.5.RELEASE</version>
        <type>jar</type>
        <scope>compile</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework.security</groupId>
        <artifactId>spring-security-core</artifactId>
        <version>3.0.5.RELEASE</version>
        <type>jar</type>
        <scope>compile</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-aop</artifactId>
        <version>3.0.5.RELEASE</version>
        <type>jar</type>
        <scope>compile</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework.security</groupId>
        <artifactId>spring-security-config</artifactId>
        <version>3.0.5.RELEASE</version>
        <type>jar</type>
        <scope>compile</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework.security</groupId>
        <artifactId>spring-security-web</artifactId>
        <version>3.0.5.RELEASE</version>
        <type>jar</type>
        <scope>compile</scope>
    </dependency>
    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>servlet-api</artifactId>
        <version>2.5</version>
        <type>jar</type>
        <scope>compile</scope>
    </dependency>
      <dependency>
          <groupId>org.mongodb</groupId>
          <artifactId>mongo-java-driver</artifactId>
          <version>2.11.2</version>
      </dependency>
      <dependency>
          <groupId>cglib</groupId>
          <artifactId>cglib</artifactId>
          <version>2.2</version>
      </dependency>
      <dependency>
          <groupId>com.google.code.gson</groupId>
          <artifactId>gson</artifactId>
          <version>2.2.4</version>
          <scope>compile</scope>
      </dependency>

  </dependencies>
  <build>
      <plugins>
          <plugin>
              <artifactId>maven-failsafe-plugin</artifactId>
              <version>2.6</version>
              <executions>
                  <execution>
                      <goals>
                          <goal>integration-test</goal>
                          <goal>verify</goal>
                      </goals>
                  </execution>
              </executions>
          </plugin>
      </plugins>

    <finalName>commerce</finalName>
  </build>
</project>

提前谢谢您

最佳答案

在我看来,您正在开发的 MongoDB 驱动程序版本与网络服务器上的驱动程序版本之间可能不匹配。 MongoClient 仅出现在 2.11 版本中,因此我怀疑您 Tomcat 中的驱动程序版本较旧。

关于java - Spring mongodb 异常 HTTP Status 500 - 过滤器执行抛出异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18176773/

相关文章:

java - 使用 Hibernate 和 JDBC 关闭连接

java - 复制到用户目录(java.nio)

java - IndexOutOfBoundException - 从站点检索所有元素

java - 有没有关于可伸缩 Web 应用程序(Java/Ajax/REST)的好书?

node.js - MongoDB findOne for 循环中出现错误

MongoDB C# 查询从文档中选择特定键

node.js - 使用 Mongoose 将 MongoDB 中的字符串字段转换为 ObjectID 字段

java - Spring bean 范围 : session and globalSession

spring - 如何部署这个罕见的 Spring MVC web 应用程序?

java - 使用 SPRING MVC 在 JSP 中显示图像