【问题标题】:how do i configure applicationcontext.xml in eclipse我如何在eclipse中配置applicationcontext.xml
【发布时间】:2012-04-05 19:17:51
【问题描述】:

当我将 struts.xml 放入 web-inf 时,它显示错误......当我放入 src 文件夹时,它工作正常。(在 web-inf 中是 applicationcontext.xml)

(在(src 文件夹或 src/resources)中的 struts.xml)当我将 applicationcontext.xml 放在 src 文件夹中时............这是说无法在 web-inf 中找到 applicationcontext.xml文件夹............它无法执行。

我如何配置以便 eclipse 可以找到 struts.xml 或 applicationcontext.xml 的路径,以便无论我放在哪里都应该检测到它。

web.xml中的代码如下。

<filter>
        <filter-name>struts2</filter-name>
        <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
    </filter>
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>
    <filter-mapping>
        <filter-name>struts2</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
    <welcome-file-list>
        <welcome-file>index.jsp</welcome-file>
    </welcome-file-list>
</web-app>

谢谢大家。

【问题讨论】:

  • 我不认为您可以配置 eclipse,以便无论您保留 struts.xml 或 applicationcontext.xml,它都会被接受。最好将 struts.xml 保存在 src 文件夹中,将 applicationcontext.xml 保存在 web-inf 中。 kandarp 给出的答案将有助于为 spring 指定 applicationcontext.xml 的路径。我不认为这样的东西可用于 struts2。

标签: java eclipse spring struts2


【解决方案1】:

如果你放入 web-inf 文件夹

<context-param>
  <param-name>contextConfigLocation</param-name>
  <param-value>/WEB-INF/applicationContext*.xml</param-value>
</context-param>

如果你放入 src/resource 文件夹

<context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>classpath*:applicationContext*.xml</param-value>
    </context-param>

如果您在修改后收到类似以下链接的错误,还有一件事。

http://www.bpjava.net/Struts2_Configuration_Plugin/config-browser/showBeans.action

最后给出解决方案。

或者您可以执行以下操作。

在struts.xml中&lt;constant name="struts.devMode" value="false" /&gt;

【讨论】:

    【解决方案2】:

    在 web.xml 中配置上下文参数,如下所示:

    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value> /WEB-INF/application-context.xml</param-value>
      </context-param>
    

    并将您的 application-context.xml 放在 WEB-INF 文件夹中。

    【讨论】:

    • we.xml 中有以下条目吗? xyzorg.springframework.web.servlet.DispatcherServlet1xyz/*org .springframework.web.context.ContextLoaderListener 注意:代替 xyz,请指定您自己的 servlet 映射名称
    • 请浏览下面的链接。他们清楚地定义了我们如何在我们的应用程序中配置 struts 和 spring。 static.springsource.org/spring/docs/2.5.x/reference/…
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-09-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-05-25
    • 1970-01-01
    相关资源
    最近更新 更多