spring版本:spring-framework-5.1.6.RELEASE
环境: jdk1.8.0_144 ,gradle 4.0,win10
开发工具:idea 2018.2.3
下载的源码中,有一个import-into-idea.md文件,根据文件里的流程进行源码构建,
第一步:Precompile spring-oxm
with ./gradlew :spring-oxm:compileTestJava
预编译 spring-oxm
过程中产生的问题:
1.报错内容如下图
具体原因: Received status code 401 from server: Unauthorized
项目中build.gradle文件默认配置的中央仓库的地址是spring官方提供的仓库,该仓库需要认证.
解决方案:将build.gradle文件下的buildscript 和allprojects下的repositories仓库地址分别替换成阿里云官方提供的仓库地址,如下所示
buildscript {
repositories {
maven { url "https://maven.aliyun.com/repository/public" }
maven { url "https://maven.aliyun.com/repository/spring-plugin"}
}
dependencies {
classpath("io.spring.gradle:propdeps-plugin:0.0.9.RELEASE")
classpath("org.asciidoctor:asciidoctorj-pdf:1.5.0-alpha.16")
}
}
.
.
.
repositories {
maven { url "https://maven.aliyun.com/repository/public" }
maven { url "https://maven.aliyun.com/repository/spring-plugin"}
}
替换中央仓库地址后,重新执行命令,成功如下图
第二步:Import into IntelliJ (File -> New -> Project from Existing Sources -> Navigate to directory -> Select build.gradle 选择源码根目录的build.gradle 导入到idea
1.选择好jdk版本
2.选择本地gradle仓库(这里给个提示,gradle可以引用maven的本地仓库)
3.设置jvm参数:-XX:MaxPermSize=2048m -Xmx2048m -XX:MaxHeapSize=2048m
接下来就是漫长的导包过程,导包完成后,没有任何报错
好像感觉都挺顺利的!!!
接下来在spring工程的基础上创建一个子模块(普通的Spring+Springmvc工程),如下图
项目结构如下图
web.xml文件内容:
<?xml version="1.0" encoding="UTF-8"?>
<web-app>
<servlet>
<servlet-name>app</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:spring.xml</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>app</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
</web-app>
spring.xml内容
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context" xmlns:p="http://www.springframework.org/schema/p"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd">
<context:component-scan base-package="com.chx.test"/>
<!--使RestController生效-->
<mvc:annotation-driven />
<!--开启切面-->
<aop:aspectj-autoproxy proxy-target-class="true" />
</beans>
build.gradle内容
plugins {
id 'java'
}
group 'org.springframework'
version '5.1.6.RELEASE'
apply plugin: 'war' //标记该项目打包形式是war
sourceCompatibility = 1.8
repositories {
mavenCentral()
}
dependencies {
dependencies {
compile(project(":spring-context"))
compile(project(":spring-core"))
compile(project(":spring-webmvc"))
optional("org.aspectj:aspectjweaver:${aspectjVersion}")
optional("com.fasterxml.jackson.core:jackson-databind:${jackson2Version}")
testCompile group: 'junit', name: 'junit', version: '4.12'
}
}
然后项目成功启动
这个版本尤其顺利,可能是之前构建过spring-framework-5.0.2.RELEASE的原因
总结:
一.如果引入依赖报错
解决方式:修改中央仓库地址
二.解决 cglib和objenesis的编译错误
解决方式:构建spring-core模块,构建完,spring-framework-5.0.2.RELEASE\spring-core\build\libs 会出现spring-cglib-repack-3.2.5.jar,spring-objenesis-repack-2.6.jar,如下图
三.解决Aspectj 问题
参考:https://blog.csdn.net/qq_38196479/article/details/104071904