eclipse导入Spring 5.0X源码

1. 版本信息
eclipse Version: 2018-12 (4.10.0)
gradle-4.9
JDK 1.8

2. gradle-4.9
下载链接:(https://services.gradle.org/distributions/)
eclipse导入Spring 5.0X源码_第1张图片
gadle下载时候有三个包,gradle-src为gralde源码,gradle-bin为安装包,gradle-all为源码加安装包,我们这里只需下载安装包就可以了。

gradle安装步骤

  1. 将下载的gradle-4.9解压
  2. 配置gradle环境变量

配置的两种方式:
1.新建用户变量 -------> 变量名(GRADLE_HOME) 变量值(自己解压gradle的文件夹路径) ------> 将新建的用户变量添加到系统变量path的末尾增加:;%GRADLE_HOME%/bin;
eclipse导入Spring 5.0X源码_第2张图片
2.将gradle的解压路径直接配置在path里面
eclipse导入Spring 5.0X源码_第3张图片
注:本人是选择的第二种方式

配置完成以后验证:win+r,输入cmd进入dos界面, 键入命令gradle -v
eclipse导入Spring 5.0X源码_第4张图片

3. 下载Spring 5.0X源码
下载链接:(https://github.com/spring-projects/spring-framework)
注:没有账号的同学自己注册一个哟!!!

  选择5.0X版本

eclipse导入Spring 5.0X源码_第5张图片
eclipse导入Spring 5.0X源码_第6张图片
然后下载一个压缩包

4. 导入eclipse过程
1)将Spring 5.0X压缩包解压
2)找到import-into-eclipse.bat
eclipse导入Spring 5.0X源码_第7张图片
3)运行import-into-eclipse.bat。根据界面提示操作,运行成功出现BUILD SUCCESSFUL(如果失败,根据提示排查,目前这一步基本没有遇到问题)
4)执行命令(因为第一次导入的时候出现导入的Spring丢失了一些架包的情况,所以后面吸取教训就执行一些命令。建议执行,如果能确保自己前面步骤一定不会出现架包丢失,也可以不执行)
在Spring 源码的解压目录下执行:
– gradle objenesisRepackJar
– gradle cglibRepackJar
eclipse导入Spring 5.0X源码_第8张图片
注:
执行命令的时候可能会报错提示:spring-framework-5.0.x\spring-beans\spring-beans.gradle 第二十八行存在错误。
解决方法:注释这一行
eclipse导入Spring 5.0X源码_第9张图片
5)eclipse 安装Groovy
Help -----> Eclipse Maker ------>搜索Groovy
eclipse导入Spring 5.0X源码_第10张图片
安装Groovy,注意Groovy的版本需要指向2.5
6)安装AspectJ
Help选项,选择Install New Software
eclipse导入Spring 5.0X源码_第11张图片
AspectJ : (http://download.eclipse.org/tools/ajdt/43/update)

7)导入Spring
右键import
eclipse导入Spring 5.0X源码_第12张图片
eclipse导入Spring 5.0X源码_第13张图片

8)检查报错
如果有项目报错,检查是不是Groovy版本问题。
eclipse导入Spring 5.0X源码_第14张图片
如果是2.4的版本,就指向2.5就能解决报错。

5. 测试
eclipse导入Spring 5.0X源码_第15张图片
eclipse导入Spring 5.0X源码_第16张图片

/*
 * Copyright 2002-2019 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.spring.test;

import org.springframework.context.annotation.AnnotationConfigApplicationContext;

import com.spring.app.Appconfig;
import com.spring.service.UserService;

/**
 * 
 * @author Administrator
 * @since 5.0
 */
public class Test {

	public static void main(String[] args) {
		AnnotationConfigApplicationContext ac 
		= new AnnotationConfigApplicationContext(Appconfig.class);
		UserService bean = ac.getBean(UserService.class);
		bean.query();
	}
}

/*
 * Copyright 2002-2019 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.spring.app;

import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;

/**
 * 
 * @author Administrator
 * @since 5.0
 */
@Configuration
@ComponentScan("com.spring")
public class Appconfig {

}


```java
/*
 * Copyright 2002-2019 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.spring.service;

import org.springframework.stereotype.Component;

/**
 * 
 * @author Administrator
 * @since 5.0
 */
@Component
public class UserService {

	public void query() {
		System.out.println("userservice");
	}
}

运行结果:
eclipse导入Spring 5.0X源码_第17张图片

你可能感兴趣的:(Spring那些事,spring)