Struts2+Spring 集成

发布于 2024-12-24 03:22:49 字数 1990 浏览 4 评论 0原文

尝试使用 Maven 将 Struts2 和 Spring 集成到我的应用程序中。我已将与 Spring-web、Spring、Struts2-spring 插件相关的所有依赖项放入 Pom 文件中

<!-- Spring framework --> 
     <dependency>
 <groupId>org.springframework</groupId>
 <artifactId>spring</artifactId>
 <type>jar</type>
 <version>2.5.6</version>
 </dependency>
 <dependency>
 <groupId>org.springframework</groupId>
 <artifactId>spring-web</artifactId>
 <version>2.5.6</version>
 </dependency>
 <dependency>
 <groupId>org.apache.struts</groupId>
 <artifactId>struts2-spring-plugin</artifactId>
 <version>2.2.3</version>
 </dependency>

,并且在 Web.xml 文件中包含以下内容,

<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> 
    <listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
      </listener>  

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

当我使用 Maven 运行时生成 war 文件以及当我部署我的 war 时我的服务器(glassfish)中的文件错误消息显示为

"Error An error has occurred
Error occurred during deployment: Exception while loading the app : java.lang.IllegalStateException: ContainerBase.addChild: start: org.apache.catalina.LifecycleException: java.lang.NoClassDefFoundError: Could not initialize class org.springframework.web.context.ContextLoader. Please see server.log for more details."

所以任何人请帮助我解决这个问题。

Trying to integrate Struts2 and Spring in my application using Maven. I have placed all the dependencies in Pom file which is related to Spring-web,Spring,Struts2-spring plugin

<!-- Spring framework --> 
     <dependency>
 <groupId>org.springframework</groupId>
 <artifactId>spring</artifactId>
 <type>jar</type>
 <version>2.5.6</version>
 </dependency>
 <dependency>
 <groupId>org.springframework</groupId>
 <artifactId>spring-web</artifactId>
 <version>2.5.6</version>
 </dependency>
 <dependency>
 <groupId>org.apache.struts</groupId>
 <artifactId>struts2-spring-plugin</artifactId>
 <version>2.2.3</version>
 </dependency>

and i have included the following in Web.xml file,

<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> 
    <listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
      </listener>  

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

When i running using Maven war file is generated and when i deploying my war file in my server(glassfish) error message is showing like

"Error An error has occurred
Error occurred during deployment: Exception while loading the app : java.lang.IllegalStateException: ContainerBase.addChild: start: org.apache.catalina.LifecycleException: java.lang.NoClassDefFoundError: Could not initialize class org.springframework.web.context.ContextLoader. Please see server.log for more details."

So anyone please help me to fix this issue.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

雨夜星沙 2024-12-31 03:22:50

ContextLoader 位于 Spring-web jar 中。该错误是因为找不到此类定义。检查您的 .m2 文件夹中是否存在此依赖项。

如果由于某种原因没有自动下载,请使用 mvn install:install 命令手动安装。有关更多信息,请参阅 Maven Spring Hibernate 项目中的 Jars 问题可能的解决方案。

尝试

  1. 执行 mvn package 并查看 Spring jar 是否在您的 war 中

  2. 执行 mvn eclipse:eclipse 后,刷新 eclipse ,清理你的 Eclipse 工作区 - 项目 - 清理(勾选自动构建)

打开.classpath 文件并检查类似的条目

,或右键单击项目 --> 属性 --> java 构建路径 --> 库,然后查看 spring-web jar 是否在那里。

  1. 打开 .m2 存储库并查看 jar 是否在存储库内 - 如果没有,请执行安装:安装

  2. 执行 mvn dependency:tree 并查看 jar 是否出现。

这就是我能建议的

ContextLoader is in the Spring-web jar . The error is because this class definition could not be found . Check if this dependency is present in your .m2 folder .

If it is not downloaded automatically for some reason manually install it using the mvn install:install command . See Jars Issues in Maven Spring Hibernate Project for more probable solutions .

Try

  1. Doing a mvn package and see if the Spring jar is in your war

  2. After doing mvn eclipse:eclipse , refresh the eclipse ,clean your eclipse workspace - project- clean (Tick Build automatically)

open up the .classpath file and check for an entry similar to

or right click the project -->properties-->java build path-->libraries and see if the spring-web jar is there .

  1. Open up the .m2 repo and see if the jar is inside the repo - If not do a install:install

  2. do an mvn dependency:tree and see if the jar comes up .

That's pretty much what I can suggest

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文