Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/13.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 web.xml init params包含多个param值_Spring_Jakarta Ee_Parameters - Fatal编程技术网

Spring web.xml init params包含多个param值

Spring web.xml init params包含多个param值,spring,jakarta-ee,parameters,Spring,Jakarta Ee,Parameters,我想问一下,是否可以在中添加多个参数值 <param-value> 标签 例如: <init-param> <param-name>contextClass</param-name> <param-value>org.springframework.web.context.support.AnnotationConfigWebApplicationContext, org.springfra

我想问一下,是否可以在中添加多个参数值

<param-value>

标签

例如:

<init-param>
        <param-name>contextClass</param-name>
            <param-value>org.springframework.web.context.support.AnnotationConfigWebApplicationContext, org.springframework.web.context.support.XmlWebApplicationContext</param-value>
</init-param>

上下文类
org.springframework.web.context.support.AnnotationConfigWebApplicationContext,org.springframework.web.context.support.XmlWebApplicationContext

谢谢大家!

您所做的是正确的,应该用逗号分隔,,作为delimeter

<context-param>
  <param-name>contextClass</param-name>
  <param-value>ex1.com,ex2.com,.....</param-value>
</context-param>

上下文类
ex1.com,ex2.com,。。。。。
或者你可以把它们放在下面,让它更具可读性

<context-param>
    <param-name>contextClass</param-name>
    <param-value> 
        org.springframework.web.context.support.AnnotationConfigWebApplicationContext
       org.springframework.web.context.support.XmlWebApplicationContext
    </param-value>
</context-param>

上下文类
org.springframework.web.context.support.AnnotationConfigWebApplicationContext
org.springframework.web.context.support.XmlWebApplicationContext

应按预期工作

您可以在
中使用多个值,但前提是该方法可以接受值数组

例1:

<init-param>
    <param-name>suffixExclusions</param-name>
    <param-value>.jsp, .ftl</param-value>
</init-param>
原因方法只需要一个布尔值

UPD


根据预期,参数
contextClass

中只有一个类依赖于该参数。读取该值的代码可以用他们喜欢的任何方式解析它。这意味着你没有办法说“我想传递多个值”,也没有标准

Spring不支持多个类作为
contextClass
。该类用于构建应用程序上下文,Java类始终只能有一个具体类型。如果不指定参数,Spring将使用
XmlWebApplicationContext
作为默认值。如果使用带注释的Java配置,则需要将其替换为
org.springframework.web.context.support.AnnotationConfigWebApplicationContext

配置Spring的类需要使用
contextConfigLocation
指定,它采用文件或类名的列表(逗号和/或空格分隔)


有关详细信息,请参阅文档:和

我想您指的是
contextConfigLocation
contextClass
是用于构建应用程序上下文的类,它只能是一种类型。非常感谢您的回答!
<init-param>
    <param-name>forceEncoding</param-name>
    <param-value>true, false</param-value>
</init-param>
 org.springframework.beans.TypeMismatchException: Failed to convert property value of type 'java.lang.String' to required type 'boolean' for property 'forceEncoding'; nested exception is java.lang.IllegalArgumentException: Invalid boolean value [true, false]
[INFO] [talledLocalContainer]   at org.springframework.beans.BeanWrapperImpl.convertIfNecessary(BeanWrapperImpl.java:480)
[INFO] [talledLocalContainer]   at org.springframework.beans.BeanWrapperImpl.convertForProperty(BeanWrapperImpl.java:512)
[INFO] [talledLocalContainer]   at org.springframework.beans.BeanWrapperImpl.setPropertyValue(BeanWrapperImpl.java:1120)