在Apache Tomcat上部署SpringBoot应用程序

时间:2018-06-29 05:26:29

标签: java spring spring-boot tomcat

我有一个Spring Boot应用程序,该应用程序可以在嵌入式tomcat容器中正常运行。但我希望将其部署在外部tomcat服务器上。因此,我遵循了一些在线教程并进行了更改,以使应用程序可与外部容器一起使用。

看起来像是tomcat部署了它,但是catalina.2018-06-28.log(严重警告)和localhost.2018-06-28.log(2 Spring WebApplicationInitializers)文件的输出有些奇怪,我不确定这意味着,如果那是问题。另外,当我从log4j2插件检查我的输出文件时,文件已创建,但为空。

不确定我想念的是什么。它不给我任何输出,也不起作用。如果我删除为使其与外部tomcat一起工作而添加的多余代码,它将与嵌入式tomcat一起工作。

下面是我的主要Java文件:

package com.consumer;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
import org.springframework.context.ApplicationContext;

import com.consumer.config.KafkaConfig;
import com.consumer.services.KafkaConnector;

@SpringBootApplication
@EnableConfigurationProperties(KafkaConfig.class)
public class KafkaBussOpsConsumer extends SpringBootServletInitializer {

private static final Logger logger = LogManager.getLogger(KafkaBussOpsConsumer.class);

public static void main(String[] args) {
    logger.info("||||||||||||||||| Application Started");
    ApplicationContext context = SpringApplication.run(KafkaBussOpsConsumer.class, args);
    KafkaConnector kConnector = context.getBean(KafkaConnector.class);
    logger.info("Application about to connecto kafka");
    kConnector.connect();
}

@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
    return builder.sources(KafkaBussOpsConsumer.class);
}

}

下面是我的pom.xml文件:

<?xml version="1.0" encoding="UTF-8"?>
<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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.consumer</groupId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>

<name>Consumer</name>
<description>Kafka consumer</description>

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.1.0.BUILD-SNAPSHOT</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.8</java.version>
</properties>

<dependencies> 
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
        <exclusions>
            <exclusion>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-logging</artifactId>
            </exclusion>
            <exclusion>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-tomcat</artifactId>
            </exclusion>
        </exclusions>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-log4j2</artifactId>
    </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.apache.httpcomponents</groupId>
      <artifactId>httpclient</artifactId>
      <version>4.5.5</version>
    </dependency>

    <dependency>
       <groupId>org.json</groupId>
       <artifactId>json</artifactId>
       <version>20080701</version>
    </dependency>

    <dependency>
        <groupId>org.apache.kafka</groupId>
        <artifactId>kafka-streams</artifactId>
        <version>1.1.0</version>
    </dependency>

    <dependency>
        <groupId>org.apache.kafka</groupId>
        <artifactId>kafka-clients</artifactId>
        <version>1.1.0</version>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-configuration-processor</artifactId>
        <optional>true</optional>
    </dependency>
    <!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-data-cassandra -->
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-cassandra</artifactId>
    </dependency>
</dependencies>

<build>
    <finalName>${artifactId}</finalName>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
    </plugins>
</build>

<repositories>
    <repository>
        <id>spring-snapshots</id>
        <name>Spring Snapshots</name>
        <url>https://repo.spring.io/snapshot</url>
        <snapshots>
            <enabled>true</enabled>
        </snapshots>
    </repository>
    <repository>
        <id>spring-milestones</id>
        <name>Spring Milestones</name>
        <url>https://repo.spring.io/milestone</url>
        <snapshots>
            <enabled>false</enabled>
        </snapshots>
    </repository>
    <repository>
        <id>spring-libs-release</id>
        <name>Spring Releases</name>
        <url>https://repo.spring.io/libs-release</url>
        <snapshots>
            <enabled>false</enabled>
        </snapshots>
    </repository>
</repositories>

<pluginRepositories>
    <pluginRepository>
        <id>spring-snapshots</id>
        <name>Spring Snapshots</name>
        <url>https://repo.spring.io/snapshot</url>
        <snapshots>
            <enabled>true</enabled>
        </snapshots>
    </pluginRepository>
    <pluginRepository>
        <id>spring-milestones</id>
        <name>Spring Milestones</name>
        <url>https://repo.spring.io/milestone</url>
        <snapshots>
            <enabled>false</enabled>
        </snapshots>
    </pluginRepository>
</pluginRepositories>


<artifactId>kafka-consumer</artifactId>

我的tomcat / logs / localhost.2018-06-28.log文件输出-

28-Jun-2018 21:14:12.560 INFO [http-nio-8080-exec-15] org.apache.catalina.core.ApplicationContext.log Closing Spring root WebApplicationContext
28-Jun-2018 21:15:54.573 INFO [http-nio-8080-exec-21] org.apache.catalina.core.ApplicationContext.log 2 Spring WebApplicationInitializers detected on classpath
28-Jun-2018 21:15:56.548 INFO [http-nio-8080-exec-21] org.apache.catalina.core.ApplicationContext.log Initializing Spring embedded WebApplicationContext
28-Jun-2018 21:28:03.801 INFO [http-nio-8080-exec-23] org.apache.catalina.core.ApplicationContext.log Closing Spring root WebApplicationContext
28-Jun-2018 21:28:07.574 INFO [http-nio-8080-exec-23] org.apache.catalina.core.ApplicationContext.log 2 Spring WebApplicationInitializers detected on classpath

