You need to enable JavaScript to run this app. Hybris本地化EnumType时出现IllegalStateException异常如何解决
优惠活动
大模型
产品
解决方案
定价
更多

Hybris本地化EnumType时出现IllegalStateException异常如何解决

问题解决方案

错误根因

报错的核心原因有两点:

  • 自定义枚举类型不支持直接添加localized:前缀修饰,你配置的localized:ServiceType属于非法类型
  • 当前ServiceType枚举的定义顺序在Service itemtype之后,系统从上到下解析xml时,加载Service的serviceType属性时,ServiceType还未被注册,也会触发类型不存在的错误

修复步骤

  1. 调整items.xml中定义顺序,将ServiceType枚举的定义放在Service itemtype之前
  2. 修改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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.16 18:54:07