Commit c1aa8413 authored by RenanMontenegro3's avatar RenanMontenegro3

"feat: adiciona suporte ao .env com spring-dotenv e atualiza Config.java"

parent f1bc34f3
DB_DRIVER_CLASS_NAME=com.mysql.cj.jdbc.Driver
DB_PLATFORM=org.hibernate.dialect.MySQL8Dialect
DB_URL=jdbc:mysql://host.docker.internal:3306/porto?createDatabaseIfNotExist=true&serverTimezone=UTC
DB_USERNAME=root
DB_PASSWORD=root
SPRING_SERVLET_MULTIPART_MAX_FILE_SIZE=2GB
SPRING_SERVLET_MULTIPART_MAX_REQUEST_SIZE=2GB
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=pauloacb2020@gmail.com
MAIL_PASSWORD=ehyn ryqu utgv ntjd
MAIL_SMTP_AUTH=true
MAIL_SMTP_STARTTLS_ENABLE=true
JPA_SHOW_SQL=true
JPA_MERGE_ENTITY_COPY_OBSERVER=allow
JPA_HIBERNATE_DDL_AUTO=update
JPA_HIBERNATE_FORMAT_SQL=true
PAGEABLE_ONE_INDEXED_PARAMETERS=true
PAGEABLE_DEFAULT_PAGE_SIZE=2
PAGEABLE_MAX_PAGE_SIZE=20
JWT_ACCESS_SECRET=b9048bb98d808d82bf7250333035db0ea7ada419a53153ec550fcf3dd6d51b13
JWT_ACCESS_EXPIRES_IN=3600
JWT_REFRESH_SECRET=5893d555ee0b886b14929d630c2027b912c104ca29295bf9fd126666baf5bff1
JWT_REFRESH_EXPIRES_IN=7200
DISCO_RAIZ=C:\\fotos-java
DISCO_DIRETORIO_FOTOS=contato-disco
...@@ -25,7 +25,6 @@ ...@@ -25,7 +25,6 @@
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId> <artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.google.code.gson</groupId> <groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId> <artifactId>gson</artifactId>
...@@ -37,7 +36,6 @@ ...@@ -37,7 +36,6 @@
<artifactId>hibernate-validator</artifactId> <artifactId>hibernate-validator</artifactId>
<version>8.0.0.Final</version> <version>8.0.0.Final</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId> <artifactId>spring-boot-starter-validation</artifactId>
...@@ -46,7 +44,11 @@ ...@@ -46,7 +44,11 @@
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId> <artifactId>spring-boot-starter-web</artifactId>
</dependency> </dependency>
<dependency>
<groupId>me.paulschwarz</groupId>
<artifactId>spring-dotenv</artifactId>
<version>4.0.0</version>
</dependency>
<dependency> <dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId> <artifactId>spring-boot-devtools</artifactId>
......
package br.com.treinaweb.twjobs;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.PropertySource;
import org.springframework.stereotype.Component;
@Component
@PropertySource("classpath:application.properties")
public class Config {
@Value("${spring.datasource.driver-class-name}")
String dbDriverClassName;
@Value("${spring.jpa.database-platform}")
String dbPlatform;
@Value("${spring.datasource.url}")
String dbUrl;
@Value("${spring.datasource.username}")
String dbUsername;
@Value("${spring.datasource.password}")
String dbPassword;
@Value("${spring.servlet.multipart.max-file-size}")
String maxFileSize;
@Value("${spring.servlet.multipart.max-request-size}")
String maxRequestSize;
@Value("${spring.mail.host}")
String mailHost;
@Value("${spring.mail.port}")
String mailPort;
@Value("${spring.mail.username}")
String mailUsername;
@Value("${spring.mail.password}")
String mailPassword;
@Value("${spring.mail.properties.mail.smtp.auth}")
String mailSmtpAuth;
@Value("${spring.mail.properties.mail.smtp.starttls.enable}")
String mailStartTls;
@Value("${spring.jpa.show-sql}")
String jpaShowSql;
@Value("${spring.jpa.properties.hibernate.event.merge.entity_copy_observer}")
String jpaMergeEntityCopyObserver;
@Value("${spring.jpa.hibernate.ddl-auto}")
String jpaHibernateDdlAuto;
@Value("${spring.jpa.properties.hibernate.format_sql}")
String jpaFormatSql;
@Value("${spring.data.web.pageable.one-indexed-parameters}")
String pageableOneIndexedParameters;
@Value("${spring.data.web.pageable.default-page-size}")
String pageableDefaultPageSize;
@Value("${spring.data.web.pageable.max-page-size}")
String pageableMaxPageSize;
@Value("${jwt.access.secret}")
String jwtAccessSecret;
@Value("${jwt.access.expires-in}")
String jwtAccessExpiresIn;
@Value("${jwt.refresh.secret}")
String jwtRefreshSecret;
@Value("${jwt.refresh.expires-in}")
String jwtRefreshExpiresIn;
@Value("${contato.disco.raiz}")
String discoRaiz;
@Value("${contato.disco.diretorio-fotos}")
String discoDiretorioFotos;
}
package br.com.treinaweb.twjobs; package br.com.treinaweb.twjobs;
import me.paulschwarz.springdotenv.DotenvPropertySource;
import org.springframework.boot.SpringApplication; import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.scheduling.annotation.EnableAsync; import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
@SpringBootApplication @SpringBootApplication
public class TwjobsApplication { public class TwjobsApplication {
private static final Logger log = LoggerFactory.getLogger(TwjobsApplication.class);
public static void main(String[] args) { public static void main(String[] args) {
AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext();
DotenvPropertySource.addToEnvironment(applicationContext.getEnvironment());
applicationContext.register(Config.class);
applicationContext.refresh();
SpringApplication.run(TwjobsApplication.class, args); SpringApplication.run(TwjobsApplication.class, args);
} }
} }
DB_DRIVER_CLASS_NAME="com.mysql.cj.jdbc.Driver"
DB_PLATFORM="org.hibernate.dialect.MySQL8Dialect"
DB_URL="jdbc:mysql://localhost:3306/porto10?createDatabaseIfNotExist=true&serverTimezone=UTC"
DB_USERNAME="root"
DB_PASSWORD="root"
SPRING_SERVLET_MULTIPART_MAX_FILE_SIZE="2GB"
SPRING_SERVLET_MULTIPART_MAX_REQUEST_SIZE="2GB"
MAIL_HOST="smtp.gmail.com"
MAIL_PORT="587"
MAIL_USERNAME="pauloacb2020@gmail.com"
MAIL_PASSWORD="ehyn ryqu utgv ntjd"
MAIL_SMTP_AUTH="true"
MAIL_SMTP_STARTTLS_ENABLE="true"
JPA_SHOW_SQL="true"
JPA_MERGE_ENTITY_COPY_OBSERVER="allow"
JPA_HIBERNATE_DDL_AUTO="update"
JPA_HIBERNATE_FORMAT_SQL="true"
PAGEABLE_ONE_INDEXED_PARAMETERS="true"
PAGEABLE_DEFAULT_PAGE_SIZE="2"
PAGEABLE_MAX_PAGE_SIZE="20"
JWT_ACCESS_SECRET="b9048bb98d808d82bf7250333035db0ea7ada419a53153ec550fcf3dd6d51b13"
JWT_ACCESS_EXPIRES_IN="3600"
JWT_REFRESH_SECRET="5893d555ee0b886b14929d630c2027b912c104ca29295bf9fd126666baf5bff1"
JWT_REFRESH_EXPIRES_IN="7200"
DISCO_RAIZ=C:\\fotos-java
DISCO_DIRETORIO_FOTOS=contato-disco
...@@ -16,7 +16,6 @@ spring.mail.properties.mail.smtp.starttls.enable=${MAIL_SMTP_STARTTLS_ENABLE} ...@@ -16,7 +16,6 @@ spring.mail.properties.mail.smtp.starttls.enable=${MAIL_SMTP_STARTTLS_ENABLE}
spring.jpa.show-sql=${JPA_SHOW_SQL} spring.jpa.show-sql=${JPA_SHOW_SQL}
spring.jpa.properties.hibernate.event.merge.entity_copy_observer=${JPA_MERGE_ENTITY_COPY_OBSERVER} spring.jpa.properties.hibernate.event.merge.entity_copy_observer=${JPA_MERGE_ENTITY_COPY_OBSERVER}
spring.jpa.hibernate.ddl-auto=${JPA_HIBERNATE_DDL_AUTO} spring.jpa.hibernate.ddl-auto=${JPA_HIBERNATE_DDL_AUTO}
spring.jpa.properties.hibernate.format_sql=${JPA_HIBERNATE_FORMAT_SQL} spring.jpa.properties.hibernate.format_sql=${JPA_HIBERNATE_FORMAT_SQL}
...@@ -24,10 +23,12 @@ spring.data.web.pageable.one-indexed-parameters=${PAGEABLE_ONE_INDEXED_PARAMETER ...@@ -24,10 +23,12 @@ spring.data.web.pageable.one-indexed-parameters=${PAGEABLE_ONE_INDEXED_PARAMETER
spring.data.web.pageable.default-page-size=${PAGEABLE_DEFAULT_PAGE_SIZE} spring.data.web.pageable.default-page-size=${PAGEABLE_DEFAULT_PAGE_SIZE}
spring.data.web.pageable.max-page-size=${PAGEABLE_MAX_PAGE_SIZE} spring.data.web.pageable.max-page-size=${PAGEABLE_MAX_PAGE_SIZE}
br.com.treinaweb.twjobs.jwt.accessSecret=${JWT_ACCESS_SECRET} jwt.access.secret=${JWT_ACCESS_SECRET}
br.com.treinaweb.twjobs.jwt.accessExpiresIn=${JWT_ACCESS_EXPIRES_IN} jwt.access.expires-in=${JWT_ACCESS_EXPIRES_IN}
br.com.treinaweb.twjobs.jwt.refreshSecret=${JWT_REFRESH_SECRET} jwt.refresh.secret=${JWT_REFRESH_SECRET}
br.com.treinaweb.twjobs.jwt.refreshExpiresIn=${JWT_REFRESH_EXPIRES_IN} jwt.refresh.expires-in=${JWT_REFRESH_EXPIRES_IN}
contato.disco.raiz = ${DISCO_RAIZ}
contato.disco.diretorio-fotos = ${DISCO_DIRETORIO_FOTOS}
contato.disco.raiz=${DISCO_RAIZ}
contato.disco.diretorio-fotos=${DISCO_DIRETORIO_FOTOS}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment