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

Spring Boot应用启动后始终显示白标错误页问题排查

Troubleshooting: Whitelabel Error Page When Accessing /clients in Spring Boot Multi-Module App

Hey there, let's walk through why you're seeing that Whitelabel Error Page when hitting /clients and how to fix it. First, let's recap your setup to make sure we're on the same page.

Your Setup Overview

You've got a two-module Spring app:

  • core: Handles entities, repositories, and services (works fine in a standalone console project)
  • web: Houses the REST controller and main application entry point

Module Structures

Core Module

|-- core
    |-- model
        |-- client
            |-- Client.java
    |-- repositories
        |-- client
            |-- IClientRepository.java
    |-- services
        |-- client
            |-- IClientService.java
            |-- ClientServiceImpl.java

Web Module

|-- web
    |-- rest
        |-- client
            |-- ClientController.java
    |-- main
        |-- Application.java

Key Code Snippets

Client.java

package model.client; // Note: Your original code had `package model;` which doesn't match the folder structure
import javax.persistence.*;

@Entity
@Table(name="clients")
public class Client {
    @Id
    @GeneratedValue(strategy=GenerationType.IDENTITY)
    @Column(name="ID")
    private Integer id;
    @Column(name="NAME")
    private String name;
    @Column(name="EMAIL")
    private String email;
    @Column(name="PHONE")
    private String phone;

    public Client () { }

    public Client (String name, String email, String phone) {
        this.email = email;
        this.name = name;
        this.phone = phone;
    }

    @Override
    public String toString () {
        return "[" + id + "] " + name + " (" + email + ", " + phone + ")";
    }

    // Getters & Setters
    public Integer getId() { return id; }
    public String getName() { return name; }
    public void setName(String name) { this.name = name; }
    public String getEmail() { return email; }
    public void setEmail(String email) { this.email = email; }
    public String getPhone() { return phone; }
    public void setPhone(String phone) { this.phone = phone; }
}

IClientRepository.java

package repositories.client;
import org.springframework.data.repository.CrudRepository;
import org.springframework.stereotype.Repository;
import model.client.Client;
import java.util.List;
import java.util.Optional;

@Repository
public interface IClientRepository extends CrudRepository<Client, Integer> {
    List<Client> findAll ();
    Optional<Client> findById (Integer id);
    Client save(Client client);
    void deleteById (Integer ID);
}

ClientServiceImpl.java

package services.client;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import model.client.Client;
import repositories.client.IClientRepository;
import java.util.List;
import java.util.Optional;

@Service
public class ClientServiceImpl implements IClientService{
    @Autowired
    private IClientRepository repository;

    @Override
    public List<Client> findAll() {
        return repository.findAll();
    }

    @Override
    public Optional<Client> findById(Integer id) {
        return repository.findById(id);
    }

    @Override
    public void deleteById(Integer id) {
        repository.deleteById(id);
    }

    @Override
    public Client save(Client client) {
        return repository.save(client);
    }
}

ClientController.java

package rest.client;
import model.client.Client;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import services.client.IClientService;
import java.util.List;

@RestController
public class ClientController {
    @Autowired
    private IClientService clientService;

    @RequestMapping("/clients")
    public List<Client> getAllClients() {
        return clientService.findAll();
    }
}

Application.java

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.domain.EntityScan;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;

@SpringBootApplication(scanBasePackages = {"rest"})
@ComponentScan({"services"})
@EntityScan("model")
@EnableJpaRepositories("repositories")
public class Application {
    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }
}

application.properties (both modules)

spring.jpa.hibernate.ddl-auto=none
spring.datasource.url=jdbc:mysql://localhost:33

Top Issues to Fix & Solutions

1. Incomplete Database Configuration

Your spring.datasource.url is cut off—it's missing the full port (MySQL default is 3306), database name, plus you haven't set a username/password. This will break the database connection entirely.

Fix: Update your application.properties with a complete database config:

spring.datasource.url=jdbc:mysql://localhost:3306/your_db_name?useSSL=false&serverTimezone=UTC
spring.datasource.username=root # Default XAMPP MySQL username
spring.datasource.password=your_password # Leave empty if you didn't set one in XAMPP
spring.jpa.hibernate.ddl-auto=none
spring.jpa.show-sql=true # Optional: Helps debug SQL queries

Also, make sure your XAMPP MySQL service is running, and the database your_db_name exists (create it via phpMyAdmin if needed).

2. Package Path Mismatches & Component Scanning

  • Entity Class: Your Client.java is in the model/client folder, but the package declaration was package model;—it should be package model.client;. If this is wrong, @EntityScan("model") might not find your entity.
  • Component Scanning: Your @SpringBootApplication only scans rest, and @ComponentScan({"services"}) covers services, but double-check that all packages (like model.client, repositories.client) are being picked up correctly.

Fix:

  • Correct all package declarations to match your folder structure, and update imports in other classes (e.g., import model.client.Client; instead of import model.Client;).
  • Simplify your scan configs to avoid gaps. For example, move your Application.java to a root package like com.yourcompany, then all other modules' packages (e.g., com.yourcompany.model, com.yourcompany.services) will be automatically scanned. If you can't do that, update your annotations:
@SpringBootApplication(scanBasePackages = {"rest", "services", "model", "repositories"})
@EntityScan("model.client")
@EnableJpaRepositories("repositories.client")

3. Missing Module Dependency

If your web module doesn't depend on the core module, it can't access the Client entity, IClientService, or repository classes. This would cause injection failures or class not found errors.

Fix: Add the core module as a dependency in your web module's build file:

  • Maven (pom.xml):
<dependency>
    <groupId>your.group.id</groupId>
    <artifactId>core</artifactId>
    <version>1.0-SNAPSHOT</version>
</dependency>
  • Gradle (build.gradle):
implementation project(':core')

4. Controller Injection Issues

If IClientService isn't being injected properly, you'll get a NullPointerException when hitting /clients, which triggers the Whitelabel page.

Fix:

  • Switch to constructor injection (more reliable than field injection with @Autowired):
@RestController
public class ClientController {
    private final IClientService clientService;

    // Constructor injection (no @Autowired needed in Spring 4.3+)
    public ClientController(IClientService clientService) {
        this.clientService = clientService;
    }

    @RequestMapping("/clients")
    public List<Client> getAllClients() {
        return clientService.findAll();
    }
}
  • Check your console logs for errors like No qualifying bean of type 'services.client.IClientService' available—if you see this, go back to component scanning fixes.

Debugging Tips

  1. Check Startup Logs: Look for ERROR or WARN messages—they'll tell you exactly what's broken (e.g., database connection failed, bean not found).
  2. Enable Debug Logs: Add these lines to application.properties to see detailed Spring activity:
logging.level.org.springframework=DEBUG
logging.level.org.hibernate=DEBUG
  1. Test Core Module Isolation: Re-run your standalone core module test to confirm the repository/service still works—this rules out core module issues.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.29 09:00:00