简体   繁体   English

与Firebase数据库集成的Spring代码在IDE上可以正常工作,但在Tomcat上却不能

[英]Spring code integrated with Firebase database works fine on IDE but NOT on Tomcat

I have a spring boot web application (non-android). 我有一个Spring Boot Web应用程序(非Android)。 There is a method named initializeComments and this is annotated with @PostConstruct. 有一个名为initializeComments的方法,并用@PostConstruct进行注释。 This method reads data from firebase database. 此方法从Firebase数据库读取数据。 This same exact application code works on Eclipse IDE but NOT when i copy this war file to a tomcat container and run it using tomcat/bin/startup.sh script. 相同的完全相同的应用程序代码在Eclipse IDE上有效,但是当我将此war文件复制到tomcat容器并使用tomcat / bin / startup.sh脚本运行它时,则无法使用。 I have spent lot of time trying to debug and research but am not able to find any solutions. 我花了大量时间尝试调试和研究,但是找不到任何解决方案。 So posting to this forum for help. 所以发布到这个论坛寻求帮助。 Appreciate if anyone can provide any pointers. 欣赏是否有人可以提供任何指针。

@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();
        }
    }

my pom file: 我的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>

When i run on Eclipse IDE i am able to read all the posts successfully using the same exact code. 当我在Eclipse IDE上运行时,我可以使用完全相同的代码成功读取所有帖子。 But when i run on tomcat (the war file), it just hangs and never exits. 但是,当我在tomcat(战争文件)上运行时,它只是挂起而从未退出。 I don't receive any async response. 我没有收到任何异步响应。 I have handled the CountDownLatch piece also to ensure it does not exit before the main function returns. 我还处理了CountDownLatch部分,以确保它不会在主函数返回之前退出。 So where am i going wrong here? 那我在哪里错了?

finally found the issue by enabling debug logs in firebase... seems the clock was not synchronized. 最终通过在Firebase中启用调试日志找到了问题...似乎时钟未同步。 After doing an ntp sync the issue was resolved. 完成ntp同步后,问题已解决。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 与弹簧集成的嵌入式tomcat - embedded tomcat integrated with spring 代码工作正常,然后在安装maven之后,jar和IDE中均存在错误 - Code works fine, then after maven install, there are errors in both the jar and the IDE 我的webapplication在IDE中测试时工作正常,但在webserver(tomcat)上不起作用 - My webapplication works fine when testing it in IDE, but doesnt work on webserver (tomcat) 通过HTTP进行粗麻布的Spring RPC在maven tomcat插件上工作正常,但在Tomcat服务器上返回http 500错误 - Spring RPC with hessian over HTTP works fine on maven tomcat plugin, but return http 500 error on Tomcat server 将.war文件部署到tomcat 8在IDE中工作正常,但是当我部署到我的VPS时,我丢失了所有的JS和CSS - Deploying .war file to tomcat 8 works fine in IDE but I lose all my JS and CSS when I deploy to my VPS SonarQube与不带Maven的Tomcat集成的代码覆盖率 - Code Coverage with SonarQube integrated with Tomcat without Maven 部署在Tomcat上的Spring Boot Rest API可以提供404,但可以独立运行 - Spring Boot Rest API Deployed on Tomcat gives 404 but works Stand-alone all fine Reflections.getTypesAnnotatedWith在Tomcat上工作正常,但在Weblogic上工作不正常 - reflections.getTypesAnnotatedWith works fine on Tomcat but not Weblogic 自定义servlet在Tomcat 6上提供404,在7上运行良好 - Custom servlet gives 404 on Tomcat 6, works fine on 7 应用程序不是从websphere 8.5.5开始,但在tomcat中工作正常 - Application is not starting in websphere 8.5.5 but works fine in tomcat
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM