Spring Boot 应用程序未在 Tomcat 7 上启动 [英] Spring boot application not starting on Tomcat 7

查看:77
本文介绍了Spring Boot 应用程序未在 Tomcat 7 上启动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在 Tomcat 7 服务器上部署我的 Spring Boot 应用程序并启动它.我能够部署,但在启动服务器时遇到问题.

I am trying to deploy my Spring boot application on a Tomcat 7 server and start it. I am able to deploy, while I am facing problems in starting the server.

我做了什么?

1) 使用初始配置和依赖项创建了一个 spring 启动项目.

1) Created a spring starter project with the initial configurations and dependencies.

2) 编辑'org.eclipse.wst.common.project.facet.core.xml' 文件并将'jst.web' 版本从3.1 更改为3.0.清理了项目.

2) Edited the 'org.eclipse.wst.common.project.facet.core.xml' file and changed the 'jst.web' version from 3.1 to 3.0. Cleaned the project.

3) 根据 https://github.com/spring-projects/spring-boot/issues/522.代码如下

3) Implemented ServletContextInitializer with onStartup method override based on the explicit configuration steps as per https://github.com/spring-projects/spring-boot/issues/522. Code looks like below

@Configuration
public class ContextInitializer implements ServletContextInitializer {

@Override
public void onStartup(ServletContext arg0) throws ServletException {
    // TODO Auto-generated method stub
}

}

在我的应用程序类中

public static void main(String[] args) {
    SpringApplication.run(new Class[] { SocialIntegrationApplication.class, ContextInitializer.class }, args);
}

4) 执行了 mvn 全新安装.构建成功.

4) Performed a mvn clean install. Builds successfully.

但是在启动服务器时,我收到一个错误,因为Server Java Web Tomcat 7 Server failed to start.

But when starting the server, I am getting an error as Server Java Web Tomcat 7 Server failed to start.

你能帮帮我吗?谢谢.

共享 catalina.out.虽然看不到任何错误.

EDIT : Sharing the catalina.out. Not able to see any error though.

127.0.0.1 - - [07/Feb/2017:18:16:17 +0530] "GET / HTTP/1.1" 404 899
0:0:0:0:0:0:0:1 - - [07/Feb/2017:18:16:18 +0530] "GET /ROOT/ HTTP/1.1" 200 37264
0:0:0:0:0:0:0:1 - - [07/Feb/2017:18:16:19 +0530] "GET /ROOT/pages/images/favicon.ico HTTP/1.1" 401 923
127.0.0.1 - - [07/Feb/2017:18:22:17 +0530] "GET / HTTP/1.1" 404 899
0:0:0:0:0:0:0:1 - - [07/Feb/2017:18:22:18 +0530] "GET /ROOT/ HTTP/1.1" 200 37264
0:0:0:0:0:0:0:1 - - [07/Feb/2017:18:22:18 +0530] "GET /ROOT/pages/images/favicon.ico HTTP/1.1" 401 923
0:0:0:0:0:0:0:1 - - [07/Feb/2017:18:22:27 +0530] "GET /ROOT/facebook HTTP/1.1" 200 37264
0:0:0:0:0:0:0:1 - - [07/Feb/2017:18:22:27 +0530] "GET /ROOT/pages/images/favicon.ico HTTP/1.1" 401 923
0:0:0:0:0:0:0:1 - - [07/Feb/2017:18:22:38 +0530] "GET /ROOT/facebook HTTP/1.1" 200 37264
0:0:0:0:0:0:0:1 - - [07/Feb/2017:18:22:38 +0530] "GET /ROOT/pages/images/favicon.ico HTTP/1.1" 401 923
0:0:0:0:0:0:0:1 - - [07/Feb/2017:18:25:17 +0530] "GET /ROOT/ HTTP/1.1" 200 37264
0:0:0:0:0:0:0:1 - - [07/Feb/2017:18:25:17 +0530] "GET /ROOT/pages/images/favicon.ico HTTP/1.1" 401 923
127.0.0.1 - - [07/Feb/2017:18:25:59 +0530] "GET / HTTP/1.1" 404 899
0:0:0:0:0:0:0:1 - - [07/Feb/2017:18:26:00 +0530] "GET /integration/ HTTP/1.1" 404 923
0:0:0:0:0:0:0:1 - - [07/Feb/2017:18:28:31 +0530] "GET /integration/ HTTP/1.1" 404 923
0:0:0:0:0:0:0:1 - - [07/Feb/2017:18:29:02 +0530] "GET / HTTP/1.1" 404 899
0:0:0:0:0:0:0:1 - - [07/Feb/2017:18:29:05 +0530] "GET / HTTP/1.1" 404 899

