Spring MVC + IDEA 源码项目搭建的踩坑
相关文档
Spring Framework: https://spring.io/projects/spring-framework/
Reference: https://docs.spring.io/spring-framework/reference/index.html
- 容器介绍 (基于Xml的容器) Introduction to the Spring IoC Container and Beans
- 基于Java (注解) 的容器配置: Java-based Container Configuration
- Spring Expression Language (SpEL): Spring Expression Language (SpEL)
- Transaction Management: Transaction Management
环境准备
Spring framework 源码项目
github: https://github.com/spring-projects/spring-framework
实例 v6.1.1版本源码: https://github.com/spring-projects/spring-framework/releases/tag/v6.1.1
Gradle
Spring framework 源码使用 gradle 进行构建
版本需 7.6 以上; 我这里用的是 Gradle 8.4 版本 : https://gradle.org/next-steps/?version=8.4&format=bin
实例项目
基于Spring Framework 的源码运行子项目跑起来:
- 在 Download 下来的Spring 源码项目, 新建一个子模块
- new module > my-learn-spring > gradle项目
添加源码项目依赖 context, aop ...
plugins {
id 'java'
}
group = 'org.yang.learn.spring'
version = '0.0.1'
repositories {
mavenCentral()
}
dependencies {
implementation( project(':spring-context'))
implementation( project(':spring-aop'))
implementation( project(':spring-jdbc'))
testImplementation platform('org.junit:junit-bom:5.9.1')
testImplementation 'org.junit.jupiter:junit-jupiter'
}
test {
useJUnitPlatform()
}
踩坑指南
源码部署遇到的几个问题
- idea webapp的项目 artifacts 方式 无论是 exploded 还是 archivel类类型; 已经在 output directory 和war压缩包中看到编译出来的 class了; Tomcat Server 跑起来就是报NoClassDefFoundError
- artifacts 出来了产物, 没有将依赖的项目 resources目录的文件编译出来, 只有 class文件 例如: tx模块的 spring.handlers, spring.schemas, web模块的 ContextLoader.properties;
![Pasted image 20251114154808]()
![Pasted image 20251114154818]()
![Pasted image 20251114154826]()
解决是: 项目 facets 标记的 web resource directory 目录, 是 ./src/main/ 目录下面, 比如: /src/main/webapp, 不然web.xml配置的 classpath:.., <servlet-class> idea全报红 很难看
3. lib各jar依赖报错的问题, 我这里报的是 Caused by: java.lang.IllegalArgumentException: 找到多个名为org_apache_tomcat_websocket的片段。这是不合法的相对排序。有关详细信息,请参阅Servlet规范的第8.2.2 2c节。考虑使用绝对排序。 at org.apache.tomcat.util.descriptor.web.WebXml.orderWebFragments(WebXml.java:2203)
4. 稍微注意一下 java ee 和 jakarta ee 的问题, tomcat 10 默认是 jakarta ee 的api




浙公网安备 33010602011771号