你好
当应用程序在IntelliJ IDEA上运行时,一切都正常工作。Mutation is working fine Query is working fine没有任何问题。但是当应用程序在docker容器上工作时,我无法访问GraphQL路径。当应用程序在docker容器上工作时,Spring抛出HTTP“404 not found”异常。我真的不明白这是什么问题。有人能帮我一下吗?有什么问题吗?
**注意:除了GraphQL应用程序与此docker-compose文件外,其他应用程序与POSTMAN一起工作正常。浏览器上看不出Swagger UI。使用docker container Whitelabel Error Page**时也会抛出HTTP 404 Not Found Exception
Docker容器请求端口错误:8093
{
"timestamp": "2023-02-01T19:28:13.384+00:00",
"status": 404,
"error": "Not Found",
"path": "/api/v1/graphql"
}
浏览器图片
docker-compose.yaml browser screenshot
localhost browser screenshot
build.gradle文件
plugins {
id 'java'
id 'org.springframework.boot' version '2.7.9-SNAPSHOT'
id 'io.spring.dependency-management' version '1.0.15.RELEASE'
id 'com.google.protobuf' version '0.8.18'
}
group = 'com.example'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '17'
configurations {
compileOnly {
extendsFrom annotationProcessor
}
}
repositories {
mavenCentral()
maven { url 'https://repo.spring.io/milestone' }
maven { url 'https://repo.spring.io/snapshot' }
}
def grpcVersion = '1.51.0'
def protobufVersion = '3.19.2'
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-graphql'
implementation 'org.springframework.boot:spring-boot-starter-web'
compileOnly 'org.projectlombok:lombok'
developmentOnly 'org.springframework.boot:spring-boot-devtools'
runtimeOnly 'org.postgresql:postgresql'
annotationProcessor 'org.springframework.boot:spring-boot-configuration-processor'
annotationProcessor 'org.projectlombok:lombok'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'org.springframework:spring-webflux'
testImplementation 'org.springframework.graphql:spring-graphql-test'
//GRAPHQL
implementation 'org.springframework.boot:spring-boot-starter-graphql'
testImplementation 'org.springframework.graphql:spring-graphql-test'
testImplementation 'org.springframework:spring-webflux'
//GRPC
implementation "io.grpc:grpc-netty:${grpcVersion}"
implementation "io.grpc:grpc-protobuf:${grpcVersion}"
implementation "io.grpc:grpc-stub:${grpcVersion}"
implementation 'net.devh:grpc-server-spring-boot-starter:2.14.0.RELEASE'
// Log4j
implementation 'log4j:log4j:1.2.17'
}
protobuf {
protoc { artifact = "com.google.protobuf:protoc:${protobufVersion}" }
plugins {
grpc { artifact = "io.grpc:protoc-gen-grpc-java:${grpcVersion}" }
}
generateProtoTasks {
all()*.plugins { grpc {} }
}
}
sourceSets {
main {
java {
srcDirs 'build/generated/source/proto/main/grpc'
srcDirs 'build/generated/source/proto/main/java'
}
}
}
tasks.named('test') {
useJUnitPlatform()
}
应用程序。属性
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect
spring.jpa.hibernate.show-sql=true
spring.jpa.hibernate.ddl-auto=update
spring.datasource.url=jdbc:postgresql://localhost:5434/userDb
spring.datasource.username=user
spring.datasource.password=123456
spring.graphql.graphiql.enabled=true
spring.graphql.graphiql.path=/graphiql
grpc.server.port=9093
spring.graphql.path=/api/v1/graphql
Dockerfile
FROM eclipse-temurin:17-jdk-alpine
ARG JAR_FILE=build/libs/*.jar
COPY ${JAR_FILE} app.jar
ENTRYPOINT ["java","-jar","/app.jar"]
docker-compose。yml
version: '3.8'
services:
rabbitmq:
image: rabbitmq:3-management-alpine
container_name: rabbitmq
restart: always
ports:
- "5672:5672"
- "15672:15672"
user_db:
image: postgres
container_name: user_db
read_only: true
environment:
- POSTGRES_USER=user
- POSTGRES_PASSWORD=123456
- POSTGRES_DB=userDb
expose:
- "5434"
ports:
- "5434:5434"
tmpfs:
- /tmp
- /run
- /run/postgresql
volumes:
- postgres-user-db-volume:/var/lib/postgresql/data
command: -p 5434
myapp.service:
image: 'myapp.service'
container_name: myapp.service
build:
context: .
dockerfile: Dockerfile
environment:
- SPRING_DATASOURCE_URL=jdbc:postgresql://user_db:5434/userDb
- SPRING_DATASOURCE_USERNAME=user
- SPRING_DATASOURCE_PASSWORD=123456
- SPRING_JPA_HIBERNATE_DDL_AUTO=update
- SPRING_JPA_HIBERNATE_DIALECT=org.hibernate.dialect.PostgreSQLDialect
- SPRING_GRAPHQL_GRAPHIQL_ENABLED=true
- SPRING_GRAPHQL_GRAPHIQL_PATH=/graphiql
- GRPC_SERVER_PORT=9093
- SPRING_GRAPHQL_PATH=/api/v1/graphql
ports:
- "8093:8080"
depends_on:
- user_db
volumes:
postgres-user-db-volume:
1条答案
按热度按时间xzabzqsa1#
您是否在类路径中设置了
schema.graphqls
文件?如果是,请注意,您可能依赖spring.graphql.schema.locations
属性的默认值。此默认值在Docker容器中无法正确解析。如果服务无法加载架构,它将在/graphql
端点上抛出404
错误。您应该显式地将该位置添加到
application.properties
中的graphql schema目录中。举个例子