【问题标题】:Spring-Boot java.lang.NullPointerException: null at javax.el.CompositeELResolver.add(CompositeELResolver...<c:forEach, ValidationSpring-Boot java.lang.NullPointerException: null at javax.el.CompositeELResolver.add(CompositeELResolver...<c:forEach, Validation
【发布时间】:2021-03-24 20:39:52
【问题描述】:

我正在尝试构建一个基本的 Spring-Boot 应用程序。我在控制器中使用 javax.validation。它将 EL 标记识别为 ,但是当视图具有

这是jsp:

<%@ page contentType="text/html;charset=UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<%--@elvariable id="employees" type="com.dev.spring.model.EmployeeVO"--%>

<html>
<head>
    <title>Spring MVC Hello World</title>
</head>
 
<body>
    <h2>All Employees in System</h2>
 
    <table border="1">
        <tr>
            <th>Employee Id</th>
            <th>First Name</th>
            <th>Last Name</th>
        </tr>
        <c:forEach items="${employees}" var="employee">
            <tr>
                <td>${employee.id}</td>
                <td>${employee.firstName}</td>
                <td>${employee.lastName}</td>
            </tr>
        </c:forEach>
    </table>
 
</body>
</html>

【问题讨论】:

  • 在我看来,您无法实例化一个名为 employees 的集合。你预计会发生什么?
  • 我忘了说“manager.getAllEmployees”返回一个非空集合
  • 我在最后一个选项中添加了

标签: java spring spring-boot


【解决方案1】:

我发现使应用程序工作的唯一方法。就是把spring-boot配置成spring-mvc应用。

我在 POM 中进行了更改:(已添加)

 <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
            <scope>provided</scope>
         
<!--The rest of dependencies passed from provided to compile-->

在 SpringApplication 中更改了一些 TomcatConfigurationBean(删除)

在 Tomcat 8.1 中部署,所有

【讨论】:

    猜你喜欢
    • 2020-12-25
    • 2016-08-02
    • 2020-01-10
    • 2021-05-31
    • 2017-06-21
    • 2015-02-10
    • 1970-01-01
    • 2020-04-27
    • 2018-05-29
    相关资源
    最近更新 更多