当前位置: 首页 > news >正文

IDEA 创建 Java 项目 SpringMVC Thymeleaf 碰到的问题

IDEA 创建 Java 项目 SpringMVC Thymeleaf 碰到的问题

一、环境配置

1.1、Maven 配置

Maven 配置阿里云镜像等

1.2、IDEA 配置 Maven


1.3、IDEA 添加 Tomcat


二、创建 Project









<?xml version="1.0" encoding="UTF-8"?><projectxmlns="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>com.yangjunbo</groupId><artifactId>springmvc-demo-01</artifactId><version>1.0-SNAPSHOT</version><properties><maven.compiler.source>17</maven.compiler.source><maven.compiler.target>17</maven.compiler.target><project.build.sourceEncoding>UTF-8</project.build.sourceEncoding></properties><dependencies><!-- SpringMVC --><dependency><groupId>org.springframework</groupId><artifactId>spring-webmvc</artifactId><version>5.3.1</version></dependency><!-- 日志 --><dependency><groupId>ch.qos.logback</groupId><artifactId>logback-classic</artifactId><version>1.2.3</version></dependency><!-- Spring5和Thymeleaf整合包 --><dependency><groupId>org.thymeleaf</groupId><artifactId>thymeleaf-spring5</artifactId><version>3.0.12.RELEASE</version></dependency></dependencies></project>

<?xml version="1.0" encoding="UTF-8"?><web-appxmlns="https://jakarta.ee/xml/ns/jakartaee"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="https://jakarta.ee/xml/ns/jakartaee https://jakarta.ee/xml/ns/jakartaee/web-app_5_0.xsd"version="5.0"><!-- 配置SpringMVC的前端控制器,对浏览器发送的请求统一进行处理 --><servlet><servlet-name>springMVC</servlet-name><servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class><!-- 通过初始化参数指定SpringMVC配置文件的位置和名称 --><init-param><!-- contextConfigLocation为固定值 --><param-name>contextConfigLocation</param-name><!-- 使用classpath:表示从类路径查找配置文件,例如maven工程中的src/main/resources --><param-value>classpath:springMVC.xml</param-value></init-param><!-- 作为框架的核心组件,在启动过程中有大量的初始化操作要做 而这些操作放在第一次请求时才执行会严重影响访问速度 因此需要通过此标签将启动控制DispatcherServlet的初始化时间提前到服务器启动时 --><load-on-startup>1</load-on-startup></servlet><servlet-mapping><servlet-name>springMVC</servlet-name><!-- 设置springMVC的核心控制器所能处理的请求的请求路径 /所匹配的请求可以是/login或.html或.js或.css方式的请求路径 但是/不能匹配.jsp请求路径的请求 --><url-pattern>/</url-pattern></servlet-mapping></web-app>


<?xml version="1.0" encoding="UTF-8"?><beansxmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns:context="http://www.springframework.org/schema/context"xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context https://www.springframework.org/schema/context/spring-context.xsd"><!-- 自动扫描包 --><context:component-scanbase-package="yang.junbo.mvc"/><!-- 配置Thymeleaf视图解析器 --><beanid="viewResolver"class="org.thymeleaf.spring5.view.ThymeleafViewResolver"><propertyname="order"value="1"/><propertyname="characterEncoding"value="UTF-8"/><propertyname="templateEngine"><beanclass="org.thymeleaf.spring5.SpringTemplateEngine"><propertyname="templateResolver"><beanclass="org.thymeleaf.spring5.templateresolver.SpringResourceTemplateResolver"><!-- 视图前缀 --><propertyname="prefix"value="/WEB-INF/templates/"/><!-- 视图后缀 --><propertyname="suffix"value=".html"/><propertyname="templateMode"value="HTML5"/><propertyname="characterEncoding"value="UTF-8"/></bean></property></bean></property></bean></beans>

