当前位置: 首页 > 知识库问答 >
问题:

如何解决:**Whitelabel错误页。**我得到了**这个应用程序没有 /error的显式映射,所以你把它看作是一个退路。**

公羊涛
2023-03-14

当我点击URL:http://localhost:8080/login我得到Whitelabel错误页这个应用程序没有明确的映射 /error,所以你看到这是一个后备。星期三4月21 11:24:00IST 2021有一个意外的错误(type=未找到,状态=404)。我该怎么解决这个问题?

主类

package com.springboot.controller;

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


@EntityScan(basePackages="com.springboot.controller.model")
@EnableJpaRepositories(basePackages="com.springboot.controller.Repository")
@SpringBootApplication(scanBasePackages="com.springboot.controller")
public class RestApi {
     
    public static void main(String[] args) {
        SpringApplication.run(RestApi.class, args);

    }

}

登录控制器

package com.springboot.controller.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;



@RestController
public class LoginController {
    
    @RequestMapping("/login")
    @ResponseBody
    public ModelAndView checkMVC()
    {
        ModelAndView mav= new ModelAndView("LoginForm");
                
        return mav;
    }
}

UserRepo.java

package com.springboot.controller.Repository;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Service;

import com.springboot.controller.model.User;

@Service("UserRepo")
public interface UserRepo extends JpaRepository<User,Integer> {

    String findByEmail(String email);

}

Pom.xml

<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.4.3</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.springboot.controller</groupId>
    <artifactId>cunsultustoday-web-services</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>cunsultustoday-web-services</name>
    <description>Demo project for Spring Boot</description>
    <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-data-jpa</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
           <groupId>org.apache.tomcat.embed</groupId>
           <artifactId>tomcat-embed-jasper</artifactId>
           <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>commons-configuration</groupId>
            <artifactId>commons-configuration</artifactId>
            <version>1.9</version>
        </dependency>
        <dependency>
           <groupId>javax.servlet</groupId>
           <artifactId>jstl</artifactId>
           <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-data-redis</artifactId>
                <exclusions>
                    <exclusion>
                        <groupId>io.lettuce</groupId>
                        <artifactId>lettuce-core</artifactId>
                    </exclusion>
                </exclusions>    
            </dependency>
            <dependency>
                <groupId>redis.clients</groupId>
                <artifactId>jedis</artifactId>
            </dependency>
            <dependency>
              <groupId>org.springframework</groupId>
              <artifactId>spring-webmvc</artifactId>
              </dependency>
             
    </dependencies>

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

</project>

日志

 :: Spring Boot ::                (v2.4.3)

