Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring有多条错误消息_Spring_Validation - Fatal编程技术网

Spring有多条错误消息

Spring有多条错误消息,spring,validation,Spring,Validation,我假设每个使用spring的人都使用表单绑定和验证。并且您都定义了要在验证错误时显示的消息。我在我的配置中这样做: <bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource" p:basename="messages" /> 基本上,它将读取项目根文件夹中的messages.properties 但是我需要把信息放

我假设每个使用spring的人都使用表单绑定和验证。并且您都定义了要在验证错误时显示的消息。我在我的配置中这样做:

<bean id="messageSource"
        class="org.springframework.context.support.ResourceBundleMessageSource"
        p:basename="messages" />

基本上,它将读取项目根文件夹中的messages.properties

但是我需要把信息放在两个不同的文件中。因为应用程序的一部分必须是独立的。我试着在上面的一个之后添加这个:

<bean id="messageSourceAssistenza"
        class="org.springframework.context.support.ResourceBundleMessageSource"
        p:basename = "com.mypackage.other.assistenzamessages.properties"
        />

但它根本无法解析这些消息。如何解决此问题?

您应该能够使用接受基名称数组的:

设置一个基名称数组,每个基名称 以下ResourceBundle约定: 基本上,一个完全合格的 类路径位置。如果没有 包含包限定符(例如 org.mypackage),它将被解决 从类路径根

关联的资源束将 解析时要按顺序进行检查 消息代码。请注意这条消息 以前资源中的定义 bundle将在稍后的版本中覆盖这些包 捆绑,由于顺序查找

示例配置如下所示:

<bean id="messageSource"
    class="org.springframework.context.support.ResourceBundleMessageSource">
    <property name="basenames">
        <list>
            <value>messages_1</value>
            <value>messages_2</value>
            ...
            <value>messages_n</value>
        </list>
    </property>
</bean>

信息1
信息2
...
信息
您应该能够使用接受基名称数组的:

设置一个基名称数组,每个基名称 以下ResourceBundle约定: 基本上,一个完全合格的 类路径位置。如果没有 包含包限定符(例如 org.mypackage),它将被解决 从类路径根

关联的资源束将 解析时要按顺序进行检查 消息代码。请注意这条消息 以前资源中的定义 bundle将在稍后的版本中覆盖这些包 捆绑,由于顺序查找

示例配置如下所示:

<bean id="messageSource"
    class="org.springframework.context.support.ResourceBundleMessageSource">
    <property name="basenames">
        <list>
            <value>messages_1</value>
            <value>messages_2</value>
            ...
            <value>messages_n</value>
        </list>
    </property>
</bean>

信息1
信息2
...
信息