与火力地堡数据库集成春季代码工作正常,在IDE但不是在Tomcat

问题描述 投票:1回答:1

我有一个春天启动的Web应用程序(非Android)。有一个名为initializeComments方法,这都被注解@PostConstruct。该方法从火力数据库中的数据。此完全相同的应用程序代码适用于Eclipse IDE的,但不是我这场战争文件复制到tomcat的容器中,并使用Tomcat /斌/ startup.sh脚本运行它。我花了很多时间试图调试和研究,但我无法找到任何解决方案。所以,张贴到这个论坛寻求帮助。不胜感激,如果任何人都可以提供任何指针。

@PostConstruct
    void initializeComments()
    {
        log.info("initializeComments::");
        final CountDownLatch done = new CountDownLatch(1);
        log.info("initializeComments::firebaseDatabseComments::"+firebaseDatabseComments.toString());
        // Load all comments
        firebaseDatabseComments.addListenerForSingleValueEvent(new ValueEventListener() 
        {
            public void onDataChange(DataSnapshot snapshot) 
            {
                for (DataSnapshot child : snapshot.getChildren()) 
                {
                    String key= child.getKey();
                    List<String> onlycomments = new ArrayList<String>();
                    for (DataSnapshot subchild : child.getChildren()) 
                    {
                          String value = (String) subchild.getValue();
                          onlycomments.add(value);
                    }
                    comments.put(key, onlycomments);
                 }
                log.info("initializePosts::comments: " + comments.toString());
                 done.countDown();
            }

            public void onCancelled(DatabaseError databaseError) 
            {
                log.info("initializeComments::The read failed for comments: " + databaseError.getCode());
            }
        });

        try 
        {
            done.await();
        } 
        catch (InterruptedException e) 
        {
            e.printStackTrace();
        }
    }

我的POM文件:

<parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.5.9.RELEASE</version>
        <relativePath/> 
  </parent>

  <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>1.8</java.version>
        <spring-cloud.version>Finchley.M9</spring-cloud.version>
  </properties>

    <dependencies>
        <dependency>
            <groupId>com.google.firebase</groupId>
            <artifactId>firebase-admin</artifactId>
            <version>6.7.0</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
        </dependency>
        <dependency>
            <groupId>org.json</groupId>
            <artifactId>json</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-logging</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-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger2</artifactId>
            <version>2.4.0</version>
        </dependency>
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger-ui</artifactId>
            <version>2.4.0</version>
        </dependency>
        <dependency>
            <groupId>io.dropwizard.metrics</groupId>
            <artifactId>metrics-core</artifactId>
        </dependency>
        <dependency>
            <groupId>io.dropwizard.metrics</groupId>
            <artifactId>metrics-json</artifactId>
        </dependency>
        <dependency>
            <groupId>io.dropwizard.metrics</groupId>
            <artifactId>metrics-annotation</artifactId>
        </dependency>
        <dependency>
            <groupId>com.ryantenney.metrics</groupId>
            <artifactId>metrics-spring</artifactId>
            <version>3.1.3</version>
        </dependency>
        <dependency>
            <groupId>de.codecentric</groupId>
            <artifactId>spring-boot-admin-starter-client</artifactId>
            <version>1.5.1</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-config</artifactId>
        </dependency>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-annotations</artifactId>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-databind</artifactId>
        </dependency>
        <dependency>
            <groupId>com.sun.jersey</groupId>
            <artifactId>jersey-core</artifactId>
        </dependency>
        <dependency>
            <groupId>org.glassfish</groupId>
            <artifactId>javax.json</artifactId>
            <version>1.0.4</version>
        </dependency>
         <dependency>
            <groupId>org.apache.tomcat.embed</groupId>
            <artifactId>tomcat-embed-jasper</artifactId>
         </dependency>
         <dependency>
             <groupId>javax.servlet</groupId>
             <artifactId>jstl</artifactId>
       </dependency>
    </dependencies>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>Camden.SR7</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

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

当我在Eclipse IDE中运行,我能够成功读取使用完全相同的代码的所有信息。但是,当我在Tomcat上运行(WAR文件),它只是挂起,永不退出。我没有收到任何响应异步。我已经处理了CountDownLatch片也保证了它不会在主函数返回前退出。所以我要去哪里错了吗?

java spring-boot firebase-realtime-database tomcat8
1个回答
0
投票

终于找到了问题由火力启用调试日志......似乎时钟不同步。做一个NTP同步后,问题就解决了。

© www.soinside.com 2019 - 2024. All rights reserved.