[英]Java Beans Introspector requires desktop module
I'm investigating using Jigsaw to reduce the footprint of a microservice. 我正在研究使用Jigsaw来减少微服务的占用空间。 One of the last dependencies I had to find was java.beans.Introspector.
我必须找到的最后一个依赖项是java.beans.Introspector。
Imagine my surprise when I discovered I needed to bring in the whole module java.desktop which contains all sorts of irrelevant stuff like awt, applets, swing etc. 想象一下,当我发现需要引入整个模块java.desktop时,我感到惊讶,该模块包含各种不相关的东西,例如awt,applet,swing等。
This seems crazy to me, surely bean introspection should be a part of the fundamental language and not related to UI functionality. 在我看来,这很疯狂,可以肯定的是,bean的自省应该是基本语言的一部分,并且与UI功能无关。 I think the dependency comes from the embedded Tomcat from Spring Boot so it's not something I can modify myself.
我认为依赖项来自Spring Boot的嵌入式Tomcat,因此我无法自行修改。
The Question: Are modules the finest granularity you can access or is there another way to trim the fat as it were. 问题:模块是您可以访问的最细粒度,还是有另一种方式来减少脂肪。
The dependency exists, because BeanInfo
and SimpleBeanInfo
have references to Icon
and Image
from the AWT package. 之所以存在依赖关系,是因为
BeanInfo
和SimpleBeanInfo
引用了AWT包中的Icon
和Image
。 Further, PropertyEditor
declares the methods getCustomEditor
and paintValue
creating dependencies to the classes Component
, Graphics
, and Rectangle
. 此外,
PropertyEditor
声明的方法getCustomEditor
和paintValue
创建依赖的类Component
, Graphics
和Rectangle
。 There are also some classes not visible in the API having references to desktop classes, ie the default property editor and persistence delegate implementations shipped for these desktop classes. API中还有一些不可见的类,其中包含对桌面类的引用,即为这些桌面类提供的默认属性编辑器和持久性委托实现。
Since Java modules do not allow packages spread across multiple modules, there is no way to split the functionality into an AWT dependent and a non-dependent module (in a backward compatible manner). 由于Java模块不允许程序包跨多个模块散布,因此无法将功能拆分为AWT依赖模块和非依赖模块(以向后兼容的方式)。 The dynamically loaded artifacts, ie actual bean infos, editors and persistence delegates, could have been moved into another module, but not the
BeanInfo
and PropertyEditor
interfaces and their SimpleBeanInfo
and PropertyEditorSupport
implementations. 动态加载的工件(即实际的bean信息,编辑器和持久性委托)可以移到另一个模块中,但不能移到
BeanInfo
和PropertyEditor
接口及其SimpleBeanInfo
和PropertyEditorSupport
实现中。
There is no finer granularity and no solution to use bean classes without creating that dependency. 没有更好的粒度,没有在不创建依赖项的情况下使用Bean类的解决方案。 This is best illustrated by how the JDK developers dealt with the problems caused by this decision.
JDK开发人员如何处理此决定引起的问题可以很好地说明这一点。 Since
java.util.logging.LogManager
and java.util.jar.Pack200.Packer
/ Unpacker
had support for java.beans.PropertyChangeListener
, which caused a dependency to java.desktop
, if kept that way, these methods were the first methods ever removed from the standard Java API, as fast as being deprecated in Java 8 for the first time and already removed in Java 9. 由于
java.util.logging.LogManager
和java.util.jar.Pack200.Packer
/ Unpacker
支持java.beans.PropertyChangeListener
,这导致对java.desktop
的依赖,如果保持这种方式,则这些方法是有史以来的第一个方法从标准Java API中删除,速度与Java 8中首次弃用并已在Java 9中删除一样快。
I think, if there was a way to declare a dependency to the fundamental bean classes like PropertyChangeListener
without creating the unwanted dependency to java.desktop
, the JDK developers didn't set that precedent. 我认为,如果有一种方法可以声明对像
PropertyChangeListener
类的基本bean类的依赖关系, java.desktop
创建不必要的依赖关系,那么JDK开发人员就不会设置该先例。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.