栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

spring源码

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

spring源码

搭建环境

本次使用的源码Spring4.3.x,JDK8,gradle4.10.2,idea2018.2.5

Spring源码使用的是Gradle 进行构建的,所以需要下载 Gradle 以及搭建 java开发环境

Java环境使用的是 JDK1.8

Gradle版本4.10.2 Gradle下载

 spring-framework-4.3.x.zip 包:查看build.gradle文件 查询gradlew 有推荐匹配的gradle版本号

Spring源码下载地址:Spring源码下载

开始编译

Spring官方给出的步骤

  1. 进入Spring源码目录cd spring-framework-4.3.x
  2. 执行脚本:gradlew.bat cleanIdea :spring-oxm:compileTestJava
导入idea

File-->new-->Project from Existing Sources... 选中解压的目录(spring-framework-4.3.x)

 如果build报错,一般都是引用的jar无法下载到

修改配置build.gradle 添加maven仓库

注意:有2个地方需要添加,我这边应该是加多了,但是以防万一都加上了

可以参考:阿里仓库服务

buildscript {
	repositories {
		maven { url "https://maven.aliyun.com/repository/public" }
		gradlePluginPortal()
		maven { url "https://repo.spring.io/plugins-release" }
	}
repositories {
		maven{ url 'https://maven.aliyun.com/repository/public'}
		maven{ url 'https://maven.aliyun.com/repository/apache-snapshots'}
		maven{ url 'https://maven.aliyun.com/repository/central'}
		maven{ url 'https://maven.aliyun.com/repository/spring-plugin'}
		maven{ url 'https://maven.aliyun.com/nexus/content/groups/public'}
		maven{ url 'https://maven.aliyun.com/nexus/content/repositories/jcenter'}
		mavenCentral()
		maven { url "https://repo.spring.io/libs-spring-framework-build" }
	}

然后基本上加载就没有问题了

代码build

build会报各种问题,首先build去除test模块的代码,用  build -x test 执行

创建module:test-spring

package com.ywm;


public class TestBean {
    public TestBean() {
        System.out.println("init.......");
    }

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

}
package com.ywm;

import org.springframework.context.support.ClassPathXmlApplicationContext;


public class TestSpring {
    public static void main(String[] args) {
        ClassPathXmlApplicationContext ctx =
                new ClassPathXmlApplicationContext("beans.xml");
        System.out.println(ctx.getId());
        TestBean tb = ctx.getBean(TestBean.class);
        tb.test();
    }

}



    


启动报错:ClassPathXmlApplicationContext 无法加载

解决办法:子模块的build.gradle配置添加

 如果spring-context:main里面无法加载aop文件

解决办法:模块的build.gradle配置添加

 遇到的问题到此结束

启动test

 遇到特殊情况,这个里面的main方法的jdk默认选中6,需要特殊注意一下,应该是我电脑同时安装了jdk6和jdk8

记录:

零零总总搞了好几天,主要是各种编译问题

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/929895.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号