【问题标题】:Exception without using velocity in Struts 2 while parsing struts.xml解析struts.xml时在Struts 2中不使用速度的异常
【发布时间】:2013-04-23 23:24:23
【问题描述】:

这是我的struts.xml 文件

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd">
<struts>

<constant name="struts.devMode" value="true" /> 
<constant name="struts.enable.DynamicMethodInvocation" value="true"/>
<constant name="struts.objectFactory" value="org.apache.struts2.spring.StrutsSpringObjectFactory" />  

<package name="Authentiate" extends="struts-default">

<global-results>

<result name="error">/error.jsp</result>

</global-results>

<action name="loginAuthenticate*" class="com.authenticate.actions.LoginAuthenticate" method="{1}">

<result name="success">/welcome.jsp</result>
<result name="error">/error.jsp</result>
<result name="redirectRegister" type="redirect">/registration.jsp</result>

</action>

</package>

我没有使用速度模板,但出现以下错误。

java.lang.RuntimeException: com.opensymphony.xwork2.inject.DependencyException: com.opensymphony.xwork2.inject.ContainerImpl$MissingDependencyException: No mapping found for dependency [type=org.apache.struts2.views.velocity.VelocityManager, name='default'] in public void org.apache.struts2.osgi.OsgiConfigurationProvider.setVelocityManager(org.apache.struts2.views.velocity.VelocityManager). - Class: com.opensymphony.xwork2.inject.ContainerBuilder

【问题讨论】:

  • 什么版本的 Struts2?
  • 你在使用 OSGi 包吗?也许你添加了太多的罐子;-)

标签: java jsp struts2 velocity struts-config


【解决方案1】:

首先尝试使用默认类型dispatcher明确指出结果类型:

<result name="success" type="dispatcher">/welcome.jsp</result>
<result name="error" type="dispatcher">/error.jsp</result>
<result name="redirectRegister" type="redirect">/registration.jsp</result>

如果这没有帮助,看起来有一些 struts 依赖项无法解决。根据 apache 的 bugtracker 中的 this bug,您应该将 VelocityManager bean 添加到您的 struts.xml

<bean class="org.apache.struts2.views.velocity.VelocityManager" name="default" optional="true" />

【讨论】:

    【解决方案2】:

    这是真的奇怪的错误。通过从依赖项中删除 spring-struts jar 来修复。

    如果您没有在结果中使用速度模板,则无需将速度添加为依赖项。默认情况下,Struts2 使用 Freemarker 模板。

    如果您的服务器未使用 JMX,则可能看不到错误,但如果您在 JMX enabled appserver like JBOSS 中运行,则可能会出现错误。

    【讨论】:

      猜你喜欢
      • 2015-08-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-01-24
      • 1970-01-01
      • 2014-02-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多