JAVA-下载并运行Spring源码,超细节,包成功!

Posted 阿仇_Parsifal

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了JAVA-下载并运行Spring源码,超细节,包成功!相关的知识,希望对你有一定的参考价值。

我们看spring源码有两种方式。一,可以在项目中引入spring依赖,进行静态调试。二是下载源码进行调试。博主认为将源码下载下来,写自己的注释快乐滴研究spring的奥秘是一个很棒的主意。

 

使用工具:

IDEA,Gradle

源码下载地址:

spring-framework:

GitHub - spring-projects/spring-framework: Spring Framework

流程

博主使用的版本是spring-framework-5.2.6.RELEASE版本

选择版本,下载ZIP压缩包

下载好了之后,我们去下载一下gradle。

切换到我们下载好的 spring源码路径下。输入cmd打开命令行窗口

 

首先执行
gradlew :spring-oxm:compile TestJava,它会开始下载gradle-5.6.4-bin.zip。


默认是下载到

 

C.\\Users\\Administrator八。gradle\\wrapper\\dists\\gradle-5.6.4-binl…目录,

如果本篇博客对您有一定的帮助,大家记得留言+点赞+收藏哦。 

Nacos源码启动(超详细)

一、Nacos下载

        下载地址:https://github.com/alibaba/nacos

        下载压缩包并解压,使用idea打开。

 

 二、尝试运行:

        找到console目录,Nacos类就是启动类(实际上就是springboot项目)

三:发现报错consistency.entity不存在 

         解决:

        1.将nacos的pom文件中的protobuf依赖版本换成新版本3.19.3

        2.clean清除之前编译的内容,再install

        install之后出现以下界面:

         3.发现com.alibaba.nacos.consistency包存在

四、再次运行:

        出现以下报错信息:

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'consoleHealth' defined in file [D:\\Download\\nacos-develop\\console\\target\\classes\\com\\alibaba\\nacos\\console\\controller\\HealthController.class]: Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'externalStoragePersistServiceImpl': Invocation of init method failed; nested exception is java.lang.RuntimeException: java.lang.RuntimeException: [db-load-error]load jdbc.properties error
	at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:800)
	at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:229)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1372)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1222)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:582)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:542)
	at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335)
	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234)
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333)
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208)
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:953)
	at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:918)
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:583)
	at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:145)
	at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:745)
	at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:420)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:307)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1317)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1306)
	at com.alibaba.nacos.Nacos.main(Nacos.java:35)
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'externalStoragePersistServiceImpl': Invocation of init method failed; nested exception is java.lang.RuntimeException: java.lang.RuntimeException: [db-load-error]load jdbc.properties error
	at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor.postProcessBeforeInitialization(InitDestroyAnnotationBeanPostProcessor.java:160)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsBeforeInitialization(AbstractAutowireCapableBeanFactory.java:440)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1796)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:620)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:542)
	at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335)
	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234)
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333)
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208)
	at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:276)
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1389)
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1309)
	at org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:887)
	at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:791)
	... 19 common frames omitted
Caused by: java.lang.RuntimeException: java.lang.RuntimeException: [db-load-error]load jdbc.properties error
	at com.alibaba.nacos.config.server.service.datasource.DynamicDataSource.getDataSource(DynamicDataSource.java:60)
	at com.alibaba.nacos.config.server.service.repository.extrnal.ExternalStoragePersistServiceImpl.init(ExternalStoragePersistServiceImpl.java:135)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor$LifecycleElement.invoke(InitDestroyAnnotationBeanPostProcessor.java:389)
	at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor$LifecycleMetadata.invokeInitMethods(InitDestroyAnnotationBeanPostProcessor.java:333)
	at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor.postProcessBeforeInitialization(InitDestroyAnnotationBeanPostProcessor.java:157)
	... 32 common frames omitted
Caused by: java.lang.RuntimeException: [db-load-error]load jdbc.properties error
	at com.alibaba.nacos.config.server.service.datasource.ExternalDataSourceServiceImpl.init(ExternalDataSourceServiceImpl.java:109)
	at com.alibaba.nacos.config.server.service.datasource.DynamicDataSource.getDataSource(DynamicDataSource.java:55)
	... 40 common frames omitted

         报错原因:

                最后一个Cause by提到:[db-load-error]load jdbc.properties error,jdbc.properties异常,因为没有配置数据库mysql,所以报错。

        解决:打开console下的resources目录下的application.properties配置文件,配置连接数据库。(需提前在mysql数据库中准备nacos所对应的database)

        1.找到sql脚本

        

        2.在MySQL创建nacos的database,并执行以上sql脚本(12张表)

        

         3.在console下的application.properties配置文件中配置连接数据库

        对以下内容取消注释:

五、配置nacos单机启动

在此处配置nacos单机启动,写入以下内容:

-Dnacos.standalone=true

 再次启动

六、成功运行:

        再次启动nacos,看到成功启动: 

         访问http://localhost:8848/nacos/查看是否可以成功访问:

         看到以上界面,则证明nacos成功启动!!!

以上是关于JAVA-下载并运行Spring源码,超细节,包成功!的主要内容,如果未能解决你的问题,请参考以下文章

将java打jar包成linux后台服务service

Spring1:Spring简介环境搭建源码下载及导入MyEclipse

Nacos源码启动(超详细)

java当局部变量与全局变量同名时,源码+原理+手写框架

java入门超基础的java入门知识,细节拉满

瑞吉外卖项目 基于spring Boot+mybatis-plus开发 超详细笔记,有源码链接