我有一个spring boot web应用程序(非android)。有一个名为initializeComments的方法,并用@PostConstruct进行了注释。此方法从firebase数据库中读取数据。同样的应用程序代码可以在Eclipse IDE上运行,但是当我将这个war文件复制到tomcat容器中并使用tomcat/bin/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片段,以确保它在main函数返回之前不会退出。那么,我到底哪里错了呢?
发布于 2019-02-07 13:39:10
最终通过在firebase中启用调试日志找到了问题...看起来时钟并不同步。执行ntp同步后,问题已解决。
https://stackoverflow.com/questions/54553284
复制相似问题