java.lang.ClassNotFoundException: org.springframework.boot.SpringApplication Maven

后端 未结 13 920
醉酒成梦
醉酒成梦 2020-11-28 11:10

I\'m trying to create a spring mvc application. This is my pom.xml




        
相关标签:
13条回答
  • 2020-11-28 11:26

    Clean your maven cache and rerun:

    mvn dependency:purge-local-repository
    
    0 讨论(0)
  • 2020-11-28 11:29

    Here the packaging is jar type, hence you need to use manifest plugin, in order to add dependencies into the Manifest.mf

    The problem here is that maven could find the dependencies in pom file and compile the source code and create the output jar. But when executing the jar, manifest.mf file contains no details of dependencies. Hence you got this error. This is a case of classpath errors.

    Here you can find the details on how to do it.

    0 讨论(0)
  • 2020-11-28 11:34

    If you would like to stay in spring boot space just set the pom packaging to jar

    <packaging>jar</packaging>
    

    and add the spring-boot-maven-plugin to you build properties in the pom.xml file:

    <build>
      <plugins>
        <plugin>
          <groupId>org.springframework.boot</groupId>
          <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
      </plugins>
    </build>
    

    then a simple mvn package command will create a complete executable jar file.

    See the very good spring reference doc for more details (doing it gradle style also) spring reference doc

    0 讨论(0)
  • 2020-11-28 11:35

    Your jar does not contain the dependencies such as spring-boot which it is looking for during runtime. You can build a consolidated jar with all the dependencies as outlined in this question.

    0 讨论(0)
  • 2020-11-28 11:35

    I had the same problem and tried most of the solutions suggested above, but none worked for me. Eventually, I rebuild my entire com.springframework (maven) repository (by simply deleting .m2/org/springworkframework directory).

    It worked for me.

    0 讨论(0)
  • 2020-11-28 11:38

    The answer to the above question is "none of the above". When you download new STS it won't support the old Spring Boot parent version. Just update parent version with latest comes with STS it will work.

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.5.8.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    

    If you have problem getting the latest, just create a new Spring Starter Project. Go to File->New->Spring Start Project and create a demo project you will get the latest parent version, change your version with that all will work. I do this every time I change STS.

    0 讨论(0)
提交回复
热议问题