我正在尝试与Kotlin进行弹簧启动测试。
UserServiceTest类:
@RunWith(SpringRunner::class)
@SpringBootTest
class UserServiceTest {
@Autowired
lateinit var userService: UserService
@Test
fun someTest() {
}
}
错误日志:
java.lang.IllegalStateException: Failed to load ApplicationContext
.....
Caused by: java.lang.NoClassDefFoundError: org.springframework.boot.context.properties.ConfigurationPropertiesBean
at org.springframework.cloud.context.properties.ConfigurationPropertiesBeans.postProcessBeforeInitialization(ConfigurationPropertiesBeans.java:94)
....
... 51 more
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'bootstrapImportSelectorConfiguration': Initialization of bean failed; nested exception is java.lang.NoClassDefFoundError: org.springframework.boot.context.properties.ConfigurationPropertiesBean
....
... 24 more
Caused by: java.lang.ClassNotFoundException: org.springframework.boot.context.properties.ConfigurationPropertiesBean
at java.net.URLClassLoader.findClass(URLClassLoader.java:591)
at java.lang.ClassLoader.loadClassHelper(ClassLoader.java:953)
at java.lang.ClassLoader.loadClass(ClassLoader.java:898)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:352)
at java.lang.ClassLoader.loadClass(ClassLoader.java:881)
... 55 more
问题是弹簧无法加载ApplicationContext
。我该如何解决?
答案 0 :(得分:0)
您使用哪个版本的Spring Boot和Kotlin?
Here,您可以使用Spring Boot 2.3.0.RELEASE,Kotlin 1.3.72和JUnit 5.6.2找到一个简单的演示。也许会对您有帮助。