How do I configure my Spring Boot application so that when I run unit tests it will use embedded SQL Server so that stored procedures can be executed?
1 Answer
use spring boot jpa
compile('org.springframework.boot:spring-boot-starter-data-jpa')
have a application-local.yaml config
spring:
datasource:
driverClassName: org.h2.Driver
username: sa
password: password
url: jdbc:h2:mem:testdb;MODE=MSSQLServer;DATABASE_TO_LOWER=TRUE
MODE can be any depending upon your dev or prod db to simulate the same.
add the following in build.gradle
bootRun {
args = ["--spring.profiles.active=local"]
}
2 Comments
ncd
can you give an example/code snippet for configurations and all the properties? During application load I got syntax error for procedure execution. Is MS sql procedure execution is compatible in the above mode?
ncd
Adding to above point, stored procedures are in ms sql compatible syntax. Error is : java.lang.IllegalStateException: Failed to load ApplicationContext Caused by: org.h2.jdbc.JdbcSQLException: Syntax error in SQL statement [42001-148]