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)