0

I'm encountering the following error only when running Test class. This occurs only with Spring Boot 2 (M3 for now), while it's OK with Spring Boot 1.5.3. MyBatis 1.3.1-SNAPSHOT seems not available/published, so I use 1.3.0.

java.lang.IllegalArgumentException:
Property 'sqlSessionFactory' or 'sqlSessionTemplate' are required

Also, no problem so far when launching external Tomcat with JNDI lookup: mappers and beans are loaded fine.

build.gradle

compile("org.mybatis.spring.boot:mybatis-spring-boot-starter:${myBatisBootVersion}")
compile('org.springframework.boot:spring-boot-starter-web') {
    exclude module: "spring-boot-starter-tomcat"
}
compile("mysql:mysql-connector-java:6.0.6")
compile("org.springframework.boot:spring-boot-starter-log4j2:${springBootVersion}")

compileOnly("javax.servlet:javax.servlet-api:3.1.0")

testCompile("javax.servlet:javax.servlet-api:3.1.0")
testCompile('org.springframework.boot:spring-boot-starter-test')
testCompile("org.mybatis.spring.boot:mybatis-spring-boot-starter-test:1.3.0")

Application.java

@Configuration
@SpringBootApplication(exclude = JmxAutoConfiguration.class)
@MapperScan("eu.davidea.avocadoserver.persistence.mybatis.mappers")
public class Application extends SpringBootServletInitializer {

    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
        return application.sources(Application.class);
    }

    public static void main(final String[] args) {
        SpringApplication.run(Application.class, args);
    }

}

application.properties

spring.profiles.active=test

application-local.properties (picked up at local deployment)

spring.datasource.jndi-name='java:comp/env/jdbc/avocadoDB'

ApplicationTests.java

@ActiveProfiles("test")
@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.NONE)
public class ApplicationTests {

    @Test
    public void contextLoads() {
    }

}

application-test.poperties (picked up when launching tests)

spring.datasource.url=jdbc:mysql://...
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.username=...
spring.datasource.password=...

What's wrong in this configuration for when switching to Spring Boot 2 ?

Project will be available in Github somehow soon.

Brian Clozel
  • 56,583
  • 15
  • 167
  • 176
Davideas
  • 3,226
  • 2
  • 33
  • 51

1 Answers1

0

I found a solution myself:

Since I was using external Tomcat, I removed from the classpath the Hikari conn pool because not used, but during JUnit test phase a JDBC connection pool was missing, so I put it back.

Davideas
  • 3,226
  • 2
  • 33
  • 51