I’m using springboot, zuul and eureka.
When I try to reach a springboot endpoint through a zuul service, I get 404 NOT FOUND.
I run all the services with docker containers.
Do anyone of you know what might be wrong?
The springboot service with the resouces (which I’m trying to reach through zuul) is called ContentService.
The endpoint in the ContentService I’m trying to reach
@RestController
@RequestMapping("/content")
@RequiredArgsConstructor
@EnableGlobalMethodSecurity(prePostEnabled = true)
public class CommunityController {
private CommuntiyService communtiyService;
@Autowired
private ACLverifier acLverifier;
@Autowired
private RabbitTemplate rabbitTemplate;
@PostMapping("/send_message/{message}")
public void sendMessage(
@PathVariable("message") String message
) {
System.out.println("sent message: " + message);
rabbitTemplate.convertAndSend("commentExchange", "commentRoutingKey", message);
}
Post request Im sending:
http://localhost:8080/cont/content/send_message/hallo
Response – 404 NOT FOUND:
{
"timestamp": "2024-06-26T08:20:29.052+00:00",
"path": "/cont/content/send_message/hallo",
"status": 404,
"error": "Not Found",
"requestId": "2355b902"
}
ContentService
application.properties:
spring.application.name=ContentService
server.port=8082
spring.data.mongodb.uri=mongodb://mongodb:27017/test
# Use the database with:
# docker exec -it mongodb bash
# mongosh
# show dbs
# use <collection>
# db.<entity>.find()
# JWT
security.jwt.secret-key=3cfa76ef14937c1c0ea519f8fc057a80fcd04a7420f8e8bcd0a7567c272e007b
# 1h in millisecond
security.jwt.expiration-time=3600000
# rabbitmq
spring.rabbitmq.host=rabbitmq
spring.rabbitmq.port=5672
spring.rabbitmq.username=guest
spring.rabbitmq.password=guest
# Eureka
# eureka.instance.preferIpAddress=true
eureka.client.registerWithEureka=true
eureka.client.fetchRegistry=true
eureka.client.serviceUrl.defaultZone=${EUREKA_URI:http://eureka:8761/eureka}
# Actuator
management.endpoints.web.exposure.include=*
Application:
@EnableDiscoveryClient
@EnableFeignClients
@SpringBootApplication
public class ContentServiceApplication {
public static void main(String[] args) {
SpringApplication.run(ContentServiceApplication.class, args);
}
}
Eureka
application.properties:
spring.application.name=Eruka
server.port=8761
eureka.client.registerWithEureka=false
eureka.client.fetchRegistry=false
eureka.client.serviceUrl.defaultZone=http://eureka:8761/eureka
eureka.renewalPercentThreshold=0.85
Application:
@EnableEurekaServer
@SpringBootApplication
public class ErukaApplication {
public static void main(String[] args) {
SpringApplication.run(ErukaApplication.class, args);
}
}
Gateway/Zuul
application.properties:
spring.application.name=Gateway
server.port=8080
spring.docker.compose.enabled=false
spring.main.web-application-type=reactive
spring.jpa.hibernate.ddl-auto=none
# Eureka
# eureka.instance.preferIpAddress=true
eureka.client.registerWithEureka=true
eureka.client.fetchRegistry=true
eureka.client.serviceUrl.defaultZone=${EUREKA_URI:http://eureka:8761/eureka}
# Actuator
management.endpoints.web.exposure.include=*
management.port=8080
# ===================================
# Zuul
# Content service
zuul.routes.content-service.serviceId=content-service
zuul.routes.content-service.path=/cont/**
zuul.routes.content-service.stripPrefix=true
Application:
@EnableDiscoveryClient
@EnableZuulProxy
@SpringBootApplication
public class GatewayApplication {
public static void main(String[] args) {
SpringApplication.run(GatewayApplication.class, args);
}
}
I run all the services with a docker-compose file:
version: '3.8'
services:
# ============= GATEWAY ===============
gateway:
build:
context: .
dockerfile: API_GATEWAY/DockerfileGateway
container_name: Gateway
ports:
- "8080:8080"
networks:
- ms_architecture
# ===================================
# ============= EUREKA ===============
eureka:
build:
context: .
dockerfile: API_GATEWAY/DockerfileEruka
container_name: Eureka
ports:
- "8761:8761"
networks:
- ms_architecture
# ===================================
# ============= CONTENT SERVICE ===============
mongodb:
image: mongo:latest
container_name: mongodb
ports:
- 27017:27017
networks:
- ms_architecture
content_service:
build:
context: .
dockerfile: MicroServices/Content/ContentServiceDockerfile
depends_on:
- mongodb
ports:
- "8082:8082"
environment:
SPRING_DATA_MONGODB_URI: mongodb://mongodb:27017/test
RABBITMQ_HOST: rabbitmq
RABBITMQ_PORT: 5672
networks:
- ms_architecture
# ===================================
# ============= RABBITMQ ===============
rabbitmq:
image: rabbitmq:management
container_name: rabbitmq
ports:
- "5672:5672"
- "15672:15672"
networks:
- ms_architecture
healthcheck:
test: ["CMD", "rabbitmqctl", "status"]
interval: 30s
timeout: 10s
retries: 3
# ===================================
networks:
ms_architecture:
driver: bridge