Spring Boot-Thymeleaf-新项目无法正常工作

如何解决Spring Boot-Thymeleaf-新项目无法正常工作

我需要帮助才能使用Spring Boot启动新项目。

我使用了spring工具套件4“ spring starter project”。

我正确地遵循了指南的所有步骤,但是一旦我运行localhost:8080,它告诉我无法访问该站点。 在问题部分,我有0个问题和警告。

我的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 https://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.3.4.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>it.progettoThymeleaf</groupId>
    <artifactId>progettoThymeleaf</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>MyNewProject</name>
    <description>Nuov progetto ThymeLeaf</description>

    <properties>
        <java.version>1.8</java.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-integration</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-thymeleaf</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <scope>runtime</scope>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
            <exclusions>
                <exclusion>
                    <groupId>org.junit.vintage</groupId>
                    <artifactId>junit-vintage-engine</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.springframework.integration</groupId>
            <artifactId>spring-integration-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

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

</project>

我的.log文件

!ENTRY org.eclipse.jdt.debug 2 0 2020-10-08 21:09:12.334
!MESSAGE Unable to find location of java.lang.Thread.setName() in debuggee JVM,for type java.lang.Thread

谢谢

新控制台输出

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__,| / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::        (v2.3.4.RELEASE)

2020-10-08 21:43:13.953  INFO 19656 --- [  restartedMain] i.p.start.MyNewProjectApplication        : Starting MyNewProjectApplication on griccipw10 with PID 19656 (C:\progetto Thymeleaf\Workspace\MyNewProject\target\classes started by gricci in C:\progetto Thymeleaf\Workspace\MyNewProject)
2020-10-08 21:43:13.960  INFO 19656 --- [  restartedMain] i.p.start.MyNewProjectApplication        : No active profile set,falling back to default profiles: default
2020-10-08 21:43:14.051  INFO 19656 --- [  restartedMain] .e.DevToolsPropertyDefaultsPostProcessor : Devtools property defaults active! Set 'spring.devtools.add-properties' to 'false' to disable
2020-10-08 21:43:14.051  INFO 19656 --- [  restartedMain] .e.DevToolsPropertyDefaultsPostProcessor : For additional web related logging consider setting the 'logging.level.web' property to 'DEBUG'
2020-10-08 21:43:15.087  INFO 19656 --- [  restartedMain] faultConfiguringbeanfactoryPostProcessor : No bean named 'errorChannel' has been explicitly defined. Therefore,a default PublishSubscribeChannel will be created.
2020-10-08 21:43:15.105  INFO 19656 --- [  restartedMain] faultConfiguringbeanfactoryPostProcessor : No bean named 'taskScheduler' has been explicitly defined. Therefore,a default ThreadPoolTaskScheduler will be created.
2020-10-08 21:43:15.110  INFO 19656 --- [  restartedMain] faultConfiguringbeanfactoryPostProcessor : No bean named 'integrationHeaderChannelRegistry' has been explicitly defined. Therefore,a default DefaultHeaderChannelRegistry will be created.
2020-10-08 21:43:15.199  INFO 19656 --- [  restartedMain] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.integration.config.IntegrationManagementConfiguration' of type [org.springframework.integration.config.IntegrationManagementConfiguration] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2020-10-08 21:43:15.212  INFO 19656 --- [  restartedMain] trationDelegate$BeanPostProcessorChecker : Bean 'integrationChannelResolver' of type [org.springframework.integration.support.channel.beanfactoryChannelResolver] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2020-10-08 21:43:15.215  INFO 19656 --- [  restartedMain] trationDelegate$BeanPostProcessorChecker : Bean 'integrationdisposableautocreatedBeans' of type [org.springframework.integration.config.annotation.disposables] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2020-10-08 21:43:15.615  INFO 19656 --- [  restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8080 (http)
2020-10-08 21:43:15.627  INFO 19656 --- [  restartedMain] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2020-10-08 21:43:15.627  INFO 19656 --- [  restartedMain] org.apache.catalina.core.StandardEngine  : Starting Servlet engine: [Apache Tomcat/9.0.38]
2020-10-08 21:43:15.949  INFO 19656 --- [  restartedMain] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2020-10-08 21:43:15.949  INFO 19656 --- [  restartedMain] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 1898 ms
2020-10-08 21:43:16.267  INFO 19656 --- [  restartedMain] o.s.s.concurrent.ThreadPoolTaskExecutor  : Initializing ExecutorService 'applicationTaskExecutor'
2020-10-08 21:43:16.283 DEBUG 19656 --- [  restartedMain] s.w.s.m.m.a.RequestMappingHandlerAdapter : ControllerAdvice beans: 0 @modelattribute,0 @InitBinder,1 RequestBodyAdvice,1 ResponseBodyAdvice
2020-10-08 21:43:16.365 DEBUG 19656 --- [  restartedMain] s.w.s.m.m.a.RequestMappingHandlerMapping : 2 mappings in 'requestMappingHandlerMapping'
2020-10-08 21:43:16.399 DEBUG 19656 --- [  restartedMain] o.s.w.s.handler.SimpleUrlHandlerMapping  : Patterns [/webjars/**,/**] in 'resourceHandlerMapping'
2020-10-08 21:43:16.408 DEBUG 19656 --- [  restartedMain] .m.m.a.ExceptionHandlerExceptionResolver : ControllerAdvice beans: 0 @ExceptionHandler,1 ResponseBodyAdvice
2020-10-08 21:43:16.601  INFO 19656 --- [  restartedMain] o.s.b.d.a.OptionalLiveReloadServer       : LiveReload server is running on port 35729
2020-10-08 21:43:16.751  INFO 19656 --- [  restartedMain] o.s.s.c.ThreadPoolTaskScheduler          : Initializing ExecutorService 'taskScheduler'
2020-10-08 21:43:16.851  INFO 19656 --- [  restartedMain] o.s.i.endpoint.EventDrivenConsumer       : Adding {logging-channel-adapter:_org.springframework.integration.errorLogger} as a subscriber to the 'errorChannel' channel
2020-10-08 21:43:16.852  INFO 19656 --- [  restartedMain] o.s.i.channel.PublishSubscribeChannel    : Channel 'application.errorChannel' has 1 subscriber(s).
2020-10-08 21:43:16.852  INFO 19656 --- [  restartedMain] o.s.i.endpoint.EventDrivenConsumer       : started bean '_org.springframework.integration.errorLogger'
2020-10-08 21:43:16.903  INFO 19656 --- [  restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 8080 (http) with context path ''
2020-10-08 21:43:16.923  INFO 19656 --- [  restartedMain] i.p.start.MyNewProjectApplication        : Started MyNewProjectApplication in 3.491 seconds (JVM running for 6.366)
2020-10-08 21:43:20.841  INFO 19656 --- [nio-8080-exec-1] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring dispatcherServlet 'dispatcherServlet'
2020-10-08 21:43:20.841  INFO 19656 --- [nio-8080-exec-1] o.s.web.servlet.dispatcherServlet        : Initializing Servlet 'dispatcherServlet'
2020-10-08 21:43:20.841 DEBUG 19656 --- [nio-8080-exec-1] o.s.web.servlet.dispatcherServlet        : Detected StandardServletMultipartResolver
2020-10-08 21:43:20.851 DEBUG 19656 --- [nio-8080-exec-1] o.s.web.servlet.dispatcherServlet        : enableLoggingRequestDetails='false': request parameters and headers will be masked to prevent unsafe logging of potentially sensitive data
2020-10-08 21:43:20.851  INFO 19656 --- [nio-8080-exec-1] o.s.web.servlet.dispatcherServlet        : Completed initialization in 10 ms
2020-10-08 21:43:20.881 DEBUG 19656 --- [nio-8080-exec-1] o.s.web.servlet.dispatcherServlet        : GET "/home",parameters={}
2020-10-08 21:43:20.896 DEBUG 19656 --- [nio-8080-exec-1] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped to ResourceHttpRequestHandler ["classpath:/meta-inf/resources/","classpath:/resources/","classpath:/static/","classpath:/public/","/"]
2020-10-08 21:43:20.900 DEBUG 19656 --- [nio-8080-exec-1] o.s.w.s.r.ResourceHttpRequestHandler     : Resource not found
2020-10-08 21:43:20.901 DEBUG 19656 --- [nio-8080-exec-1] o.s.web.servlet.dispatcherServlet        : Completed 404 NOT_FOUND
2020-10-08 21:43:20.911 DEBUG 19656 --- [nio-8080-exec-1] o.s.web.servlet.dispatcherServlet        : "ERROR" dispatch for GET "/error",parameters={}
2020-10-08 21:43:20.914 DEBUG 19656 --- [nio-8080-exec-1] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped to org.springframework.boot.autoconfigure.web.servlet.error.BasicErrorController#errorHtml(HttpServletRequest,HttpServletResponse)
2020-10-08 21:43:20.960 DEBUG 19656 --- [nio-8080-exec-1] o.s.w.s.v.ContentNegotiatingViewResolver : Selected 'text/html' given [text/html,text/html;q=0.8]
2020-10-08 21:43:20.966 DEBUG 19656 --- [nio-8080-exec-1] o.s.web.servlet.dispatcherServlet        : Exiting from "ERROR" dispatch,status 404

浏览器的屏幕:

enter image description here

HomeController.java:


package it.progettoThymeleaf.start;

import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

public class HomeController {
    
    @GetMapping("/home")
    public String getHome(Model model) {
        model.addAttribute("message","Benvenuti nel mio nuovo progetto Thymeleaf!");
        return "home";
    }
}

home.html:

<!DOCTYPE html>
<html xmlns:th="www.thymeleaf.org">
<head>
<Meta charset="ISO-8859-1">
<title>Gianluca's New Project</title>
</head>
<body>
    <h1 th:text=${message}></h1>
</body>
</html>

项目包浏览器屏幕:

enter image description here

解决方法

您在home.html中的名称空间不完整http://www.w3.org/1999/xhtml

<html lang="en" xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org">
,

我试图在本地创建一个项目,并且遇到了同样的问题。

我通过在模板文件夹下添加一个html文件来解决此问题。 基本上,这是您的thymeleaf模板所在的位置。添加屏幕截图。

enter image description here

如果要从/home访问主页,请将其添加到属性文件中

server.servlet.context-path=/home

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其他元素将获得点击?
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。)
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbcDriver发生异常。为什么?
这是用Java进行XML解析的最佳库。
Java的PriorityQueue的内置迭代器不会以任何特定顺序遍历数据结构。为什么?
如何在Java中聆听按键时移动图像。
Java“Program to an interface”。这是什么意思?
Java在半透明框架/面板/组件上重新绘画。
Java“ Class.forName()”和“ Class.forName()。newInstance()”之间有什么区别?
在此环境中不提供编译器。也许是在JRE而不是JDK上运行?
Java用相同的方法在一个类中实现两个接口。哪种接口方法被覆盖?
Java 什么是Runtime.getRuntime()。totalMemory()和freeMemory()?
java.library.path中的java.lang.UnsatisfiedLinkError否*****。dll
JavaFX“位置是必需的。” 即使在同一包装中
Java 导入两个具有相同名称的类。怎么处理?
Java 是否应该在HttpServletResponse.getOutputStream()/。getWriter()上调用.close()?
Java RegEx元字符(。)和普通点?