【问题标题】:Spring mongodb exception HTTP Status 500 - Filter execution threw an exceptionSpring mongodb异常HTTP状态500 - 过滤器执行引发异常
【发布时间】:2013-08-11 21:17:51
【问题描述】:

我正在使用 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>

提前感谢您

【问题讨论】:

    标签: java mongodb spring-mvc spring-security tomcat7


    【解决方案1】:

    在我看来,您开发的 MongoDB 驱动程序版本与网络服务器上的驱动程序版本可能不匹配。 MongoClient 只出现在 2.11 版本中,所以我怀疑您在 Tomcat 中拥有的驱动程序版本较旧。

    【讨论】:

      【解决方案2】:

      我使用 Java EE (JSF + EJB)。 Mongo 客户端位于 @startup @singleton ejb 中,当 @PostConstruct void init() 调用 new MongoClient() 时,我遇到了同样的问题。

      事实上,我可以通过将 EJB 作为独立程序运行(添加一个调用 init() 的 main 方法)来完成任务。

      我尝试清理并重新启动,但问题消失了。从技术上讲,这不是一个答案,Nabeel 可能已经修复了它,但我希望这可以帮助其他人。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2017-11-28
        • 2014-10-26
        • 1970-01-01
        • 2015-08-23
        • 2012-11-18
        • 2015-09-26
        • 1970-01-01
        • 2013-01-25
        相关资源
        最近更新 更多