我是spring boot的新手,我正在尝试用Spring MVC + Spring + Boot2 + 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 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 = 8091Main
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);
}
}OEEController
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();
}
}OEERepository
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>有人能给我一些建议来解决这个错误信息吗?谢谢
这是我的项目目录

发布于 2020-04-17 22:54:30
您是否可以尝试从属性文件中删除此server.servlet.context-path=/oee并使用localhost:8080/oeee进行尝试
https://stackoverflow.com/questions/61268238
复制相似问题