共享服务器控制台日志

    15:27:19.848 [localhost-startStop-1] ERROR org.slf4j.helpers.Util - SLF4J: Class path contains multiple SLF4J bindings.
15:27:19.852 [localhost-startStop-1] ERROR org.slf4j.helpers.Util - SLF4J: Found binding in [jar:file:/C:/XM/neo-java-web-sdk-2.53.6/repository/.archive/bin/logback-classic.jar!/org/slf4j/impl/StaticLoggerBinder.class]
15:27:19.852 [localhost-startStop-1] ERROR org.slf4j.helpers.Util - SLF4J: Found binding in [jar:file:/C:/XM/XM_Workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp1/wtpwebapps/social-integration/WEB-INF/lib/logback-classic-1.1.9.jar!/org/slf4j/impl/StaticLoggerBinder.class]
15:27:19.853 [localhost-startStop-1] ERROR org.slf4j.helpers.Util - SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
15:27:20.269 [localhost-startStop-1] ERROR org.slf4j.helpers.Util - SLF4J: Actual binding is of type [ch.qos.logback.classic.util.ContextSelectorStaticBinder]

EDIT 2 :将 logging.level.root=INFO 添加到属性文件,得到以下异常

EDIT 2 : Adding the logging.level.root=INFO to the properties file, getting the following exception

    11:53:20.995 [localhost-startStop-1] ERROR org.slf4j.helpers.Util - SLF4J: Class path contains multiple SLF4J bindings.
11:53:20.997 [localhost-startStop-1] ERROR org.slf4j.helpers.Util - SLF4J: Found binding in [jar:file:/C:/XM/neo-java-web-sdk-2.53.6/repository/.archive/bin/logback-classic.jar!/org/slf4j/impl/StaticLoggerBinder.class]
11:53:20.997 [localhost-startStop-1] ERROR org.slf4j.helpers.Util - SLF4J: Found binding in [jar:file:/C:/XM/XM_Workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp1/wtpwebapps/social-integration-tomcat7/WEB-INF/lib/logback-classic-1.1.7.jar!/org/slf4j/impl/StaticLoggerBinder.class]
11:53:20.998 [localhost-startStop-1] ERROR org.slf4j.helpers.Util - SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
11:53:21.283 [localhost-startStop-1] ERROR org.slf4j.helpers.Util - SLF4J: Actual binding is of type [ch.qos.logback.classic.util.ContextSelectorStaticBinder]
11:53:22.303 [main] ERROR java.lang.Throwable - java.lang.ClassCircularityError: java/util/logging/LogRecord
11:53:22.303 [main] ERROR java.lang.Throwable -     at org.slf4j.bridge.SLF4JBridgeHandler.getSLF4JLogger(SLF4JBridgeHandler.java:198)
11:53:22.304 [main] ERROR java.lang.Throwable -     at org.slf4j.bridge.SLF4JBridgeHandler.publish(SLF4JBridgeHandler.java:293)
11:53:22.304 [main] ERROR java.lang.Throwable -     at java.util.logging.Logger.log(Logger.java:616)
11:53:22.304 [main] ERROR java.lang.Throwable -     at java.util.logging.Logger.doLog(Logger.java:641)
11:53:22.304 [main] ERROR java.lang.Throwable -     at java.util.logging.Logger.logp(Logger.java:841)
11:53:22.305 [main] ERROR java.lang.Throwable -     at org.apache.juli.logging.DirectJDKLog.log(DirectJDKLog.java:185)
11:53:22.305 [main] ERROR java.lang.Throwable -     at org.apache.juli.logging.DirectJDKLog.fatal(DirectJDKLog.java:161)
11:53:22.305 [main] ERROR java.lang.Throwable -     at org.apache.catalina.startup.Catalina.start(Catalina.java:695)
11:53:22.305 [main] ERROR java.lang.Throwable -     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
11:53:22.306 [main] ERROR java.lang.Throwable -     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
11:53:22.306 [main] ERROR java.lang.Throwable -     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
11:53:22.306 [main] ERROR java.lang.Throwable -     at java.lang.reflect.Method.invoke(Method.java:606)
11:53:22.307 [main] ERROR java.lang.Throwable -     at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:294)
11:53:22.307 [main] ERROR java.lang.Throwable -     at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:428)

