Spring启动应用程序无法在Tomcat 7上启动

时间:2017-02-27 08:58:18

标签: maven tomcat spring-boot spring-social

我正在尝试在Tomcat 7服务器上部署我的Spring启动应用程序并启动它。我可以部署,而我在启动服务器时遇到问题。

我做了什么?

1)使用初始配置和依赖项创建了一个spring starter项目。

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

3)根据https://github.com/spring-projects/spring-boot/issues/522的显式配置步骤,使用onStartup方法覆盖实现ServletContextInitializer。代码如下所示

@Configuration
public class ContextInitializer implements ServletContextInitializer {

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

}

和我的Application类

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

4)执行mvn clean安装。建立成功。

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

你能帮我解决一下吗?感谢。

编辑:分享catalina.out。但是看不到任何错误。

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]

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

    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

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

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>

2 个答案:

答案 0 :(得分:2)

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

  • <packaging>war</packaging>
  • 覆盖: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);
        }
    }
    

答案 1 :(得分:0)

您可以将以下内容添加到pom.xml中并尝试

<properties>
        <tomcat.version>your tomcat version</tomcat.version>
</properties>