【问题标题】:How to solve the error message: "Whitelabel Error Page" for Spring Boot如何解决错误信息:Spring Boot 的“Whitelabel Error Page”
【发布时间】:2020-07-30 18:07:02
【问题描述】:

我是 Spring Boot 新手,我正在尝试使用 Spring MVC + Spring Boot2 + JSP + Spring Data + DB Oracle 制作一个项目。 当我运行简单的应用程序时,我的第一条消息错误是:

Whitelabel Error Page
This application has no explicit mapping for /error, so you are seeing this as a fallback.

Fri Apr 17 10:20:05 CEST 2020
There was an unexpected error (type=Not Found, status=404).
No message available

我发现了很多关于这个错误的文档,我测试了不同的解决方案,但没有什么能解决我的问题。在我做的测试下面: 1)我确保我的主类在根包中,我把其他包放在子级别; 2)我在主类中这样使用de @ComponentScan @ComponentScan({"com.dashboard.demo.controller"}); 3)在application.properties中我使用了这个命令server.servlet.context-path=/oee

这是我的代码:

Application.properties

spring.mvc.view.prefix: /WEB-INF/jsp/
spring.mvc.view.suffix: .jsp

server.servlet.context-path=/oee

## Spring DATASOURCE (DataSourceAutoConfiguration & DataSourceProperties)
spring.datasource.url= jdbc:oracle:thin:@serverIP:Port:DB11G
spring.datasource.username= Server name
spring.datasource.password= password

# The SQL dialect makes Hibernate generate better SQL for the chosen database
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.Oracle10gDialect


# Hibernate ddl auto (create, create-drop, validate, update)
spring.jpa.hibernate.ddl-auto = create-drop
spring.jpa.show-sql= true

server.port = 8091

主要

package com.dashboard.demo;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
import org.springframework.context.annotation.ComponentScan;

@SpringBootApplication
public class OeeApplication extends SpringBootServletInitializer{

    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
        return application.sources(OeeApplication.class);
    }

    public static void main(String[] args) {
        SpringApplication.run(OeeApplication.class, args);
    }

}

OEE控制器

package com.dashboard.demo.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.dashboard.demo.entities.OEE;
import com.dashboard.demo.service.OEEService;


@Controller
public class OEEController {

    @Autowired
    private OEEService oeeService;


    @RequestMapping(value = "/oee}", method = RequestMethod.GET)
    public String listAll(Model model) 
    {
        List<OEE> oee = oeeService.SelDevice();

        model.addAttribute("OEE",oee);

        return "oee";
    }

}

OEEServiceImpl

package com.dashboard.demo.service;

import java.util.List;

import javax.transaction.Transactional;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.dashboard.demo.entities.OEE;
import com.dashboard.demo.repository.OEERepository;

@Service
@Transactional
public class OEEServiceImpl implements OEEService{

    @Autowired
    private OEERepository oeeRepository;

    @Override
    public List<OEE> SelDevice() 
    {
        return oeeRepository.findAll();
    }

}

OERepository

package com.dashboard.demo.repository;

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

import com.dashboard.demo.entities.OEE;
import com.dashboard.demo.entities.OEEid;

@Repository
public interface OEERepository extends JpaRepository<OEE, OEEid>
{


}

我正在管理一个复合键,我为复合键创建了一个类,并为管理实体创建了另一个类。我在这个包中发现了错误。

package com.dashboard.demo.entities;

import java.io.Serializable;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Embeddable;

import org.springframework.format.annotation.DateTimeFormat;

import lombok.Data;

@Data
@Embeddable
public class OEEid implements Serializable{

    /**
     * 
     */
    private static final long serialVersionUID = 4512114330774744082L;

    @DateTimeFormat(pattern = "dd-MM-yy HH:mm:ss")
    @Column(name = "MSO_GIORNO_LAV")
    private Date date;

    @Column(name = "MSO_MACCHINA")
    private String device;

    public OEEid(Date date, String device) {
        super();
        this.date = date;
        this.device = device;
    }


}

package com.dashboard.demo.entities;

import java.io.Serializable;


import javax.persistence.Basic;
import javax.persistence.Column;

import javax.persistence.EmbeddedId;
import javax.persistence.Entity;

import javax.persistence.IdClass;
import javax.persistence.Table;

import lombok.Data;

@Entity
@Table(name = "MES_OEE")
@Data
public class OEE implements Serializable
{

    /**
     * 
     */
    private static final long serialVersionUID = -7738922358421962399L;

    @EmbeddedId
    private OEEid oeeID;

    @Basic(optional = false)
    @Column(name = "MSO_QUANTITA")
    private int amount;

    @Basic(optional = false)
    @Column(name = "MSO_OEE")
    private float oee;
}

oee.jsp

<!DOCTYPE html>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<html lang="en">
<head>

<link rel="stylesheet" type="text/css"
 href="webjars/bootstrap/3.3.7/css/bootstrap.min.css" />
<c:url value="/css/main.css" var="jstlCss" />
<link href="${jstlCss}" rel="stylesheet" />

</head>
<body>
 <div class="container">
  <header>
   <h1>Spring MVC + JSP + JPA + Spring Boot 2</h1>
  </header>
  <div class="starter-template">
   <h1>Users List</h1>
   <table
    class="table table-striped table-hover table-condensed table-bordered">
    <tr>
     <th>Date</th>
     <th>Device</th>
     <th>Amount</th>
     <th>OEE</th>
    </tr>
    <c:forEach items="${OEE}" var="oee">
     <tr>
        <td>${oee.oeeID.date}</td>
        <td>${oee.oeeID.device}</td>
        <td>${oee.amount}</td>
        <td>${oee.oee}</td>
     </tr>
    </c:forEach>
   </table>
  </div>

 </div>

 <script type="text/javascript"
  src="webjars/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</body>

</html>

谁能给我任何解决此错误消息的建议? 谢谢

这是我的项目目录

【问题讨论】:

  • 我对jsp不熟悉,但是这个错误说明你试图访问一个不存在的端点。你确定你的客户打电话给localhost:8091/oee
  • 我这么认为...我制作了另一个没有弹簧数据的应用程序。我遇到了同样的错误,但我更改了我的包的级别,现在它可以工作了。
  • 只有一个不同的是8080端口

标签: spring-boot spring-mvc jsp oracle11g spring-data-jpa


【解决方案1】:

您能否尝试从属性文件中删除此server.servlet.context-path=/oee 并尝试使用localhost:8080/oeee

【讨论】:

  • 是的,oee.jsp 在 WEB-INF/jsp 中
  • 你能附上你的项目目录屏幕吗?
  • 请将您的OeeApplication.class 保留在此包com.dashboard 下,然后重试。
  • 我已经完成了这个证明,但它不起作用.. 感谢您的帮助。任何其他建议。我在上面附上了我的项目目录图片
猜你喜欢
  • 2019-05-03
  • 2020-01-26
  • 2019-09-10
  • 2021-12-07
  • 1970-01-01
  • 2019-04-04
  • 2018-07-22
  • 1970-01-01
  • 2020-04-15
相关资源
最近更新 更多