Я использую базу данных H2 с проектом Spring Boot. У меня есть зависимость времени выполнения от h2 в файле build.gradle.kts, но он не может найти драйвер.
Caused by: java.lang.IllegalStateException: Driver for test database type [H2] is not available
at org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseConfigurerFactory.getConfigurer(EmbeddedDatabaseConfigurerFactory.java:57) ~[spring-jdbc-5.2.4.RELEASE.jar:5.2.4.RELEASE]
at org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseFactory.setDatabaseType(EmbeddedDatabaseFactory.java:132) ~[spring-jdbc-5.2.4.RELEASE.jar:5.2.4.RELEASE]
at org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder.setType(EmbeddedDatabaseBuilder.java:121) ~[spring-jdbc-5.2.4.RELEASE.jar:5.2.4.RELEASE]
at com.example.datarestdemo.DataRestDemoApplication.dataSource(DataRestDemoApplication.kt:24) ~[main/:na]
at com.example.datarestdemo.DataRestDemoApplication$$EnhancerBySpringCGLIB$$3e09cdea.CGLIB$dataSource$0(<generated>) ~[main/:na]
at com.example.datarestdemo.DataRestDemoApplication$$EnhancerBySpringCGLIB$$3e09cdea$$FastClassBySpringCGLIB$$1a09d5e.invoke(<generated>) ~[main/:na]
at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:244) ~[spring-core-5.2.4.RELEASE.jar:5.2.4.RELEASE]
at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:331) ~[spring-context-5.2.4.RELEASE.jar:5.2.4.RELEASE]
at com.example.datarestdemo.DataRestDemoApplication$$EnhancerBySpringCGLIB$$3e09cdea.dataSource(<generated>) ~[main/:na]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_211]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_211]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_211]
at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_211]
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154) ~[spring-beans-5.2.4.RELEASE.jar:5.2.4.RELEASE]
... 217 common frames omitted
Caused by: java.lang.ClassNotFoundException: org.h2.Driver
at java.net.URLClassLoader.findClass(URLClassLoader.java:382) ~[na:1.8.0_211]
at java.lang.ClassLoader.loadClass(ClassLoader.java:424) ~[na:1.8.0_211]
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349) ~[na:1.8.0_211]
at java.lang.ClassLoader.loadClass(ClassLoader.java:357) ~[na:1.8.0_211]
at java.lang.Class.forName0(Native Method) ~[na:1.8.0_211]
at java.lang.Class.forName(Class.java:348) ~[na:1.8.0_211]
at org.springframework.util.ClassUtils.forName(ClassUtils.java:282) ~[spring-core-5.2.4.RELEASE.jar:5.2.4.RELEASE]
at org.springframework.jdbc.datasource.embedded.H2EmbeddedDatabaseConfigurer.getInstance(H2EmbeddedDatabaseConfigurer.java:51) ~[spring-jdbc-5.2.4.RELEASE.jar:5.2.4.RELEASE]
at org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseConfigurerFactory.getConfigurer(EmbeddedDatabaseConfigurerFactory.java:49) ~[spring-jdbc-5.2.4.RELEASE.jar:5.2.4.RELEASE]
... 230 common frames omitted
Вот как я добавил зависимость времени выполнения
runtimeOnly("com.h2database:h2")
и это конфигурация плагина
plugins {
id("org.springframework.boot") version "2.2.5.RELEASE"
id("io.spring.dependency-management") version "1.0.9.RELEASE"
kotlin("jvm") version "1.3.61"
kotlin("plugin.spring") version "1.3.61"
}
Я что-то упустил ?