2
respostas

[Dúvida] Não consigo fazer build

Olá, eu resolvi fazer um deploy real e escolhi a Azure para isso, porem na etapa de build com o Maven, estou com problemas nas variáveis de ambiente. Se eu simplesmente não as utilizo e passo a url, senha etc diretamente, eu consigo fazer o deploy, mas se uso as variáveis de ambiente, isso não ocorre. Queria saber se estou deixando de fazer algo com essas variáveis. Eu sei que foge um pouco do escopo do curso, mas como estou com problemas de build e variáveis de ambiente, talvez alguém consiga me ajudar. Segue o repositório: https://github.com/Mayara-Amorim/Voll.med/blob/master/env/app.env

Obrigada!

2 respostas

Oi!

Qual o erro que está acontecendo? Manda o log aqui.

Obs: Vi que você subiu pro GitHub os arquivos .env com as variáveis de ambiente. Isso jamais deve ser feito! Qualquer pessoa agora vai conseguir se conectar no seu banco de dados na Azure e ter acesso para ler, modificar e apagar os dados.

Por mais que seja um projeto para estudos, é bom já se acostumar a nunca subir dados sensíveis para repositórios no GitHub ;)

Ao tentar realizar o build inicialmente:

initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'flyway' defined in class path resource [org/springframework/boot/autoconfigure/flyway/FlywayAutoConfiguration$FlywayConfiguration.class]: Failed to instantiate [org.flywaydb.core.Flyway]: Factory method 'flyway' threw exception with message: Error creating bean with name 'dataSource' defined in class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceConfiguration$Hikari.class]: Failed to instantiate [com.zaxxer.hikari.HikariDataSource]: Factory method 'dataSource' threw exception with message: URL must start with 'jdbc'
2024-05-04T18:07:04.429-03:00  INFO 7096 --- [           main] .s.b.a.l.ConditionEvaluationReportLogger : 
Error starting ApplicationContext. To display the condition evaluation report re-run your application with 'debug' enabled.
2024-05-04T18:07:04.466-03:00 ERROR 7096 --- [           main] o.s.boot.SpringApplication               : Application run failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'flyway' defined in class path resource [org/springframework/boot/autoconfigure/flyway/FlywayAutoConfiguration$FlywayConfiguration.class]: Failed to instantiate [org.flywaydb.core.Flyway]: Factory method 'flyway' threw exception with message: Error creating bean with name 'dataSource' defined in class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceConfiguration$Hikari.class]: Failed to instantiate [com.zaxxer.hikari.HikariDataSource]: Factory method 'dataSource' threw exception with message: URL must start with 'jdbc'
    at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:654) ~[spring-beans-6.0.12.jar:6.0.12]
    at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:642) ~[spring-beans-6.0.12.jar:6.0.12]

Quando entrou no contexto de testes:

Caused by: java.sql.SQLException: Access denied for user '${DATASOURCE_USERNAME}'@'181.189.122.75' (using password: YES)
    at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:130)
    at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:122)
    at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:825)
    at com.mysql.cj.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:446)
    at com.mysql.cj.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:239)
    at com.mysql.cj.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:188)
    at com.zaxxer.hikari.util.DriverDataSource.getConnection(DriverDataSource.java:138)
    at com.zaxxer.hikari.pool.PoolBase.newConnection(PoolBase.java:359)
    at com.zaxxer.hikari.pool.PoolBase.newPoolEntry(PoolBase.java:201)
    at com.zaxxer.hikari.pool.HikariPool.createPoolEntry(HikariPool.java:470)
    at com.zaxxer.hikari.pool.HikariPool.checkFailFast(HikariPool.java:561)
    at com.zaxxer.hikari.pool.HikariPool.<init>(HikariPool.java:100)
    at com.zaxxer.hikari.HikariDataSource.getConnection(HikariDataSource.java:112)
    at org.flywaydb.core.internal.jdbc.JdbcUtils.openConnection(JdbcUtils.java:48)
    ... 102 more
[INFO] 
[INFO] Results:
[INFO] 
[ERROR] Errors: 
[ERROR]   ApiApplicationTests.contextLoads » IllegalState Failed to load ApplicationContext for [WebMergedContextConfiguration@5d508d22 testClass

Ultimo erro:

Please refer to C:\Users\Mayara Amorim\Desktop\ESTUDOS\BACKEND\JAVA\api\target\surefire-reports for the individual test results.
Please refer to dump files (if any exist) [date].dump, [date]-jvmRun[N].dump and [date].dumpstream.

Se no profile dafault eu retiro a configuracão para apontar para prod, o build ocorre, mas se tento rodar a aplicacão: recebo $ java -Dspring.profiles.active=prod -DSPRING_DATASOURCE_URL=jdbc:mysql://voll-med.mysql.database.azure.com:3306/vollmed_api -DSPRING_DATASOURCE_USERNAME=db_user_voll -DSPRING_DATASOURCE_PASSWORD=Vollmed_api_pwd -jar target/api-0.0.1-SNAPSHOT.jar

Erro: ocorreu LinkageError ao carregar a classe principal org.springframework.boot.loader.JarLauncher java.lang.UnsupportedClassVersionError: org/springframework/boot/loader/JarLauncher has been compiled by a more recent version of the Java Runtime (class file version 61.0), this version of the Java Runtime only recognizes class file versions up to 55.0