我的tomcat / logs / catalina.2018-06-28.log-

28-Jun-2018 21:15:54.499 INFO [http-nio-8080-exec-21] org.apache.jasper.servlet.TldScanner.scanJars At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
28-Jun-2018 21:15:59.340 INFO [http-nio-8080-exec-21] org.apache.catalina.startup.HostConfig.deployWAR Deployment of web application archive [/opt/tomcat/webapps/kafka-consumer.war] has finished in [6,562] ms
28-Jun-2018 21:28:03.793 INFO [http-nio-8080-exec-23] org.apache.catalina.core.StandardContext.reload Reloading Context with name [/kafka-consumer] has started
28-Jun-2018 21:28:06.078 SEVERE [http-nio-8080-exec-23] org.apache.catalina.loader.WebappClassLoaderBase.checkThreadLocalMapForLeaks The web application [kafka-consumer] created a ThreadLocal with key of type [java.lang.ThreadLocal] (value [java.lang.ThreadLocal@1fa79f9c]) and a value of type [io.netty.util.internal.InternalThreadLocalMap] (value [io.netty.util.internal.InternalThreadLocalMap@15234f08]) but failed to remove it when the web application was stopped. Threads are going to be renewed over time to try and avoid a probable memory leak.
28-Jun-2018 21:28:07.517 INFO [http-nio-8080-exec-23] org.apache.jasper.servlet.TldScanner.scanJars At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
28-Jun-2018 21:28:11.953 INFO [http-nio-8080-exec-23] org.apache.catalina.core.StandardContext.reload Reloading Context with name [/kafka-consumer] is completed
28-Jun-2018 21:55:54.551 INFO [http-nio-8080-exec-31] org.apache.catalina.startup.HostConfig.undeploy Undeploying context [/kafka-consumer]
28-Jun-2018 21:56:07.712 INFO [http-nio-8080-exec-33] org.apache.catalina.startup.HostConfig.deployWAR Deploying web application archive [/opt/tomcat/webapps/kafka-consumer.war]
28-Jun-2018 21:56:09.232 INFO [http-nio-8080-exec-33] org.apache.jasper.servlet.TldScanner.scanJars At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
28-Jun-2018 21:56:14.132 INFO [http-nio-8080-exec-33] org.apache.catalina.startup.HostConfig.deployWAR Deployment of web application archive [/opt/tomcat/webapps/kafka-consumer.war] has finished in [6,420] ms

我的tomcat / logs / cataline.out文件-

2018-06-28 21:56:11.999  INFO --- [io-8080-exec-33] c.d.d.c.GuavaCompatibility               : Detected Guava >= 19 in the classpath, using modern compatibility layer
2018-06-28 21:56:12.248  INFO --- [io-8080-exec-33] c.d.d.c.ClockFactory                     : Using native clock to generate timestamps.
2018-06-28 21:56:12.661  INFO --- [io-8080-exec-33] c.d.d.c.NettyUtil                        : Did not find Netty's native epoll transport in the classpath, defaulting to NIO.
2018-06-28 21:56:13.131  INFO --- [io-8080-exec-33] c.d.d.c.p.DCAwareRoundRobinPolicy        : Using data-center name 'datacenter1' for DCAwareRoundRobinPolicy (if this is incorrect, please provide the correct datacenter name with DCAwareRoundRobinPolicy constructor)
2018-06-28 21:56:13.132  INFO --- [io-8080-exec-33] c.d.d.c.Cluster                          : New Cassandra host localhost/127.0.0.1:9042 added
2018-06-28 21:56:14.093  INFO --- [io-8080-exec-33] o.s.j.e.a.AnnotationMBeanExporter        : Registering beans for JMX exposure on startup
2018-06-28 21:56:14.114  INFO --- [io-8080-exec-33] c.h.c.KafkaConsumer            : Started KafkaConsumer in 4.353 seconds (JVM running for 3626.441)
28-Jun-2018 21:56:14.132 INFO [http-nio-8080-exec-33] org.apache.catalina.startup.HostConfig.deployWAR Deployment of web application archive [/opt/tomcat/webapps/kafka-consumer.war] has finished in [6,420] ms
2018-06-28 21:56:19.203  INFO --- [io-8080-exec-39] o.s.w.s.DispatcherServlet                : FrameworkServlet 'dispatcherServlet': initialization started
2018-06-28 21:56:19.211  INFO --- [io-8080-exec-39] o.s.w.s.DispatcherServlet                : FrameworkServlet 'dispatcherServlet': initialization completed in 7 ms

0 个答案:

没有答案