一、struts2配置文件加载顺序为:
struts-default.xml-->struts=plugin.xml-->struts.xml-->struts.properties-->web.xml
struts2的配置文件不止这些,但是常用的就这么多,其中如果在多个配置文件中配置了相同的属性,后面的配置文件配置的属性会覆盖前面的配置。一般采用在struts.xml中配置Action的映射及其包含的result定义、struts.properties定义了struts2框架的大量属性,开发者可以通修改这些属性来满足应用的需求。
如果想要深入探究struts2的配置文件加载顺序可以对struts的filter过滤器进行源码分析:
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
二、struts.properties配置详解
struts.properties文件是一个标准的Properties文件,该文件包含了一系列的key-value对象,每个key就是一个Struts 2属性,该key对应的value就是一个Struts 2属性值。
struts.properties文件通常放在Web应用的WEB-INF/classes路径下。实际上,只要将该文件放在Web应用的CLASSPATH路径下,Struts 2框架就可以加载该文件。
现在的问题是,struts.properties文件的哪些key是有效的?即struts.properties文件里包含哪些属性是有效的Struts 2属性。下面列出了可以在struts.properties中定义的Struts 2属性。
### Struts default properties
###(can be overridden by a struts.properties file in the root of the classpath)
###该属性指定加载Struts2配置文件的配置文件管理器。该属性的默认值是org.apache.Struts2.config.DefaultConfig###uration,这是Struts 2默认的配 置文件管理器。如果需要实现自己的配置管理器,开发者则可以实现一个实现Configu###ration接口的类,该类可以自己加载Struts 2配置文件
# struts.configuration=org.apache.struts2.config.DefaultConfiguration
### 指定Web应用的默认Locale
struts.locale=utf-8
struts.custom.i18n.resources =language
###指定Web应用的默认编码集。该属性对于处理中文请求参数非常有用,对于获取中文请求参数值,应该将该属性值设置为GB### K或者GB2312。
struts.i18n.encoding=utf-8
### 指定Struts 2默认的ObjectFactory Bean,该属性默认值是spring
struts.objectFactory = spring
### 指定Spring框架的自动装配模式,该属性的默认值是name,即默认根据Bean的name属性自动装配
struts.objectFactory.spring.autoWire = name
### 该属性指定整合Spring框架时,是否缓存Bean实例,该属性只允许使用true和false两个属性值,它的默认值是true。#### 通常不建议修改该属性值
struts.objectFactory.spring.useClassCache = true
### 该属性指定Struts 2的类型检测机制,通常支持tiger和notiger两个属性值
#struts.objectTypeDeterminer = tiger
#struts.objectTypeDeterminer = notiger
### 该属性指定处理multipart/form-data的MIME类型(文件上传)请求的框架,该属性支持cos、pell和jakarta等属性#### 值,即分别对应使用cos的文件上传框架、pell上传及common-fileupload文件上传框架。该属性的默认值为jakarta
# struts.multipart.parser=cos
# struts.multipart.parser=pell
struts.multipart.parser=jakarta
### 该属性指定上传文件的临时保存路径,该属性的默认值是javax.servlet.context.tempdir
struts.multipart.saveDir=javax.servlet.context.tempdir
###该属性指定Struts 2文件上传中整个请求内容允许的最大字节数
struts.multipart.maxSize=10485760000
### 该属性指定Struts 2应用加载用户自定义的属性文件,该自定义属性文件指定的属性不会覆盖struts.properties文件### 中指定的属性。如果需要加载多个自定义属性文件,多个自定义属性文件的文件名以英文逗号(,)隔开
# struts.custom.properties=application,org/apache/struts2/extension/custom
### 指定将HTTP请求映射到指定Action的映射器,Struts 2提供了默认的映射器:org.apache.struts2.dispatcher.map### per.DefaultActionMapper。默认映射器根据请求的前缀与Action的name属性完成映射
#struts.mapper.class=org.apache.struts2.dispatcher.mapper.DefaultActionMapper
### 该属性指定需要Struts 2处理的请求后缀,该属性的默认值是action,即所有匹配*.action的请求都由Struts 2处理### 。如果用户需要指定多个请求后缀,则多个后缀之间以英文逗号(,)隔开
struts.action.extension=do,action,,
### Used by FilterDispatcher
### If true then Struts serves static content from inside its jar.
### If false then the static content must be available at <context_path>/struts
struts.serve.static=true
### Used by FilterDispatcher
### This is good for development where one wants changes to the static content be
### fetch on each request.
### NOTE: This will only have effect if struts.serve.static=true
### If true -> Struts will write out header for static contents such that they will
### be cached by web browsers (using Date, Cache-Content, Pragma, Expires)
### headers).
### If false -> Struts will write out header for static contents such that they are
### NOT to be cached by web browser (using Cache-Content, Pragma, Expires
### headers)
struts.serve.static.browserCache=false
### Set this to false if you wish to disable implicit dynamic method invocation
### via the URL request. This includes URLs like foo!bar.action, as well as params
### like method:bar (but not action:foo).
### An alternative to implicit dynamic method invocation is to use wildcard
### mappings, such as <action name="*/*" method="{2}" class="actions.{1}">
struts.enable.DynamicMethodInvocation = true
### Set this to true if you wish to allow slashes in your action names. If false,
### Actions names cannot have slashes, and will be accessible via any directory
### prefix. This is the traditional behavior expected of WebWork applications.
### Setting to true is useful when you want to use wildcards and store values
### in the URL, to be extracted by wildcard patterns, such as
### <action name="*/*" method="{2}" class="actions.{1}"> to match "/foo/edit" or
### "/foo/save".
struts.enable.SlashesInActionNames = false
### use alternative syntax that requires %{} in most places
### to evaluate expressions for String attributes for tags
struts.tag.altSyntax=true
### when set to true, Struts will act much more friendly for developers. This
### includes:
### - struts.i18n.reload = true
### - struts.configuration.xml.reload = true
### - raising various debug or ignorable problems to errors
### For example: normally a request to foo.action?someUnknownField=true should
### be ignored (given that any value can come from the web and it
### should not be trusted). However, during development, it may be
### useful to know when these errors are happening and be told of
### them right away.
struts.devMode = true
### when set to true, resource bundles will be reloaded on _every_ request.
### this is good during development, but should never be used in production
struts.i18n.reload=false
### Standard UI theme
### Change this to reflect which path should be used for JSP control tag templates by default
struts.ui.theme=xhtml
struts.ui.templateDir=my_template
#sets the default template type. Either ftl, vm, or jsp
struts.ui.templateSuffix=ftl
### Configuration reloading
### This will cause the configuration to reload struts.xml when it is changed
struts.configuration.xml.reload=false
### Location of velocity.properties file. defaults to velocity.properties
struts.velocity.configfile = velocity.properties
### Comma separated list of VelocityContext classnames to chain to the StrutsVelocityContext
struts.velocity.contexts =
### Location of the velocity toolbox
struts.velocity.toolboxlocation=
### used to build URLs, such as the UrlTag
struts.url.http.port = 80
struts.url.https.port = 443
### possible values are: none, get or all
struts.url.includeParams = get
### Load custom default resource bundles
# struts.custom.i18n.resources=testmessages,testmessages2
### workaround for some app servers that don't handle HttpServletRequest.getParameterMap()
### often used for WebLogic, Orion, and OC4J
struts.dispatcher.parametersWorkaround = false
### configure the Freemarker Manager class to be used
### Allows user to plug-in customised Freemarker Manager if necessary
### MUST extends off org.apache.struts2.views.freemarker.FreemarkerManager
#struts.freemarker.manager.classname=org.apache.struts2.views.freemarker.FreemarkerManager
### Enables caching of FreeMarker templates
### Has the same effect as copying the templates under WEB_APP/templates
struts.freemarker.templatesCache=false
### Enables caching of models on the BeanWrapper
struts.freemarker.beanwrapperCache=false
### See the StrutsBeanWrapper javadocs for more information
struts.freemarker.wrapper.altMap=true
### configure the XSLTResult class to use stylesheet caching.
### Set to true for developers and false for production.
struts.xslt.nocache=false
### A list of configuration files automatically loaded by Struts
struts.configuration.files=struts-default.xml,struts-plugin.xml,struts.xml
### Whether to always select the namespace to be everything before the last slash or not
struts.mapper.alwaysSelectFullNamespace=false