java - 为什么我在运行一个简单的 Spring Boot gradle 项目时会得到 404 状态?
问题描述
我是弹簧靴的新手。我用 gradle build 创建了一个简单的 spring-boot 版本 2.2.6 项目。我创建了一个欢迎 jsp 只是为了打印一个标题。当我使用http://localhost:8081/welcome.html在我的服务器上运行它时,我得到 404 状态以下是我的 build.gradle、应用程序类、控制器类和 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 中传递了错误的端口。
未发现其他技术错误。
推荐阅读
- excel - 当我将另存为 CSV 时,它会将 true/false 更改为 TRUE/FALSE
- html - Thymeleaf + CSS:弹性方向在 Thymeleaf 中的工作方式不同?
- python-3.x - 如何在 python 代码中突出显示控制台输出?
- php - 使用 $wpdb->get_results 时如何对表数据进行排序
- objective-c - 是否有任何最新资源可以解释 MacOS 的 AuthenticationPlugin 开发?
- spotfire - 甘特图,活动持续时间
- java - 用于 Spring Boot Web 应用程序的 Maven 构建插件
- python - 使用 psycopg2 时如何使用多行 f 字符串
- python - 与 Maya scriptJob 命令一起使用的事件是什么,以便跟踪何时从渲染层添加或删除对象?
- python-3.x - 如何创建一个只接受字符串值的空列表