Para reproduzir o erro:
Executar o comando docker compose run --build
Resultado: "APPLICATION FAILED TO START" com os seguintes detalhes:
**Description:**
Parameter 0 of constructor in br.com.alura.codechella.infra.email.EnviadorDeEmailReal required a bean of type 'org.springframework.mail.javamail.JavaMailSender' that could not be found.
**Action:**
Consider defining a bean of type 'org.springframework.mail.javamail.JavaMailSender' in your configuration.
Outra informação relevante: A applicação entra num loop de tentativas de arranque, culminando sempre no "APPLICATION FAILED TO START", com os detalhes indicados no Resultado, acima.
O que já foi feito:
- Anotar com
@Autowired
na variávelprivate final JavaMailSender emailSender
, da classeEnviadorDeEmailReal
; - Anotar com
@Component
a interfaceEnviadorDeEmail
;
docker-compose.yml:
version: '3'
services:
mysql:
image: mysql:8.0.36
env_file: ./env/mysql.env
volumes:
- ./mysql-data:/var/lib/mysql
restart: unless-stopped
healthcheck:
test: mysqladmin ping -h 127.0.0.1 -u $$MYSQL_USER --password=$$MYSQL_PASSWORD
interval: 5s
timeout: 5s
retries: 10
app:
build:
context: .
env_file: ./env/app.env
restart: unless-stopped
depends_on:
mysql:
condition: service_healthy
volumes:
mysql-data:
app.env:
SPRING_PROFILES_ACTIVE=prod
SPRING_DATASOURCE_URL=jdbc:mysql://mysql:3306/codechella_db
SPRING_DATASOURCE_USERNAME=codechella_user
SPRING_DATASOURCE_PASSWORD=codechella_pwd
MAIL_HOST=smtp.gmail.com
MAIL_USER=mail_user
MAIL_PASSWORD=mail_pwd
APP_JWT_SECRET=jwt_secret
application-prod.properties:
spring.datasource.url=${SPRING_DATASOURCE_URL}
spring.datasource.username=${SPRING_DATASOURCE_USERNAME}
spring.datasource.password=${SPRING_DATASOURCE_PASSWORD}
spring.jpa.show-sql=false
spring.jpa.properties.hibernate.format_sql=false
spring.mail.host=${MAIL_HOST}
spring.mail.username=${MAIL_USER}
spring.mail.password=${MAIL_PASSWORD}
spring.mail.port=587
spring.mail.properties.mail.smtp.auth=true
spring.mail.properties.mail.smtp.starttls.enable=true
spring.mail.properties.mail.smtp.starttls.required=true
app.security.jwt.secret=${APP_JWT_SECRET}