和我当前的 pom.xml

and my current pom.xml

<?xml version="1.0" encoding="UTF-8"?>

http://maven.apache.org/xsd/maven-4.0.0.xsd">4.0.0

http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0

<groupId>com.xm</groupId>
<artifactId>social-integration</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>

<name>social-integration</name>
<description>Social integration using Spring Boot</description>

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.5.1.RELEASE</version>
    <relativePath /> <!-- lookup parent from repository -->
</parent>

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    <java.version>1.7</java.version>
    <tomcat.version>7.0.59</tomcat.version>
</properties>

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-batch</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-social-facebook</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-social-linkedin</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-social-twitter</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web-services</artifactId>
    </dependency>
    <dependency>
        <groupId>org.apache.tomcat</groupId>
        <artifactId>tomcat-juli</artifactId>
        <version>7.0.59</version>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-tomcat</artifactId>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-configuration-processor</artifactId>
        <optional>true</optional>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-configuration-processor</artifactId>
        <optional>true</optional>
    </dependency>
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-log4j12</artifactId>
    </dependency>
    <!-- Facebook APIs -->
    <dependency>
        <groupId>com.facebook.ads.sdk</groupId>
        <artifactId>facebook-java-ads-sdk</artifactId>
        <version>0.4.0</version>
    </dependency>
</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
    </plugins>
</build>

推荐答案

Spring Boot 和 Tomcat 7

pom.xml

版本规范:

<properties>
    <tomcat.version>7.0.78</tomcat.version>
    <servlet-api.version>3.0.1</servlet-api.version>
</properties>

依赖项降级:

<dependencies>
    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>javax.servlet-api</artifactId>
        <version>${servlet-api.version}</version>
        <scope>provided</scope>  <!-- provided: tomcat/lib/servlet-api.jar -->
    </dependency>
    <dependency>
        <groupId>org.apache.tomcat</groupId>
        <artifactId>tomcat-juli</artifactId>
        <version>${tomcat.version}</version>
        <scope>runtime</scope> <!-- runtime: tomcat/bin/tomcat-juli.jar -->
    </dependency>
    <!-- remove it:
     <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-tomcat</artifactId>
        <scope>provided</scope>
    </dependency>
    -->
</dependencies>

传统部署

要创建可部署的 war 文件 (Tomcat 7),请阅读本指南:https://docs.spring.io/spring-boot/docs/current/reference/html/howto-traditional-deployment.html

  • war
  • 覆盖:SpringBootServletInitializer.configure:

@SpringBootApplication
public class Application extends SpringBootServletInitializer {
    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
        return application.sources(Application.class);
    }
    public static void main(String[] args) throws Exception {
        SpringApplication.run(Application.class, args);
    }
}

这篇关于Spring Boot 应用程序未在 Tomcat 7 上启动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