java - 为什么在运行简单的Spring Boot Gradle项目时获得404状态?

标签 java spring spring-boot gradle

我是 Spring 靴的新手。我用gradle build创建了一个简单的spring-boot版本2.2.6项目。我创建了一个欢迎jsp只是为了打印标题。当我使用http://localhost:8081/welcome.html在服务器上运行它时,我得到404状态,以下是我的build.gradle,应用程序类, Controller 类和application.properties文件:

//build.gradle    
plugins {
    id 'org.springframework.boot' version '2.2.6.RELEASE'
    id 'io.spring.dependency-management' version '1.0.9.RELEASE'
    id 'java'
    }

    group = 'com.banuprojects'
    version = '0.0.1-SNAPSHOT'
    sourceCompatibility = '11'

    repositories {
        mavenCentral()
    }

    dependencies {
        implementation 'org.springframework.boot:spring-boot-starter-web'
        implementation 'org.apache.tomcat.embed:tomcat-embed-jasper'
        implementation 'javax.servlet:jstl'
        testImplementation('org.springframework.boot:spring-boot-starter-test') {
            exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
        }
    }

    test {
        useJUnitPlatform()
    }

//application class
        package com.banuprojects.lmsdemo;

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

    @SpringBootApplication
    public class LmsdemoApplication {

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

    }

    //controller class
        package com.banuprojects.lmsdemo;

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

        @Controller
        public class TestController {

            @RequestMapping("/welcome.html")
            public ModelAndView firstPage() {
                return new ModelAndView("welcome");
            }

        }

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

我不确定我的实现哪里有错。任何帮助将不胜感激。
谢谢

最佳答案

正如讨论过的评论。查看应用程序属性文件后,发现URL中传递了错误的端口。
找不到其他技术错误。

关于java - 为什么在运行简单的Spring Boot Gradle项目时获得404状态?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61256998/

相关文章:

java - 如何使用 Spring Boot 在后端跟踪文件下载进度?

java - Vertx客户端Http : Connection closed when perform rest call

java - JTable:看不到列名

java - 不同端口上的多个 Spring Boot 实例 - 登录/注销问题

java - 我可以获取 map 的一部分并测试我使用的 key 吗?

java - 带有 Spring Autowiring 元素的 Junit Suites

java - Spring 3.1 @Scheduled 随机触发

java - spring默认@Transactional和默认丢失更新

spring - Kafka Connect 与 Spring 框架

java - 验证 Thymeleaf 中的输入