packageyang.junbo.mvc;importorg.springframework.stereotype.Controller;importorg.springframework.web.bind.annotation.RequestMapping;/** * ClassName: HelloController * Package: yang.junbo.mvc * Description: * * @Author 杨钧博 * @Create 2026/6/10 19:39 * @Version 1.0 */@ControllerpublicclassHelloController{// localhost:8080/springMVC/@RequestMapping("/")publicStringindex(){//设置视图名称return"index";}}

<!DOCTYPEhtml><htmllang="en"xmlns:th="http://www.thymeleaf.org"><head><metacharset="UTF-8"><title>首页</title></head><body><h1>首页</h1><ath:href="@{/hello}">HelloWorld</a><br/></body></html>

三、部署启动







四、排查问题


现在有两个解决办法

  • 更换 Tomcat 9 以下版本
  • 升级 SpringMVC 依赖的版本

升级 SpringMVC 依赖的版本




更换 Tomcat 9 以下版本


















http://www.jsqmd.com/news/989260/

相关文章:

  • 【2027最新】基于SpringBoot+Vue的智慧校园之家长子系统管理系统源码+MyBatis+MySQL
  • GEO公司|2026年国内主流服务商全维度测评与专业选型指南 - GEO优化
  • 行业定制开发:对接业务系统的AI客服与知识库智能体实现
  • 终极Aria2GUI完整指南:从命令行到macOS图形界面的技术实现
  • Playnite终极指南:一站式解决多平台游戏管理难题的免费开源方案
  • 世毫九实验室(Shardy Lab)原创理论开源与版权声明
  • jfinal cms优化版本:jfinal升至5.2.2,beetl升至3.16.2
  • 2026男装工厂一手批发TOP5评测:选厂核心维度全解析 - 优质品牌商家
  • 从零开始:如何用Neo4j图形数据库构建你的社交推荐系统
  • 2026年近期河北钻裂一体机生产商可靠选择指南 - 品牌鉴赏官2026
  • 数据的加密与解密(01:57)
  • 【无人机】基于PID控制的无人机巡航仿真附Matlab代码
  • Cesium 导航模块设计
  • 数据的加密与解密(01:50)
  • C#微信自动化开发套件:多版本协议DLL、扫码登录注入工具与完整文档
  • 2026年Q2四川制冷服务对接推荐:四川冰雪人等企业解析 - 优质品牌商家
  • 【Agent Harness实战】我给 Agent 装了一套“神经系统”,它现在比我还敏感
  • 018华夏之光永存,助力国家科技破局:先进制程(7nm及以下)全流程EDA工具链专项
  • OpenBangla键盘终极指南:免费开源的孟加拉语输入法解决方案
  • 学生可用的步态识别课程设计全套材料:Python源码+预训练模型+详细PDF文档
  • 2026年当下,焦作有实力的小区电梯门套直销厂商选择指南 - 品牌鉴赏官2026
  • 2026年东莞橡胶制品厂家推荐榜:耐低温/阻燃/导电/医用橡胶密封圈及汽车配件、婴儿辅食碗与耐高温硅橡胶无菌垫圈源头厂商精选 - 品牌发掘
  • Claude Code对话历史:实现可回溯的AI调试时间线
  • 用STM32F103C8T6的TIM4+DMA驱动WS2812灯带:一个CubeMX配置的避坑实录
  • 广州 GEO 服务商深度测评:2026 年五大优质品牌与全意图 GEO 核心价值 - GEO优化
  • 想在广东找到专业靠谱的退税机构,这些筛选方法值得你参考
  • 3步掌握Bottles:在Linux上完美运行Windows软件与游戏的终极指南
  • 非公度量子系统的谱分析方法与高维嵌入技术
  • 2026年 阁楼货架厂家推荐排行榜:规模最大、专业实力与定制化仓储方案深度解析 - 品牌发掘
  • 深圳 GEO 服务商推荐:2026 年五大权威机构测评与全意图 GEO 价值解析 - GEO优化