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

编译spring源码

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

编译spring源码

环境:

  • jdk1.8
  • spring 5.20
  • IDEA 2019
下载
  1. 进入https://spring.io/

  2. 选择spring framework,进入github

  3. 选择稳定版下载

编译
  1. 参考官方教程:https://github.com/spring-projects/spring-framework/blob/main/import-into-idea.md
    github界面选择:

    在wiki的界面翻到最后:

  2. 按照step里面的步骤进行
    使用gradlew编译,添加下述语句

    # 修改的第一部分
    repositories {
            maven{ url 'https://maven.aliyun.com/nexus/content/groups/public/' }
            maven{ url 'https://maven.aliyun.com/nexus/content/repositories/jcenter'}
    }
    
    
    # 修改的第而部分
    maven{ url 'https://maven.aliyun.com/nexus/content/groups/public/'}
    maven{ url 'https://maven.aliyun.com/nexus/content/repositories/jcenter'}
    
  3. 保存后,在spring框架目录下打开cmd执行./gradlew :spring-oxm:compileTestJava(如果是windows的话,执行.gradlew :spring-oxm:compileTestJava或gradlew :spring-oxm:compileTestJava)

  4. IDEA import项目


  5. 把spring-aspect给upload出去,然后重新编译


测试使用
  1. 新建module,注意选择gradle创建(maven和gradle共存会有问题)


  2. 新建package和class


    最终的文件结构如图:

  3. Service实现
    接口:

    package com.mytest.service;
    
    public interface WelcomeService {
    	String sayHello(String name);
    }
    

    实现类:

    package com.mytest.service.impl;
    
    import com.mytest.service.WelcomeService;
    
    public class WelcomeServiceImpl implements WelcomeService {
    	@Override
    	public String sayHello(String name) {
    		System.out.println("欢迎");
    		System.out.println(name);
    		return "success";
    	}
    }
    
  4. resource里的xml文件

    
    
    	
    
    
  5. gradle

    plugins {
        id 'java'
    }
    
    group 'org.springframework'
    version '5.2.0.RELEASE'
    
    sourceCompatibility = 1.8
    
    repositories {
        mavenCentral()
    }
    
    dependencies {
        compile(project(":spring-context"))
        testCompile group: 'junit', name: 'junit', version: '4.12'
    }
    

    新加了语句:compile(project(":spring-context")),加完后在IDEA右下角,自动导入

  6. 入口函数Entrance

    package com.mytest;
    
    import com.mytest.service.WelcomeService;
    import org.springframework.context.ApplicationContext;
    import org.springframework.context.support.FileSystemXmlApplicationContext;
    
    public class Entrance {
    	public static void main(String[] args) {
    		String xmlPath = "D:\spring-framework-5.2.0.RELEASE\springdemo\src\main\resources\spring\spring-config.xml";
    		ApplicationContext applicationContext = new FileSystemXmlApplicationContext(xmlPath);
    		WelcomeService welcomeService = (WelcomeService) applicationContext.getBean("welcomeService");
    		welcomeService.sayHello("啦啦啦,a test");
    	}
    }
    

然后点击运行就可以了。


报错:

Error:(347, 51) java: 找不到符号
  符号:   变量 CoroutinesUtils
  位置: 类 org.springframework.core.ReactiveAdapterRegistry.CoroutinesRegistrar

解决方法:
点击File -> Project Structure -> Libraries -> + -> Java,然后选择spring-framework/spring-core/kotlin-coroutines/build/libs/kotlin-coroutines-5.2.4.BUILD-SNAPSHOT.jar,在弹出的对话框中选择spring-core.main,在重新build项目即可。

参考:
https://blog.csdn.net/gooaaee/article/details/104437902

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

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

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