简体   繁体   English

无法从 postman 向我的 docker spring-boot 容器发送请求

[英]Can't send request from postman to my docker spring-boot container

I'm trying to send request from postman to my backend spring-boot container and I get我正在尝试将请求从 postman 发送到我的后端 spring-boot 容器,我得到了

"could not send request" message “无法发送请求”消息

docker-compose.yml: docker-compose.yml:

version: '3'

services:
  mysqldb:
    image: mysql
    environment:
      - MYSQL_ROOT_PASSWORD=root
      - MYSQL_DATABASE=booking
      - MYSQL_USER=dhia
      - MYSQL_PASSWORD=root
    ports:
      - 3308:3306

  app:
    image: app:latest
    ports:
       - 8091:8091
    environment:
      SPRING_DATASOURCE_URL: jdbc:mysql://mysqldb:3306/booking
    depends_on:
       - mysqldb

The application started fine and 0 errors应用程序启动正常,0 错误

This is my Dockerfile这是我的 Dockerfile

FROM maven:3.8.6-openjdk-18-slim as MAVEN_BUILD
WORKDIR /build
COPY pom.xml .
RUN mvn dependency:go-offline
COPY src ./src
RUN mvn package -Dmaven.test.skip=true
FROM openjdk:18-alpine
WORKDIR /app
ARG JAR_FILE=*.jar
COPY --from=MAVEN_BUILD /build/target/${JAR_FILE} ./app.jar
EXPOSE 8080
CMD ["java", "-jar", "app.jar"]
bookingsystem-app-1      |
bookingsystem-app-1      |   .   ____          _            __ _ _
bookingsystem-app-1      |  /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
bookingsystem-app-1      | ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
bookingsystem-app-1      |  \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
bookingsystem-app-1      |   '  |____| .__|_| |_|_| |_\__, | / / / /
bookingsystem-app-1      |  =========|_|==============|___/=/_/_/_/
bookingsystem-app-1      |  :: Spring Boot ::                (v2.7.3)
bookingsystem-app-1      |
bookingsystem-app-1      | 2022-08-21 11:10:34.994  INFO 1 --- [           main] Booking.BookingApplication               : Starting BookingApplication v0.0.1-SNAPSHOT using Java 18-ea on 521f32647790 with PID 1 (/app/app.jar started by root in /app)
bookingsystem-app-1      | 2022-08-21 11:10:35.005  INFO 1 --- [           main] Booking.BookingApplication               : No active profile set, falling back to 1 default profile: "default"
bookingsystem-app-1      | 2022-08-21 11:10:36.215  INFO 1 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JPA repositories in DEFAULT mode.
bookingsystem-app-1      | 2022-08-21 11:10:36.325  INFO 1 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 90 ms. Found 4 JPA repository interfaces.
bookingsystem-app-1      | 2022-08-21 11:10:37.470  INFO 1 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8090 (http)
bookingsystem-app-1      | 2022-08-21 11:10:37.499  INFO 1 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
bookingsystem-app-1      | 2022-08-21 11:10:37.499  INFO 1 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet engine: [Apache Tomcat/9.0.65]
bookingsystem-app-1      | 2022-08-21 11:10:37.637  INFO 1 --- [           main] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
bookingsystem-app-1      | 2022-08-21 11:10:37.638  INFO 1 --- [           main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 2339 ms
bookingsystem-app-1      | 2022-08-21 11:10:37.753  INFO 1 --- [           main] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Starting...
bookingsystem-app-1      | 2022-08-21 11:10:38.142  INFO 1 --- [           main] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Start completed.
bookingsystem-app-1      | 2022-08-21 11:10:38.342  INFO 1 --- [           main] o.hibernate.jpa.internal.util.LogHelper  : HHH000204: Processing PersistenceUnitInfo [name: default]
bookingsystem-app-1      | 2022-08-21 11:10:38.466  INFO 1 --- [           main] org.hibernate.Version                    : HHH000412: Hibernate ORM core version 5.6.10.Final
bookingsystem-app-1      | 2022-08-21 11:10:38.792  INFO 1 --- [           main] o.hibernate.annotations.common.Version   : HCANN000001: Hibernate Commons Annotations {5.1.2.Final}
bookingsystem-app-1      | 2022-08-21 11:10:38.946  INFO 1 --- [           main] org.hibernate.dialect.Dialect            : HHH000400: Using dialect: org.hibernate.dialect.MySQL5Dialect
bookingsystem-app-1      | Hibernate:
bookingsystem-app-1      |
bookingsystem-app-1      |     alter table bookings
bookingsystem-app-1      |        add constraint FK4xjjw8rumqxvr8c6t7xm6q8ty
bookingsystem-app-1      |        foreign key (hike_id)
bookingsystem-app-1      |        references hikes (id)
bookingsystem-app-1      | Hibernate:
bookingsystem-app-1      |
bookingsystem-app-1      |     alter table bookings
bookingsystem-app-1      |        add constraint FKg37gxkbbjvc3dp3een92kxy05
bookingsystem-app-1      |        foreign key (hiker_id)
bookingsystem-app-1      |        references hikers (id)
bookingsystem-app-1      | Hibernate:
bookingsystem-app-1      |
bookingsystem-app-1      |     alter table hikes
bookingsystem-app-1      |        add constraint FKs8qvf1tnml0ahxs407ggng3bs
bookingsystem-app-1      |        foreign key (trail_id)
bookingsystem-app-1      |        references trails (id)
bookingsystem-app-1      | 2022-08-21 11:10:39.988  INFO 1 --- [           main] o.h.e.t.j.p.i.JtaPlatformInitiator       : HHH000490: Using JtaPlatform implementation: [org.hibernate.engine.transaction.jta.platform.internal.NoJtaPlatform]
bookingsystem-app-1      | 2022-08-21 11:10:40.000  INFO 1 --- [           main] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'
bookingsystem-app-1      | 2022-08-21 11:10:40.542  WARN 1 --- [           main] JpaBaseConfiguration$JpaWebConfiguration : spring.jpa.open-in-view is enabled by default. Therefore, database queries may be performed during view rendering. Explicitly configure spring.jpa.open-in-view to disable this warning
bookingsystem-app-1      | 2022-08-21 11:10:41.008  INFO 1 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 8090 (http) with context path ''
bookingsystem-app-1      | 2022-08-21 11:10:41.019  INFO 1 --- [           main] Booking.BookingApplication               : Started BookingApplication in 6.813 seconds (JVM running for 7.789)

This is my application properties file:这是我的应用程序属性文件:

spring.datasource.url = jdbc:mysql://localhost:3308/booking
spring.datasource.username=root
spring.jpa.database-platform=org.hibernate.dialect.MySQL5InnoDBDialect
spring.datasource.password=root
createDatabaseIfNotExist=true
### JPA / HIBERNATE ###
spring.jpa.show-sql=true
spring.jpa.hibernate.ddl-auto=none
spring.jpa.generate-ddl = true
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL5Dialect
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.jpa.properties.show-sql = true
spring.jpa.properties.hibernate.format_sql = true
server.port=8090 

The problem that I can't access to my controllers or send any requests I tried all the Ports and all the names ( localhost, booking, app ) and always CONNREFUSED我无法访问我的控制器或发送任何请求的问题我尝试了所有端口和所有名称(本地主机、预订、应用程序)并且总是 CONNREFUSED

http://mysqldb:8080/hikes http://mysqldb:8080/hikes

http://mysqldb:8090/hikes http://mysqldb:8090/hikes

http://mysqldb:8091/hikes http://mysqldb:8091/hikes

http://localhost:8080/hikes http://localhost:8080/hikes

http://localhost:8090/hikes http://localhost:8090/hikes

http://localhost:8091/hikes http://localhost:8091/hikes

By the way when I run it without the container everything work fine.顺便说一句,当我在没有容器的情况下运行它时,一切正常。

Try to change these port numbers with the same port number dockerfile -> EXPOSE 8080 -> EXPOSE 8090 docker-compose.yml -> ports: - 8091:8091 -> ports: - 8090:8090 this will work because your application using 8090 port and you using 8091 to run your application in your docker-compose, and at the same time trying to expose with 8080 port尝试将这些端口号更改为相同的端口号 dockerfile -> EXPOSE 8080 -> EXPOSE 8090 docker-compose.yml -> 端口:- 8091:8091 -> 端口: - 8090:8090 您的应用程序使用 8090:8090 端口这将工作使用 8091 在 docker-compose 中运行您的应用程序,同时尝试使用 8080 端口公开

暂无
暂无

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

相关问题 在Spring Boot中使用自签名https无法验证Postman的POST / GET请求方法 - Can't authenticate a POST/GET request method from Postman, in Spring-boot with self-signed https 无法从Spring-Boot容器连接到MySQL - Can't connect to MySQL from Spring-Boot container 在docker容器中重新部署spring-boot应用程序? - Redeploy spring-boot application in docker container? 使用docker-compose时无法访问docker容器内的spring-boot rest-endpoint - Can't access spring-boot rest-endpoint inside docker container when using docker-compose Spring-boot rest api当前请求不是邮递员的多部分请求 - Spring-boot rest api current request is not multipart request with postman 我无法创建我的自定义 spring-boot 启动器 - I can't create my custom spring-boot starter 为什么我的浏览器在应该发送 POST 请求的地方发送 GET 请求 [Spring-Boot]? - Why does my browser send a GET request on a form where it should be sending a POST request[Spring-Boot]? 如何从docker容器内的java / spring-boot项目运行python脚本(并接收输出)? - How to run python script (and receive output) from java/spring-boot project which is inside a docker container? Spring-boot应用程序无法在docker内启动时启动 - Spring-boot application won't boot at startup inside docker 为什么在尝试将PUT请求从angular5发送到spring-boot时得到未授权? - Why i'm getting Unauthorized when trying to send PUT request from angular5 to spring-boot?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM