在使用带有JSP页面的Spring MVC时获得错误500

问题描述 投票:0回答:1

我正在尝试使用SpringMVC使用JSP和SpringBoot创建UI。在所有配置正确完成后,我仍然收到错误 - “java.lang.ClassNotFoundException:org.eclipse.jdt.internal.compiler.env.INameEnvironment”我已经尝试了很多来解决它但仍然无法正常工作。如果有人可以帮助我先感谢您。

我的文件结构enter image description here

我的控制器

    package com.capgemini.PACE.PACE;

    import org.springframework.stereotype.Controller;
    import org.springframework.web.bind.annotation.RequestMapping;

    @Controller
    public class HelloController {

@RequestMapping("/")
public String Hello()
{
    return "/Hello";
}
    }

我的Spring Boot页面

    package com.capgemini.PACE.PACE;

    import org.springframework.boot.SpringApplication;
    import org.springframework.boot.autoconfigure.SpringBootApplication;

    @SpringBootApplication
    public class PaceApplication {

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

    }

我们会帮忙的

    <?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 http://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.1.3.RELEASE</version>
    <relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.capgemini.PACE</groupId>
<artifactId>PACE</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>PACE</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-web</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.apache.tomcat.embed</groupId>
        <artifactId>tomcat-embed-jasper</artifactId>
    </dependency>
</dependencies>

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

我的JSP页面

    <%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="UTF-8">
    <title>Insert title here</title>
    </head>
    <body>
    <h1>HEllo!!</h1>

    </body>
    </html>

我的application.properties

    server.port=8082
    spring.mvc.view.prefix = /WEB-INF/views/
    spring.mvc.view.suffix = .jsp
    spring.mvc.static-path-pattern=/resources/**

我试过在pom.xml中添加这些依赖项仍然无法获得相同的错误

    <dependency>
        <groupId>javax.servlet.jsp.jstl</groupId>
        <artifactId>javax.servlet.jsp.jstl-api</artifactId>
        <version>1.2.1</version>
    </dependency>
    <dependency>
        <groupId>javax.servlet.jsp</groupId>
        <artifactId>jsp-api</artifactId>
        <version>2.1</version>

我收到错误 -

Whitelabel Error Page

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

Wed Apr 03 14:06:02 EDT 2019
There was an unexpected error (type=Internal Server Error, status=500).
org/eclipse/jdt/internal/compiler/env/INameEnvironment
spring spring-boot spring-mvc jsp tomcat
1个回答
0
投票
In my case it worked by adding this dependency in pom.xml file.
It is needed to compile jsp don't know why tomcat-embed-jasper version is not working
        <dependency>
            <groupId>org.eclipse.jdt.core.compiler</groupId>
            <artifactId>ecj</artifactId>
            <version>4.6.1</version>
            <scope>provided</scope>
        </dependency>
© www.soinside.com 2019 - 2024. All rights reserved.