ClassNotFoundException: org.springframework.core.NativeDetector报错及解决

使用springcloud想搭建一个微服务架构,在parent里引用了spring-boot-starter-web依赖,子项目却启动不了,报错如下:

搭建springcloud的工程遇到的问题
Exception in thread "main" java.lang.IllegalArgumentException: Cannot instantiate interface org.springframework.context.ApplicationListener : org.springframework.boot.autoconfigure.BackgroundPreinitializer
	at org.springframework.boot.SpringApplication.createSpringFactoriesInstances(SpringApplication.java:450)
	at org.springframework.boot.SpringApplication.getSpringFactoriesInstances(SpringApplication.java:429)
	at org.springframework.boot.SpringApplication.getSpringFactoriesInstances(SpringApplication.java:420)
	at org.springframework.boot.SpringApplication.<init>(SpringApplication.java:270)
	at org.springframework.boot.SpringApplication.<init>(SpringApplication.java:249)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1260)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1248)
	at com.hm.SchoolApplication.main(SchoolApplication.java:17)
Caused by: java.lang.NoClassDefFoundError: org/springframework/core/NativeDetector
	at org.springframework.boot.autoconfigure.BackgroundPreinitializer.<clinit>(BackgroundPreinitializer.java:71)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
	at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
	at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:172)
	at org.springframework.boot.SpringApplication.createSpringFactoriesInstances(SpringApplication.java:446)
	... 7 more
Caused by: java.lang.ClassNotFoundException: org.springframework.core.NativeDetector
	at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:418)
	at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:355)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:351)
	... 14 more

解决方式:父工程里只依赖spring-boot-starter-web还不够,要加上

	<parent>
        <artifactId>spring-boot-starter-parentartifactId>
        <groupId>org.springframework.bootgroupId>
        <version>2.1.0.RELEASEversion>
    parent>

再次启动,就好了。

你可能感兴趣的:(spring,java,spring,boot)