Spring和Docker:localhost没有发送任何数据。

29 浏览
0 Comments

Spring和Docker:localhost没有发送任何数据。

这个问题已经在这里有了答案:

如何配置Spring Boot应用程序的端口

我使用Spring(Maven)构建了一个RESTful Web Service,参考了这个指南,工作得很好:

https://spring.io/guides/gs/rest-service/

现在我想在Docker容器中启动它,但遇到了问题。请看下面我的Dockerfile:

#Take the base Java image to build upon
FROM openjdk:11
#Expose the container port that your application listens to outside world
#In the Sample application you can find this under Application.properties
EXPOSE 9090
#Add our application Jar file to the package
ADD target/demo-0.0.1-SNAPSHOT.jar demo.jar
# Run the application
ENTRYPOINT ["java", "-jar", "demo.jar"]

我使用以下命令构建和运行:

docker build -t username/demo.jar .
docker run -p 80:9090 username/demo.jar

我检查了application.properties文件,它是空的。我不知道这里是否需要设置什么。

我该如何纠正这个问题?

admin 更改状态以发布 2023年5月21日
0
0 Comments

从在线检查不同的帖子和博客来看,问题与端口有关。默认情况下,Spring将使用8080端口。我将其从9090端口更改后,Dockerfile和命令都可以工作。

我找到了一篇博客,展示了不同的更改方法,但我还没有尝试:

https://www.baeldung.com/spring-boot-change-port

0