这个问题是因为在你的代码中,你尝试访问org.springframework.boot.loader.Launcher类的protected成员,但是由于访问修饰符的限制,你不能在不同的包中访问protected成员。

要解决这个问题,你可以使用反射来访问protected成员。在Launcher类中,你可以尝试使用getDeclaredField方法来获取protected成员变量,并使用setAccessible(true)方法来设置访问权限。以下是一个示例代码:

Field field = launcherClass.getDeclaredField("protectedField");
field.setAccessible(true);
Object value = field.get(jarLauncherInstance);

请注意,你需要将protectedField替换为你要访问的具体成员变量的名称,并将jarLauncherInstance替换为你创建的JarLauncher实例。

另外,你还可以使用getDeclaredMethod方法来获取protected方法,并使用setAccessible(true)方法来设置访问权限。以下是一个示例代码:

Method method = launcherClass.getDeclaredMethod("protectedMethod", String.class);
method.setAccessible(true);
Object result = method.invoke(jarLauncherInstance, "arg1");

请注意,你需要将protectedMethod替换为你要访问的具体方法的名称,并将jarLauncherInstance替换为你创建的JarLauncher实例。

通过使用反射,你可以绕过访问修饰符的限制,访问protected成员。但是请注意,这种做法可能会违反封装性原则,因此请谨慎使用

出现问题:Class comexampledemocontrollerTestController2 can not access a member of class orgspringframeworkbootloaderLauncher with modifiers protected执行代码如下: GetMappingvalue = JarLauncherJar 运行JarLauncher

原文地址: http://www.cveoy.top/t/topic/hHoJ 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录