不要在pom.xml文件中配置这个属性:

<properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <start-class>eurekademo.EurekaApplication</start-class>
        <java.version>1.8</java.version>
        <docker.image.prefix>springcloud</docker.image.prefix>
        <spring.cloud.version>Finchley.SR2</spring.cloud.version>
        <guava.version>19.0</guava.version>
        <hessian.version>4.0.38</hessian.version>
        <protostuff.version>1.1.3</protostuff.version>
        <kryo.version>4.0.0</kryo.version>
        <org.slf4j-version>1.7.7</org.slf4j-version>
        <junit.version>4.12</junit.version>
    </properties>

如果配置了这个属性,java -jar启动spring boot的时候就会认为这个类eurekademo.EurekaApplication是启动类,然后就会报找不到启动类的错误:

Exception in thread "main" java.lang.ClassNotFoundException: eurekademo.EurekaApplication
        at java.net.URLClassLoader.findClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at org.springframework.boot.loader.LaunchedURLClassLoader.loadClass(LaunchedURLClassLoader.java:93)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:46)
        at org.springframework.boot.loader.Launcher.launch(Launcher.java:87)
        at org.springframework.boot.loader.Launcher.launch(Launcher.java:50)
        at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:51)

如果真的想自己配置启动类,可以使用maven-shade-plugin插件。

Logo

权威|前沿|技术|干货|国内首个API全生命周期开发者社区

更多推荐