使用Spring Boot和Thymeleaf时如何调试404错误?

矮鸭

这是Controller类:

    package me.ankit.zooplus;

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

    @Controller
    public class HomeController {   
        @RequestMapping("/home")
        public String home() {

        return "home";
    }
}

这是我的应用程序类

package me.ankit.zooplus;

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

@SpringBootApplication
public class ZooplusApplication  {

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

我的文件夹结构如下:文件结构

我来自maven [从控制台复制并粘贴几行]:

INFO 7484 --- [lication.main()] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/home]}" onto public java.lang.String me.ankit.zooplus.HomeController.home()
INFO 7484 --- [lication.main()] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 8080 (http) with context path ''
INFO 7484 --- [lication.main()] me.ankit.zooplus.ZooplusApplication      : Started ZooplusApplication in 10.554 seconds (JVM running for 16.948)

[INFO] BUILD SUCCESS

最后是我的pom.xml

<?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>

<groupId>me.ankit</groupId>
<artifactId>zooplus</artifactId>
<version>0.0.1-SNAPSHOT</version>

<name>zooplus</name>
<description>zooplus: Currency Converter</description>

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.0.1.RELEASE</version>
    <relativePath /> <!-- lookup parent from repository -->
</parent>

<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-data-jpa</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-security</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-thymeleaf</artifactId>
    </dependency>

    <!-- hot swapping, disable cache for template, enable live reload -->       
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-devtools</artifactId>
        <optional>true</optional>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>

    <dependency>
        <groupId>org.hsqldb</groupId>
        <artifactId>hsqldb</artifactId>
        <scope>runtime</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework.security</groupId>
        <artifactId>spring-security-test</artifactId>
        <scope>test</scope>
    </dependency>
</dependencies>

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

可能出了什么问题?还有一个地方/视图/日志,我以后可以去检查哪里出了问题?

路易斯·阿卜杜勒·拉赫姆(Luay Abdulraheem)

我已经克隆了您的项目并运行了它。我有几点注意事项:

  1. 在中pom.xml,您已经添加了spring-boot-starter-security依赖项,一旦您访问Web应用程序,它将创建一个默认的登录页面。如果在此阶段不需要安全性,请从您pom.xml的应用程序中删除所有安全性依赖项,或者您必须为应用程序提供安全性配置。
  2. 访问应用程序时,请确保将“ home”添加到URL:http:// localhost:8080 / home,因为这已映射到您的控制器。如果你想在默认情况下添加到您的应用程序添加以下到application.propertiesserver.servlet.contextPath=/zooplus:,那么你可以通过URL访问它的http://本地主机:8080 / zooplus /家

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

Spring Boot和Thymeleaf-到另一个站点的“ a href”进入404错误

Spring Boot和Thymeleaf-删除严格的HTML错误检查

使用Spring Boot时如何使用SpringTemplateEngine

Spring Boot和Thymeleaf在字段错误上返回400错误

如何在不使用Thymeleaf或其他模板引擎的情况下处理Spring Boot中的Whitelabel 404错误

如何使用Spring Boot,JPA和Thymeleaf设置搜索栏

尝试使用Angular 6和Spring Boot登录时出现404错误

在Thymeleaf和Spring Boot的嵌套类中使用枚举

如何在Thymeleaf和Spring Boot中使用自定义标签库?

使用Spring Boot和Thymeleaf进行分页

尝试使用Thymeleaf加载HTML文件时的Spring Boot 404

使用Spring Boot和Thymeleaf创建文件下载链接

使用@PathVariable时的Spring Boot报告404错误

Spring Boot和Thymeleaf Neko HTML错误

使用Spring Boot和Thymeleaf发送HTML电子邮件

使用Spring Boot和Thymeleaf加载静态资源

使用Spring Boot时主控制器上的404错误

如何在Spring Boot应用程序中使用Thymeleaf加载HashMap和ModelandView对象值?

如何使用Thymeleaf和Spring Boot将对象集合从UI绑定到后端

Thymeleaf 3和Spring Boot 2.1的模板解析错误

在使用Spring Boot和Spring Data Jpa时如何使用Rest Service

使用Spring Boot和Thymeleaf上传多个文件

使用@Valid和Thymeleaf验证spring-boot中的输入

Spring和Thymeleaf,Spring如何知道如何使用模板?

如何使用Thymeleaf和Spring Boot从下拉列表中提取所选值

Spring Boot,使用Thymeleaf发行

使用@PathVariable 时如何使用spring boot 和thymeleaf 在首页导入静态资源

模板解析时出错。Spring boot 和 Thymeleaf

如何使用 Spring Boot 和 Thymeleaf 在表单中提交隐藏字符串?