简体   繁体   English

解析 struts.xml 时在 Struts 2 中不使用速度的异常

[英]Exception without using velocity in Struts 2 while parsing struts.xml

Here is my struts.xml file这是我的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>

I haven't used velocity templates but I am getting the following error.我没有使用速度模板,但出现以下错误。

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

First of all try to point result type explicitly using default type dispatcher :首先尝试使用默认类型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>

If this doesn't help, it looks like there are some struts dependencies that can't be resolved.如果这没有帮助,则似乎存在一些无法解决的 struts 依赖项。 According to this bug at apache's bugtracker you should add VelocityManager bean to your struts.xml :根据 apache 的 bugtracker 上的这个错误,您应该将VelocityManager bean 添加到您的struts.xml

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

This is really weird error.真是一个奇怪的错误。 Fixed by removing spring-struts jar from dependencies.通过从依赖项中删除spring-struts jar 来修复。

Velocity is not necessary to add as a dependency if you are not using velocity templates in your results.如果您没有在结果中使用速度模板,则无需将速度添加为依赖项。 By default Struts2 uses Freemarker templates.默认情况下,Struts2 使用 Freemarker 模板。

Errors may not seen if your server not utilizing JMX, but if you run in JMX enabled appserver like JBOSS it might raise.如果您的服务器未使用 JMX,则可能不会出现错误,但如果您在启用 JMX 的应用服务器(如 JBOSS)中运行,则可能会出现错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM