[英]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.