嵌入式Tomcat不是以eclipse开始的

时间:2016-10-06 09:04:41

标签: java eclipse maven tomcat embedded-tomcat-7

我在maven项目中使用嵌入式tomcat进行一些集成测试(客户端 - 服务器场景)。

Tomcat tomcat = new Tomcat();
//set Host and port..
//add user and role for basic authentication
tomcat.start()

如果我使用maven构建项目,则测试按预期运行并且服务器正常启动。如果我尝试通过Eclipse调试测试,那么tomcat服务器不会以异常开头:

org.apache.catalina.LifecycleException: Failed to start component [StandardService[Tomcat]]

我尝试调试tomcat.start()方法以找出异常发生的位置。它位于(StandardServer.class):

synchronized (services) {
        for (int i = 0; i < services.length; i++) {
            services[i].start();
        }
    }

Services处于状态[StandardService[Tomcat]],所以我实际上不知道比以前更多,因为我没有堆栈跟踪。此代码段(LifeCycleBase.class)中包含例外:

try {
        startInternal();
    } catch (Throwable t) {
        ExceptionUtils.handleThrowable(t);
        setStateInternal(LifecycleState.FAILED, null, false);
        throw new LifecycleException(
                sm.getString("lifecycleBase.startFail",toString()), t);
    }

我正在使用Eclipse版本:Neon Release(4.6.0)。有些同事也使用eclipse,它在一个案例中有效。我们试图找出差异,但没有找到太多。到目前为止我们尝试的是编辑项目的某些依赖项的构建路径。当然,我们确实只更改了我们自己的项目依赖项。其他图书馆e.G.嵌入式tomcat没有受到影响。

在Netbeans中,它按预期工作。我认为这是一个日食设置或类似的东西..

编辑:

我想我没有提供足够的信息。 pom.xml的依赖关系如下:

<dependency>
  <groupId>org.apache.tomcat.embed</groupId>
  <artifactId>tomcat-embed-core</artifactId>
  <version>7.0.55</version>
</dependency>

<dependency>
  <groupId>org.apache.tomcat.embed</groupId>
  <artifactId>tomcat-embed-logging-log4j</artifactId>
</dependency

<dependency>
  <groupId>org.apache.tomcat</groupId>
  <artifactId>tomcat-jasper</artifactId>
  <version>7.0.55</version>
  <exclusions>
    <exclusion>
      <groupId>javax.servlet</groupId>
      <artifactId>javax.servlet-api</artifactId>
    </exclusion>
  </exclusions>
</dependency>

<dependency>
  <groupId>javax.servlet</groupId>
  <artifactId>servlet-api</artifactId>
  <version>2.5</version>
  <scope>provided</scope>
</dependency>

我试图删除javax.servlet的依赖项和排除。执行此操作后,tomcat服务器启动但有200多个测试失败。所以我需要这种依赖。 This帖子解释了这两个依赖关系之间的区别。但我仍然没有得到,为什么它不起作用..

0 个答案:

没有答案