0
I’m having an error, when running my application with profile test, Spring Boot does not create the same database in the local profile.
Any suggestions?
Follow my application-local file.properties:
# Hibernate
logging.level.org.hibernate.SQL=DEBUG
logging.level.org.hibernate.type.descriptor.sql.BasicBinder=TRACE
spring.datasource.username=rw_itau
spring.datasource.password=rw_itau
spring.datasource.url=jdbc\:postgresql\://localhost/rw_itau
spring.datasource.driver-class-name=org.postgresql.Driver
spring.jpa.hibernate.ddl-auto=create-drop
And the application-test.properties file:
# Hibernate
logging.level.org.hibernate.SQL=DEBUG
logging.level.org.hibernate.type.descriptor.sql.BasicBinder=TRACE
spring.datasource.username=rw_itau
spring.datasource.password=rw_itau
spring.datasource.url=jdbc\:postgresql\://localhost/rw_itau_teste
spring.datasource.driver-class-name=org.postgresql.Driver
spring.jpa.hibernate.ddl-auto=create-drop
Plus I have several classes as the starting class of Springboot:
package br.com.zup.rw.itau;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.stereotype.Controller;
@SpringBootApplication
@Controller
public class Boot
{
public static void main(String[] args)
{
SpringApplication.run(Boot.class, args);
}
}
I am using Maven and Docker with Banco Postgres the error generated is this:
org.postgresql.util.Psqlexception: FATAL: database "rw_itau_teste" does not exist
I run the project with this argument:
-Dspring.profiles.active=test
But when running with the local argument, the bank is normally created.
-Dspring.profiles.active=local
When I run the second error profile when connecting to the database.
You could update your question with an example test (with an setup annotations and whatever else is needed), its folder structure and the relevant parts of the Maven / Gradle / build system?
– Anthony Accioly
See if it’s better? I’m using Maven, but I don’t believe there’s anything very important to post besides springboot
– Renato Serra
Renato, I would post the test settings with
@TestPropertySource
,@ActiveProfiles
, etc and a test. It may be missing some annotation, some file may be in the wrong folder, etc.– Anthony Accioly
Opa my properties files are all in the Resources src/main/Resources folder. I am using the Annotation @Activeprofiles("test") in my test class, only for the project to understand which profile to use. In addition to this I have these settings in my test: Runwith(Springrunner.class) Springboottest Autoconfiguremockmvc Autoconfigurerestdocs(outputDir = "target/snippets")
– Renato Serra
Try to move the file
application-test.properties
forsrc/test/resources
. If it doesn’t work please update the question with a MVCE– Anthony Accioly
@Anthonyaccioly by what I understood so far the system is opening the application-test.properties, correctly it just fails to create the bank, the strange thing is that in application-local.properties the bank was created normally.
– Renato Serra
I thought the problem was really stupid in vdd, I’m creating a single database on Docker, I just need to learn how to create Multiplus.
– Renato Serra