diff --git a/exposed-spring-boot-starter/src/main/kotlin/org/jetbrains/exposed/spring/DatabaseInitializer.kt b/exposed-spring-boot-starter/src/main/kotlin/org/jetbrains/exposed/spring/DatabaseInitializer.kt index abb1afb183..c73d778ff0 100644 --- a/exposed-spring-boot-starter/src/main/kotlin/org/jetbrains/exposed/spring/DatabaseInitializer.kt +++ b/exposed-spring-boot-starter/src/main/kotlin/org/jetbrains/exposed/spring/DatabaseInitializer.kt @@ -53,5 +53,5 @@ fun discoverExposedTables(applicationContext: ApplicationContext, excludedPackag excludedPackages.forEach { provider.addExcludeFilter(RegexPatternTypeFilter(Pattern.compile(it.replace(".", "\\.") + ".*"))) } val packages = AutoConfigurationPackages.get(applicationContext) val components = packages.map { provider.findCandidateComponents(it) }.flatten() - return components.map { Class.forName(it.beanClassName).kotlin.objectInstance as Table } + return components.mapNotNull { Class.forName(it.beanClassName).kotlin.objectInstance as? Table } } diff --git a/exposed-spring-boot-starter/src/test/kotlin/org/jetbrains/exposed/spring/DatabaseInitializerTest.kt b/exposed-spring-boot-starter/src/test/kotlin/org/jetbrains/exposed/spring/DatabaseInitializerTest.kt index 5b6487575a..90bbf3247e 100644 --- a/exposed-spring-boot-starter/src/test/kotlin/org/jetbrains/exposed/spring/DatabaseInitializerTest.kt +++ b/exposed-spring-boot-starter/src/test/kotlin/org/jetbrains/exposed/spring/DatabaseInitializerTest.kt @@ -7,6 +7,7 @@ import org.jetbrains.exposed.sql.Database import org.jetbrains.exposed.sql.selectAll import org.jetbrains.exposed.sql.transactions.transaction import org.junit.jupiter.api.Assertions +import org.junit.jupiter.api.Assertions.assertArrayEquals import org.junit.jupiter.api.Assertions.assertEquals import org.junit.jupiter.api.Test import org.springframework.beans.factory.annotation.Autowired @@ -33,4 +34,12 @@ open class DatabaseInitializerTest { } } } + + @Test + fun `ignore non object Table`() { + Database.connect("jdbc:h2:mem:test-spring", user = "sa", driver = "org.h2.Driver") + val tables = discoverExposedTables(applicationContext, listOf()) + assertEquals(2, tables.size) + assertArrayEquals(listOf(TestTable, IgnoreTable).toTypedArray(), tables.toTypedArray()) + } } diff --git a/exposed-spring-boot-starter/src/test/kotlin/org/jetbrains/exposed/spring/tables/NonObjectTable.kt b/exposed-spring-boot-starter/src/test/kotlin/org/jetbrains/exposed/spring/tables/NonObjectTable.kt new file mode 100644 index 0000000000..e026b8cee5 --- /dev/null +++ b/exposed-spring-boot-starter/src/test/kotlin/org/jetbrains/exposed/spring/tables/NonObjectTable.kt @@ -0,0 +1,5 @@ +package org.jetbrains.exposed.spring.tables + +import org.jetbrains.exposed.sql.Table + +open class NonObjectTable : Table()