Spring源码阅读环境搭建-java: 程序包jdk.jfr不存在的报错解决方法

本文指导读者下载Spring Framework,配置Gradle并导入IDEA,实现Spring-config.xml解析与单元测试,包括如何解决Java版本兼容问题和新模块的创建。

下载Spring-Framework。

https://gitee.com/mirrors/Spring-Framework

这个是 gitee spring镜像 每天更新一次

压缩后打开/gradle/wrapper下的properties文件

查看distributionUrl用的哪个版本的gradle 先到网上下载 然后使用下载的gradle包本地引入 不然直接下载很慢

我这里是gradle-6.8.3-bin.zip.

本地引入例子:distributionUrl=file:///H:/android/gradle-6.8.3-bin.zip

repositories修改:

repositories {
   maven {url 'https://maven.aliyun.com/nexus/content/groups/public/'} 
   maven { url 'https://repo.springsource.org/plugins-release/' }
}

查看根目录文件下的 import-into-idea.md

里面有步骤

  1. 预编译oxm :使用命令

    ./gradlew :spring-oxm:compileTestJava   //windows 去掉./
    

2.idea 导入 build.gradle 之后整个项目就会加载

3.出现提示时,排除spring-aspects模块,因为该模块使用了idea无法识别的代码类型。

编译完成后,随便找个模块下test单测跑一下是否成功

然后就是我们新加入自己的moudle

右键根目录New moudle 选择Gradle 勾Java 然后取名就行了

新建模块加入代码

1.MainTest

package com.zxh.test;

import org.junit.Test;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
import org.springframework.core.io.ClassPathResource;

public class MainTest {

	@Test
	public void MyTest() {
		ClassPathResource res = new ClassPathResource("Spring-config.xml");
		DefaultListableBeanFactory factory = new DefaultListableBeanFactory();
		XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(factory);
		reader.loadBeanDefinitions(res);

		System.out.println(factory.getBean(TestBean.class).getName());

	}
}

2.TestBean

package com.zxh.test;

public class TestBean {
	private String name = "hehe";

	public TestBean(String name) {
		this.name = name;
	}

	public TestBean() {
	}