2021-04-21 11:23:50.952  INFO 13080 --- [           main] com.springboot.controller.RestApi        : Starting RestApi using Java 15.0.2 on Dell with PID 13080 (C:\Users\Ins\Desktop\Project\CunsultUsToday\CunsultUsToday\target\classes started by Ins in C:\Users\Ins\Desktop\Project\CunsultUsToday\CunsultUsToday)
2021-04-21 11:23:50.955  INFO 13080 --- [           main] com.springboot.controller.RestApi        : No active profile set, falling back to default profiles: default
2021-04-21 11:23:51.546  INFO 13080 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : Multiple Spring Data modules found, entering strict repository configuration mode!
2021-04-21 11:23:51.546  INFO 13080 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JPA repositories in DEFAULT mode.
2021-04-21 11:23:51.604  INFO 13080 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 48 ms. Found 3 JPA repository interfaces.
2021-04-21 11:23:51.795  INFO 13080 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : Multiple Spring Data modules found, entering strict repository configuration mode!
2021-04-21 11:23:51.796  INFO 13080 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data Redis repositories in DEFAULT mode.
2021-04-21 11:23:51.816  INFO 13080 --- [           main] .RepositoryConfigurationExtensionSupport : Spring Data Redis - Could not safely identify store assignment for repository candidate interface com.springboot.controller.Repository.ClgRegRepo. If you want this repository to be a Redis repository, consider annotating your entities with one of these annotations: org.springframework.data.redis.core.RedisHash (preferred), or consider extending one of the following types with your repository: org.springframework.data.keyvalue.repository.KeyValueRepository.
2021-04-21 11:23:51.817  INFO 13080 --- [           main] .RepositoryConfigurationExtensionSupport : Spring Data Redis - Could not safely identify store assignment for repository candidate interface com.springboot.controller.Repository.StudentRegRepo. If you want this repository to be a Redis repository, consider annotating your entities with one of these annotations: org.springframework.data.redis.core.RedisHash (preferred), or consider extending one of the following types with your repository: org.springframework.data.keyvalue.repository.KeyValueRepository.
2021-04-21 11:23:51.818  INFO 13080 --- [           main] .RepositoryConfigurationExtensionSupport : Spring Data Redis - Could not safely identify store assignment for repository candidate interface com.springboot.controller.Repository.UserRepo. If you want this repository to be a Redis repository, consider annotating your entities with one of these annotations: org.springframework.data.redis.core.RedisHash (preferred), or consider extending one of the following types with your repository: org.springframework.data.keyvalue.repository.KeyValueRepository.
2021-04-21 11:23:51.818  INFO 13080 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 11 ms. Found 0 Redis repository interfaces.
2021-04-21 11:23:52.325  INFO 13080 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8080 (http)
2021-04-21 11:23:52.342  INFO 13080 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2021-04-21 11:23:52.343  INFO 13080 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet engine: [Apache Tomcat/9.0.43]
2021-04-21 11:23:52.698  INFO 13080 --- [           main] org.apache.jasper.servlet.TldScanner     : At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
2021-04-21 11:23:52.709  INFO 13080 --- [           main] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2021-04-21 11:23:52.709  INFO 13080 --- [           main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 1688 ms
2021-04-21 11:23:52.881  INFO 13080 --- [           main] o.hibernate.jpa.internal.util.LogHelper  : HHH000204: Processing PersistenceUnitInfo [name: default]
2021-04-21 11:23:52.940  INFO 13080 --- [           main] org.hibernate.Version                    : HHH000412: Hibernate ORM core version 5.4.28.Final
2021-04-21 11:23:53.087  INFO 13080 --- [           main] o.hibernate.annotations.common.Version   : HCANN000001: Hibernate Commons Annotations {5.1.2.Final}
2021-04-21 11:23:53.206  INFO 13080 --- [           main] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Starting...
2021-04-21 11:23:53.377  INFO 13080 --- [           main] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Start completed.
2021-04-21 11:23:53.396  INFO 13080 --- [           main] org.hibernate.dialect.Dialect            : HHH000400: Using dialect: org.hibernate.dialect.MySQL5Dialect
2021-04-21 11:23:54.035  INFO 13080 --- [           main] o.h.e.t.j.p.i.JtaPlatformInitiator       : HHH000490: Using JtaPlatform implementation: [org.hibernate.engine.transaction.jta.platform.internal.NoJtaPlatform]
2021-04-21 11:23:54.044  INFO 13080 --- [           main] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'
2021-04-21 11:23:54.556  WARN 13080 --- [           main] JpaBaseConfiguration$JpaWebConfiguration : spring.jpa.open-in-view is enabled by default. Therefore, database queries may be performed during view rendering. Explicitly configure spring.jpa.open-in-view to disable this warning
2021-04-21 11:23:54.651  INFO 13080 --- [           main] o.s.s.concurrent.ThreadPoolTaskExecutor  : Initializing ExecutorService 'applicationTaskExecutor'
2021-04-21 11:23:54.990  INFO 13080 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 8080 (http) with context path ''
2021-04-21 11:23:54.998  INFO 13080 --- [           main] com.springboot.controller.RestApi        : Started RestApi in 4.441 seconds (JVM running for 5.327)
2021-04-21 11:24:00.446  INFO 13080 --- [nio-8080-exec-1] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring DispatcherServlet 'dispatcherServlet'
2021-04-21 11:24:00.446  INFO 13080 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet        : Initializing Servlet 'dispatcherServlet'
2021-04-21 11:24:00.447  INFO 13080 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet        : Completed initialization in 0 ms

日志中没有显示错误,但我仍然得到这个白色标签错误页面

请帮忙。

共有1个答案

松景铄
2023-03-14

您没有指定方法和值。请参阅下面的屏幕截图。https://www.baeldung.com/spring-requestmapping例如:

@RequestMapping(value = "/login", method = RequestMethod.POST)
@ResponseBody
    public ModelAndView checkMVC()
    {
        ModelAndView mav= new ModelAndView("LoginForm");
                
        return mav;
    }
 类似资料:
  • 我已经配置了一个spring启动应用程序,但是在启动应用程序时,我得到了如下映射错误 ...我已经通过了下面的链接,并更新了我的控制器,使其成为包含主类的根包的一部分。此应用程序没有 /error的显式映射 我使用下面提到的配置/代码为我的应用程序: build.gradle 售票员。JAVA 应用性质 jsp路径

  • 在此处输入图像描述这是我的控制器,我正在使用端口localhost:8080访问它返回白色标签错误。原因可能是什么?

  • 问题内容: 应用程序可以运行,但是出现错误: 我该如何解决? 问题答案: 当我们创建一个Spring Boot应用程序时,我们用注解对其进行注解。该批注“包装”了许多其他必需的批注,以使应用程序正常工作。一种这样的注释是注释。该注释告诉Spring寻找Spring组件并配置要运行的应用程序。 你的应用程序类必须位于程序包层次结构的顶部,以便Spring可以扫描子程序包并找到其他必需的组件。 下面的

  • 猜猜我哪里错了。。? 错误: 正在创建名为“subjectController”的bean:通过字段“subjectService”表示未满足的依赖关系;嵌套的异常是org。springframework。豆。工厂未满足的依赖项异常:创建名为“subjectServiceImpl”的bean时出错:通过字段“subjectRepository”表示未满足的依赖项;嵌套的异常是org。springf

  • 我试图用Selenium×Node.js实现自动化测试,但它在调查阶段被阻止了... Mac OS10.12.6 节点8.11.1 Selenium Server 3.12.0 Selenium WebDriver 4.0.0 ChromeDriver 2.38 3.安装selenium-server 通过自制安装 4.安装ChromeDriver $selenium-server-port 44

  • 我正在使用SpringBoot刷新我的Spring技能。我已经将库更新到最新版本。当我将浏览器指向应用程序时,会出现以下错误: 这是我的控制器: } tomcat日志看起来像这样: 如有任何建议,将不胜感激。 罗斯