当前位置: 首页 > 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.rkmt.cn/news/1501006.html

相关文章:

  • GEO公司|2026年国内主流服务商全维度测评与专业选型指南 - GEO优化
  • jfinal cms优化版本:jfinal升至5.2.2,beetl升至3.16.2
  • 【无人机】基于PID控制的无人机巡航仿真附Matlab代码
  • 2026年当下,焦作有实力的小区电梯门套直销厂商选择指南 - 品牌鉴赏官2026
  • 想在广东找到专业靠谱的退税机构,这些筛选方法值得你参考
  • 3步掌握Bottles:在Linux上完美运行Windows软件与游戏的终极指南
  • 2026年 阁楼货架厂家推荐排行榜:规模最大、专业实力与定制化仓储方案深度解析 - 品牌发掘
  • 腾讯云域名+Cloudflare CDN保姆级配置:手把手教你隐藏服务器真实IP并加速网站
  • 2026年高评价蛭石粉评测:珍珠岩颗粒/育苗用珍珠岩/育苗蛭石/膨胀珍珠岩/膨胀蛭石/三大品牌核心参数对比 - 优质品牌商家
  • 2026年衣架成型机厂家推荐榜:全自动/不锈钢/钢丝衣架成型机及衣架生产设备十大品牌实力解析 - 品牌发掘
  • 为什么你的视频文件总是太大?CompressO帮你5分钟解决存储难题
  • 用不到5000块DIY一个四自由度气动机械臂?开源硬件+PLC模拟器实战指南
  • 如何高效管理微信聊天数据:开源工具的完全指南
  • 2026证件照蓝底制作工具推荐:保姆级教程(免费在线+手机App)
  • Manus为人形机器人训练提供可靠数据支持
  • 2026优质塘桥办理公司注册业务公司排行参考 - 品牌排行榜
  • 2026年q2成都社区文化墙设计可靠服务商技术解析:成都党建文化墙定制公司/成都公司前台形象墙设计公司/实力盘点 - 优质品牌商家
  • FireRedTTS2实战指南:5步构建专属多说话人对话语音模型
  • MC9S12XE Flash操作实战:从寄存器配置到安全编程避坑指南
  • STC8H1K17的EEPROM读写:官方库只能存1字节?手把手教你封装16位数据读写函数
  • 年薪60W的渗透测试专家告诉你:为什么我回头去考了CISAW
  • 数据的加密与解密(01:44)
  • S12Z微控制器中断与BDC调试:原理、配置与低功耗调试实战
  • B站内容自动化监控终极解决方案:如何实现UP主动态与直播的实时推送
  • 抖音商城、团购、充值提现、达人佣金结算全链路资金流动实时风控筛查,每秒海量交易风险判定,峰值核心风控算力全盘依托阿里云金融级风控引擎兜底,自有算力只做日常轻度巡检,大额资金异动、异常转账拦截核心逻辑依
  • GD32F4的IAP升级,你的缓存区真的够用吗?从512K Flash规划谈起
  • 光伏电池恒压控制方法研究(Simulink仿真实现)
  • 从一行HEX到水文数据:手把手教你用Python解析SL651-2014协议报文
  • 手把手教你用Python解析SL651-2014水文协议(附完整代码与报文示例)
  • 自适应迭代加权惩罚最小二乘法:工业级基线校正技术深度解析