UPDATE: I realized that the problem was related to using the environment variables. When I didn't use them, it worked fine. The situation is exactly the same as this post . I don't know if it is the best solution, but for now I have disabled the test, using @Disabled annotation.
Hi, I have a Spring Boot application. When I run it locally, I can use the DB just fine. I am able to create entities using my api, they are correctly created on the DB.
But when I run the tests for the app, the following error appears:
org.hibernate.service.spi.ServiceException: Unable to create requested service [org.hibernate.engine.jdbc.env.spi.JdbcEnvironment]
org.hibernate.HibernateException: Access to DialectResolutionInfo cannot be null when 'hibernate.dialect' not set
This is the application.properties:
spring.datasource.url=jdbc:mysql://localhost:${MYSQL_DB_PORT}/myproject-db
spring.datasource.username=${MYSQL_DB_USERNAME}
spring.datasource.password=${MYSQL_DB_PASSWORD}
spring.jpa.hibernate.ddl-auto=update
spring.jpa.show-sql=true
server.servlet.context-path=/myproject-api/v1
(I have the environment variables set on IntelliJ Run Configurations)
These are the dependencies in my pom.xml:
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.24</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.12.0</version>
<scope>compile</scope>
</dependency>
</dependencies>
I know there are a lot of already answered questions about this, but nothing has worked for me so far.
1条答案
按热度按时间rjee0c151#
如果我处在你的位置,我会这样做:
1.设置maven surefire以从
~/.m2/settings.xml
中的配置文件中获取系统属性,如:1.使用占位符的真实的值在
~/.m2/settings.xml
中设置maven配置文件:1.将www.example.com放入application.properties
src/test/resources
中,内容如下:之后,测试应该可以工作,因为IntelliJ识别这样的配置
此外,您可以通过IntelliJ设置运行主要spring引导类,而无需配置环境变量,但可以利用Maven配置文件。
1.安装
SpringBoot Patcher
插件1.将
application.properties
放置在与src
文件夹相同的级别,其内容如下:1.设置
spring-boot-maven
插件,例如: