亚咪吧 关注:15贴子:538
  • 2回复贴,共1

struts2的加载顺序以及常见常量

只看楼主收藏回复

struts2加载常量的顺序
struts-default.xml
struts-plugin.xml
struts.xml
struts.properties
web.xml
后面的会覆盖掉前面的常量,最好在struts.xml中定义 怎么由.action改为.do
<constant name="struts.action.extension" value="do"/>
do或action
<constant name="struts.action.extension" value="do,action"/>
truts2用来指定默认编码的
<constant name="struts.i18n.encoding" value="UTF-8"/> 改变常量后不许重启服务器
<constant name="struts.configuration.xml.reload" value="true"/>
系统默认为false
便于排错,打印出更详细的错误信息
<constant name="struts.devMode" value="true"> 设置浏览器是否缓存静态内容,默认为TRUE 开发阶段最好关闭
<constant name="struts.server.static.browserCache" valur="false"/> 默认的视图主题
<constant name="struts.ui.theme" value="simple"/> 与spring集成时,指定spring负责action对象的创建
<struts name="struts.objectFactory" value="spring"/> 上传文件大小限制
<struts name="struts.multipart.maxSize" value="10241024"/>


IP属地:福建1楼2012-12-29 15:21回复
    ?<struts>
    <bean type="com.opensymphony.xwork2.ObjectFactory" name="spring" class="org.apache.struts2.spring.StrutsSpringObjectFactory" />
    <!-- Make the Spring object factory the automatic default -->
    <constant name="struts.objectFactory" value="spring" /><package name="spring-default">
    <interceptors>
    <interceptor name="autowiring" class="com.opensymphony.xwork2.spring.interceptor.ActionAutowiringInterceptor"/>
    <interceptor name="sessionAutowiring" class="org.apache.struts2.spring.interceptor.SessionContextAutowiringInterceptor"/>
    </interceptors>
    </package>
    </struts
    注意<constant name="struts.objectFactory" value="spring"/>
    这里它将框架常量struts.objectFactory覆盖了,设置为”spring”,其实这里是使用了缩写,我们可以写全称:org.apache.struts2.spring.StrutsSpringObjectFactory。这个缩写的”spring”是和bean配置中的name属性相对应的。默认情况下所有由框架创建的对象都是由ObjectFactory实例化的,ObjectFactory提供了与其它IoC容器如Spring、Pico等集成的方法。覆盖这个ObjectFactory的类必须继承ObjectFactory类或者它的任何子类,并且要带有一个不带参数的构造方法。在这里我们用org.apache.struts2.spring.StrutsSpringObjectFactory代替了默认的ObjectFactory。
    此外,上面我们说了,如果action不是使用Spring ObjectFactory创建的话,插件提供了两个拦截器来自动装配action,默认情况下框架使用的自动装配策略是name,也就是说框架会去Spring中寻找与action属性名字相同的bean,可选的装配策略还有:type、auto、constructor,我们可以通过常量struts.objectFactory.spring.autoWire来进行设置。
    这样的话,我们就可以在Action中使用Spring IOC中注入的Bean了。其实这是webwork早有的扩展包里的功能。呵呵。换成strut2.0了还是得说一下。
    有了上面的配置文件我们就可以把Spring2.0 和 struts2.0 结合起来了。


    IP属地:福建3楼2012-12-29 15:25
    回复
      struts.freemarker.manager.classname 该属性指定Struts 2使用的FreeMarker管理器。该属性的默认值是org.apache.struts2.views.freemarker.FreemarkerManager,这是Struts 2内建的FreeMarker管理器。
      struts.freemarker.wrapper.altMap该属性只支持true和false两个属性值,默认值是true。通常无需修改该属性值。
      struts.xslt.nocache 该属性指定XSLT Result是否使用样式表缓存。当应用处于开发阶段时,该属性通常被设置为true;当应用处于产品使用阶段时,该属性通常被设置为false。
      struts.configuration.files 该属性指定Struts 2框架默认加载的配置文件,如果需要指定默认加载多个配置文件,则多个配置文件的文件名之间以英文逗号(,)隔开。该属性的默认值为struts-default.xml,struts-plugin.xml,struts.xml,看到该属性值,读者应该明白为什么Struts 2框架默认加载struts.xml文件了。
      ?
      详解struts2-plugin.xml中spring
      ?<struts><bean type="com.opensymphony.xwork2.ObjectFactory" name="spring" class="org.apache.struts2.spring.StrutsSpringObjectFactory" />
      <!-- Make the Spring object factory the automatic default --><constant name="struts.objectFactory" value="spring" /><package name="spring-default"><interceptors><interceptor name="autowiring" class="com.opensymphony.xwork2.spring.interceptor.ActionAutowiringInterceptor"/><interceptor name="sessionAutowiring" class="org.apache.struts2.spring.interceptor.SessionContextAutowiringInterceptor"/></interceptors></package> </struts
      注意<constant name="struts.objectFactory" value="spring"/>
      这里它将框架常量struts.objectFactory覆盖了,设置为”spring”,其实这里是使用了缩写,我们可以写全称:org.apache.struts2.spring.StrutsSpringObjectFactory。这个缩写的”spring”是和bean配置中的name属性相对应的。默认情况下所有由框架创建的对象都是由ObjectFactory实例化的,ObjectFactory提供了与其它IoC容器如Spring、Pico等集成的方法。覆盖这个ObjectFactory的类必须继承ObjectFactory类或者它的任何子类,并且要带有一个不带参数的构造方法。在这里我们用org.apache.struts2.spring.StrutsSpringObjectFactory代替了默认的ObjectFactory。
      此外,上面我们说了,如果action不是使用Spring ObjectFactory创建的话,插件提供了两个拦截器来自动装配action,默认情况下框架使用的自动装配策略是name,也就是说框架会去Spring中寻找与action属性名字相同的bean,可选的装配策略还有:type、auto、constructor,我们可以通过常量struts.objectFactory.spring.autoWire来进行设置。
      这样的话,我们就可以在Action中使用Spring IOC中注入的Bean了。其实这是webwork早有的扩展包里的功能。呵呵。换成strut2.0了还是得说一下。
      有了上面的配置文件我们就可以把Spring2.0 和 struts2.0 结合起来了。


      IP属地:福建5楼2012-12-29 15:29
      回复