You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Spring Boot 2.0.0项目启动遭遇ClassNotFoundException求助

Fixing ClassNotFoundException for Your Spring Boot 2.0.0 Project

First, let's confirm your provided pom.xml looks standard for a basic Spring Boot web setup:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
	<modelVersion>4.0.0</modelVersion>

	<groupId>com.kkesley</groupId>
	<artifactId>springtest</artifactId>
	<version>0.0.1-SNAPSHOT</version>
	<packaging>jar</packaging>

	<name>springtest</name>
	<description>Demo project for Spring Boot</description>

	<parent>
		<groupId>org.springframework.boot</groupId>
		<artifactId>spring-boot-starter-parent</artifactId>
		<version>2.0.0.RELEASE</version>
		<relativePath/>
	</parent>

	<properties>
		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
		<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
		<java.version>1.8</java.version>
	</properties>

	<dependencies>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-web</artifactId>
		</dependency>

		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-test</artifactId>
			<scope>test</scope>
		</dependency>
	</dependencies>

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

</project>

Your configuration looks solid, so let's walk through the most common fixes for ClassNotFoundException:

  • Refresh and re-download Maven dependencies
    This error often pops up when dependencies are corrupted or never fully downloaded to your local Maven repo. Run this command in your project root folder:

    mvn clean install -U
    

    The -U flag forces Maven to update snapshot dependencies, and clean wipes out old compiled files that might be causing conflicts.

  • Make sure your Java version matches the project
    Your pom specifies <java.version>1.8</java.version>, so double-check:

    • Your IDE's project SDK is set to JDK 8 (e.g., in IntelliJ: File → Project Structure → Project SDK)
    • Your system's JAVA_HOME environment variable points to a JDK 8 installation
      Spring Boot 2.0.x supports JDK 8-10, but mismatched versions can break class loading.
  • Clear IDE caches and recompile
    IDEs sometimes hold onto stale cache data that messes with class detection:

    • For IntelliJ: Go to File → Invalidate Caches... and select "Invalidate and Restart"
    • For Eclipse: Go to Project → Clean, then right-click your project → Maven → Update Project
  • Check your main application class location
    Ensure your class with @SpringBootApplication is in the root package (like com.kkesley). Spring Boot automatically scans components in this package and its subfolders. If your main class is nested deeper (e.g., com.kkesley.springtest.controller), it won't pick up auto-configuration classes, leading to missing classes.

  • Inspect for dependency conflicts
    Even with starter dependencies, conflicting versions can sneak in. Run this command to generate a dependency tree:

    mvn dependency:tree
    

    Look for any dependencies with versions that don't match the Spring Boot parent's 2.0.0.RELEASE. If you find conflicts, explicitly set the correct version in your pom's <properties> section.

If none of these steps resolve the issue, share the full stack trace of the ClassNotFoundException—that will help pinpoint exactly which class is missing!

内容的提问来源于stack exchange,提问作者kkesley

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.21 03:42:22