	@Override
	public String toString() {
		return "TestBean{" +
				"name='" + name + '\'' +
				'}';
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

}

3.resources下添加Spring-config.xml 这里我的S大写 注意下

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
	   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	   xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
	<bean id="testBean" class="com.zxh.test.TestBean"/>
</beans>

然后就可以测试代码啦

在这步或者上面的步骤中可能出现 java: 程序包jdk.jfr不存在的报错
我们只需要把Project Structure的语言等级改为8,Project和Moudle的SDK换为
OpenJDK8U-jdk_x64_windows_hotspot_8u222b10.zip
**
**
Setting中Gradle下JVM也改为OpenJDK8Ujdk_x64_windows_hotspot_8u222b10.zip 即可
该资源网上找

然后运行就成功了。

D:\Java\jdk-21.0.2\bin\java.exe -agentlib:jdwp=transport=dt_socket,address=127.0.0.1:15214,suspend=y,server=n "-javaagent:C:\Users\c30080007\AppData\Local\JetBrains\IntelliJIdea2025.1\captureAgent\debugger-agent.jar=file:///C:/Users/C30080~1/AppData/Local/Temp/capture7514175130466777029.props" -javaagent:D:\appfile\yalustudio\agent\gaia-studio-agent-1.0.0-SNAPSHOT.jar -Dfoundation.console.group=c30080007 -Dfoundation.console.appName=apigcESAggregation -Dfoundation.console.enabled=true -Dfoundation.console.url=http://hissit.huawei.com/gaia/console/admin -Dfoundation.console.discovery.enabled=true -Djalor.web.requestSecurity-filter.enabled=false -DyaluStudioConvertRealRequestApiUrl=https://gaia-studio.dp-beta.huawei.com/gaia-studio/gateway/services/v1/application/query-actual-route -DyaluStudioQueryEurekaGroupUrl=https://gaia-studio.dp-beta.huawei.com/gaia-studio/gateway/services/v1/application/query-eureka-group -DyaluStudioAddRecordingRulesUrl=https://gaia-studio.dp-beta.huawei.com/gaia-studio/gateway/services/v1/record/playback/add-result -DyaluStudioAddDeployUnitRunInfoUrl=https://gaia-studio.dp-beta.huawei.com/gaia-studio/gateway/services/v1/application/deploy-unit-run-info -DyaluStudioGetPublicDeployUnitInstancesUrl=https://gaia-studio.dp-beta.huawei.com/gaia-studio/gateway/services/v1/application/public-deploy-unit-instances -DyaluStudioAddEurekaGroupUrl=https://gaia-studio.dp-beta.huawei.com/gaia-studio/gateway/services/v1/application/eureka-group -DyaluStudioIsLocalIpAddressUrl=https://gaia-studio.dp-beta.huawei.com/gaia-studio/gateway/services/v1/plugin/judgment/ip/address -DlocalDebugUrl=https://gaia-studio.dp-beta.huawei.com/gaia-studio/gateway/services/v1/plugin/local-deploy -DconfigInfoUrl=https://gaia-studio.dp-beta.huawei.com/gaia-studio/gateway/services/v1/config/link -DgetClustersActiveProfileUrl=https://gaia-studio.dp-beta.huawei.com/gaia-studio/gateway/services/v1/ads/clusters-params -DyaluStudioDataReporterUrl=https://gaia-studio.dp-beta.huawei.com/gaia-studio/gateway/services/v1/operation-record/add-record -Ddebug.deployId=866dc1709aa83872a9ceb585d698d370 -DappId=com.huawei.cbgit.gaia.apigc -DappName=apigcESAggregation -DenvJsonFilePath=C:\Users\c30080007\AppData\Roaming\JetBrains\IntelliJIdea2025.1\scratches\http-client.env.json -DwriteEnvFileSuccessLog=yaluStudioWriteEnvSuccess -Dauthor=c30080007 -Dgroup=c30080007 -DparentGroup=kwe_dev -DoperationId=c978d871-b981-42a7-a588-d03b32ad390a -DmicroserviceId=null -DrepoUrl=https://codehub-dg-g.huawei.com/CBGIT_Public/GaiaDesignDevCenter/GApiGCES.git -DpluginActiveEnv=uat -DuseLocalConfig=false -agentpath:C:\Users\c30080007\AppData\Local\Temp\idea_libasyncProfiler_dll_temp_folder33236\libasyncProfiler.dll=version,jfr,event=wall,interval=10ms,cstack=no,file=C:\Users\c30080007\IdeaSnapshots\MainApplication_2025_11_25_152607.jfr,dbghelppath=C:\Users\c30080007\AppData\Local\Temp\idea_dbghelp_dll_temp_folder7\dbghelp.dll,log=C:\Users\c30080007\AppData\Local\Temp\MainApplication_2025_11_25_152607.jfr.log.txt,logLevel=DEBUG -XX:TieredStopAtLevel=1 -Dspring.output.ansi.enabled=always -Dcom.sun.management.jmxremote -Dspring.jmx.enabled=true -Dspring.liveBeansView.mbeanDomain -Dspring.application.admin.enabled=true "-Dmanagement.endpoints.jmx.exposure.include=*" -Dkotlinx.coroutines.debug.enable.creation.stack.trace=false -Ddebugger.agent.enable.coroutines=true -Dkotlinx.coroutines.debug.enable.flows.stack.trace=true -Dkotlinx.coroutines.debug.enable.mutable.state.flows.stack.trace=true -Dfile.encoding=UTF-8 -Dsun.stdout.encoding=UTF-8 -Dsun.stderr.encoding=UTF-8 -classpath C:\Users\c30080007\AppData\Local\Temp\classpath368542657.jar com.huawei.it.gaia.apigc.app.MainApplication 已连接到地址为 ''127.0.0.1:15214',传输: '套接字'' 的目标虚拟机 11-25 15:26:08.321 INFO YaluStudioAgent : yaluStudioIsCloudDeploy=null 11-25 15:26:08.327 INFO AgentStarter : agent file dir is [D:\appfile\yalustudio\agent] 11-25 15:26:08.329 INFO AgentStarter : agent param: {} 11-25 15:26:08.330 INFO ConfigUtils : useLocalConfig is [false] OpenJDK 64-Bit Server VM warning: Sharing is only supported for boot loader classes because bootstrap classpath has been appended 11-25 15:26:08.912 INFO StudioServerClient : Config Info DTO request success, config link http://appconfig-beta.huawei.com/ConfigCenter/services/saasConfigcenterGetConfig?application_id=com.huawei.cbgit.gaia.apigc&sub_application_id=apigcESAggregation&region=kwe&environment=kwe_dev&version=1.0 11-25 15:26:09.027 INFO KmsClient : start decrypt 11-25 15:26:09.152 INFO KmsClient : end decrypt 11-25 15:26:09.152 INFO ConfigUtils : useLocalConfig is [false] 11-25 15:26:09.153 INFO StudioServerClient : get cluster param: com.yalu.studio.huawei.it.yalu.client.req.ClustersParamsReq@30ed9c6c 11-25 15:26:10.863 INFO ConfigUtils : useLocalConfig is [false] Exception in thread "main" java.lang.ExceptionInInitializerError at com.huawei.foundation.commons.logback.sensitive.SensitiveDataConvertor.convert(SensitiveDataConvertor.java:29) at com.huawei.foundation.commons.logback.sensitive.SensitiveDataConvertor.convert(SensitiveDataConvertor.java:23) at ch.qos.logback.core.pattern.FormattingConverter.write(FormattingConverter.java:36) at ch.qos.logback.core.pattern.PatternLayoutBase.writeLoopOnConverters(PatternLayoutBase.java:174) at ch.qos.logback.classic.PatternLayout.doLayout(PatternLayout.java:200) at ch.qos.logback.classic.PatternLayout.doLayout(PatternLayout.java:41) at ch.qos.logback.core.encoder.LayoutWrappingEncoder.encode(LayoutWrappingEncoder.java:114) at ch.qos.logback.core.OutputStreamAppender.writeOut(OutputStreamAppender.java:203) at ch.qos.logback.core.OutputStreamAppender.subAppend(OutputStreamAppender.java:257) at ch.qos.logback.core.OutputStreamAppender.append(OutputStreamAppender.java:111) at ch.qos.logback.core.UnsynchronizedAppenderBase.doAppend(UnsynchronizedAppenderBase.java:85) at com.huawei.foundation.commons.logging.LogbackLoggingManager.logLine(LogbackLoggingManager.java:129) at com.huawei.foundation.commons.logging.LogbackLoggingManager.logLine(LogbackLoggingManager.java:113) at com.huawei.foundation.commons.logging.Log.logln(Log.java:260) at com.huawei.foundation.commons.startup.ServiceApplicationStartingListener.onApplicationEvent(ServiceApplicationStartingListener.java:38) at com.huawei.foundation.commons.startup.ServiceApplicationStartingListener.onApplicationEvent(ServiceApplicationStartingListener.java:27) at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:185) at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:178) at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:156) at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:138) at org.springframework.boot.context.event.EventPublishingRunListener.multicastInitialEvent(EventPublishingRunListener.java:136) at org.springframework.boot.context.event.EventPublishingRunListener.starting(EventPublishingRunListener.java:75) at org.springframework.boot.SpringApplicationRunListeners.lambda$starting$0(SpringApplicationRunListeners.java:54) at java.base/java.lang.Iterable.forEach(Iterable.java:75) at org.springframework.boot.SpringApplicationRunListeners.doWithListeners(SpringApplicationRunListeners.java:118) at org.springframework.boot.SpringApplicationRunListeners.starting(SpringApplicationRunListeners.java:54) at org.springframework.boot.SpringApplication.run(SpringApplication.java:310) at org.springframework.boot.SpringApplication.run(SpringApplication.java:1362) at org.springframework.boot.SpringApplication.run(SpringApplication.java:1351) at com.huawei.it.gaia.apigc.app.MainApplication.main(MainApplication.java:31) Caused by: java.lang.reflect.InaccessibleObjectException: Unable to make field private java.lang.Throwable java.lang.Throwable.cause accessible: module java.base does not "opens java.lang" to unnamed module @1356d4d4 at java.base/java.lang.reflect.AccessibleObject.throwInaccessibleObjectException(AccessibleObject.java:391) at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:367) at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:315) at java.base/java.lang.reflect.Field.checkCanSetAccessible(Field.java:183) at java.base/java.lang.reflect.Field.setAccessible(Field.java:177) at org.springframework.util.ReflectionUtils.makeAccessible(ReflectionUtils.java:803) at com.huawei.foundation.commons.logging.security.SensitiveExceptionFilter.<clinit>(SensitiveExceptionFilter.java:42) ... 30 more
最新发布
11-26
C:\Users\CWJ\.jdks\openjdk-24.0.1\bin\java.exe -agentlib:jdwp=transport=dt_socket,address=127.0.0.1:55279,suspend=y,server=n -javaagent:C:\Users\CWJ\AppData\Local\JetBrains\IntelliJIdea2025.1\captureAgent\debugger-agent.jar=file:///C:/Users/CWJ/AppData/Local/Temp/capture14642892686990596326.props -ea -agentpath:C:\Users\CWJ\AppData\Local\Temp\idea_libasyncProfiler_dll_temp_folder\libasyncProfiler.dll=version,jfr,event=wall,interval=10ms,cstack=no,file=C:\Users\CWJ\IdeaSnapshots\_2025_09_12_132434.jfr,dbghelppath=C:\Users\CWJ\AppData\Local\Temp\idea_dbghelp_dll_temp_folder\dbghelp.dll,log=C:\Users\CWJ\AppData\Local\Temp\_2025_09_12_132434.jfr.log.txt,logLevel=DEBUG -Didea.test.cyclic.buffer.size=1048576 -Dkotlinx.coroutines.debug.enable.creation.stack.trace=false -Ddebugger.agent.enable.coroutines=true -Dkotlinx.coroutines.debug.enable.flows.stack.trace=true -Dkotlinx.coroutines.debug.enable.mutable.state.flows.stack.trace=true -Dfile.encoding=GBK -Dsun.stdout.encoding=GBK -Dsun.stderr.encoding=GBK -classpath "E:\课程软件系统\java系统\IEDA\IntelliJ IDEA 2025.1\lib\idea_rt.jar;E:\课程软件系统\java系统\IEDA\IntelliJ IDEA 2025.1\plugins\junit\lib\junit5-rt.jar;E:\课程软件系统\java系统\IEDA\IntelliJ IDEA 2025.1\plugins\junit\lib\junit-rt.jar;C:\Users\CWJ\Desktop\项目\书本购物\项目源码\out\test\项目源码;C:\Users\CWJ\Desktop\项目\书本购物\项目源码\out\production\项目源码;C:\Users\CWJ\Desktop\项目\书本购物\项目源码\WebRoot\WEB-INF\lib\c3p0-0.9.2.1.jar;C:\Users\CWJ\Desktop\项目\书本购物\项目源码\WebRoot\WEB-INF\lib\slf4j-api-1.7.5.jar;C:\Users\CWJ\Desktop\项目\书本购物\项目源码\WebRoot\WEB-INF\lib\jsqlparser-0.9.5.jar;C:\Users\CWJ\Desktop\项目\书本购物\项目源码\WebRoot\WEB-INF\lib\spring-aop-4.0.6.RELEASE.jar;C:\Users\CWJ\Desktop\项目\书本购物\项目源码\WebRoot\WEB-INF\lib\mchange-commons-java-0.2.3.4.jar;C:\Users\CWJ\Desktop\项目\书本购物\项目源码\WebRoot\WEB-INF\lib\mysql-connector-java-5.1.41-bin.jar;C:\Users\CWJ\Desktop\项目\书本购物\项目源码\WebRoot\WEB-INF\lib\spring-jdbc-4.0.6.RELEASE.jar;C:\Users\CWJ\Desktop\项目\书本购物\项目源码\WebRoot\WEB-INF\lib\commons-logging-1.1.1.jar;C:\Users\CWJ\Desktop\
09-13
评论 4
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值