Hybris本地化EnumType时出现IllegalStateException异常如何解决
问题解决方案
错误根因
报错的核心原因有两点:
- 自定义枚举类型不支持直接添加
localized:前缀修饰,你配置的localized:ServiceType属于非法类型 - 当前
ServiceType枚举的定义顺序在Serviceitemtype之后,系统从上到下解析xml时,加载Service的serviceType属性时,ServiceType还未被注册,也会触发类型不存在的错误
修复步骤
- 调整items.xml中定义顺序,将
ServiceType枚举的定义放在Serviceitemtype之前 - 修改Service的serviceType属性的type值,删除
localized:前缀,改为ServiceType
修正后的配置代码如下:
<!-- 先定义枚举 --> <enumtype code="ServiceType" autocreate="true" generate="true" dynamic="true"> <value code="Basic"></value> <value code="BasicOnsite"></value> <value code="Advanced"></value> </enumtype> <!-- 再定义Service itemtype --> <typegroup name="Services"> <itemtype code="Service" autocreate="true" generate="true"> <deployment typecode="23456" table="Service"/> <attributes> <attribute qualifier="code" type="localized:java.lang.String" autocreate="true" generate="true"> <persistence type="property"/> <description>Service Code</description> <modifiers unique="true" read="true" write="true"/> </attribute> <!-- 此处已删除localized前缀 --> <attribute qualifier="serviceType" type="ServiceType" autocreate="true" generate="true"> <persistence type="property"/> <description>Service Type</description> <modifiers read="true" write="true"/> </attribute> <attribute qualifier="years" type="localized:java.lang.Integer" autocreate="true" generate="true"> <persistence type="property"/> <description>Service Years</description> <modifiers read="true" write="true"/> </attribute> </attributes> </itemtype> </typegroup>
补充说明
你已经在properties文件中配置的枚举值本地化规则会自动生效,系统在不同语言场景下会自动读取对应语言的枚举值展示,不需要通过给属性加localized前缀实现枚举的多语言支持。
内容的提问来源于stack exchange,提问作者user15948501
相关产品推荐
相关产品推荐

