Spring Boot: Whitelabel Error Page solution

created at 11-10-2021 views: 22

This article is suitable for newbies who are new to me like me. If there is something wrong, please correct and criticize

I need to start building a new project due to my work. Spring boot is simple to build, especially suitable for people like me.

So I built and deployed the springboot project here, and deployed springboot according to the reference book

@SpringBootApplication
@RestController
public class Platform1Application {

    public static void main(String[] args) {

        SpringApplication.run(Platform1Application.class, args);
    }
    @RequestMapping("/hello")
    public String hello(){
        return "hello world";
    }
}

Start the visit as follows

hello world

So I started to test the mysql database, and then I found that I couldn’t access it. The following figure shows the structure of my package.

structure

package com.comservice.platform.controller;


import com.comservice.platform.javaBean.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

/**
 * @ClassName: com.comservice.platform.controller.UserController
 * @description: User control processing
 * @author: He bin
 * @create: 2021/11/3、9:33
 * @version: V1.0
 */
@RestController
public class UserController {
   @Autowired
   JdbcTemplate jdbcTemplate;
    @RequestMapping("/list")
    public List mySqlTest(){
       String sql="select * from user";
        List<User> users=jdbcTemplate.query(sql, new RowMapper<User>() {
            @Override
            public User mapRow(ResultSet rs, int rowNum) throws SQLException {
                User user=new User();
                user.setId(rs.getInt("id"));
                user.setName(rs.getString("name"));
                user.setPassword(rs.getString("password"));
               return  user;
            }
        });
        System.out.println("search successful"+users);
        return  users;

    }
}

Then visit the page and find that it is Whitelabel Error Page

Whitelabel Error Page

After checking various information, I found that the controller package was not scanned, and it crashed.

Solution

Annotate the startup class

@ComponentScan(basePackages = {"com.comservice.platform.controller"})

As shown below

Annotate the startup class

created at:11-10-2021
edited at: 11-10-2021: