spring里的struts2在weblogic中的初始化问题

时间:2021-04-30 19:37:48
我有个项目,用到了struts2和spring,
配置struts2的action的时候,使用的是下面的方法
在struts2的配置文件中:
<action name="index" class="indexAction">
<result name="success" type="tiles">example.index</result>
        </action>
然后在spring的配置文件中:
<bean id="indexAction" class="example.action.IndexAction" scope="prototype" />

这样配置,在tomcat下面是可以正常运行的。

但是在weblogic里面,
当访问index.action的时候,会报出下面的错误
Unable to instantiate Action, indexAction, defined for '' in namespace '/'indexAction

上网翻了翻,大概的意思是weblogic和tomcat的servlet容器启动顺序不同,导致在了weblogic上面“捞”不到action。

解决办法倒是找到了,就是按照原始的action的配置方法,如下:
<action name="index" class="example.action.IndexAction">
<result name="success" type="tiles">example.index</result>
        </action>

但是因为项目已经很多action了,一个一个改有些麻烦。

请问有什么办法解决吗?
比如修改web.xml里面spring/struts2的初始化方法/顺序等东西?

谢谢

附:web.xml文件

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" 
xmlns="http://java.sun.com/xml/ns/javaee" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">

<!-- Welcome File List START -->
<welcome-file-list>
     <welcome-file>index.jsp</welcome-file>
   </welcome-file-list>
<!-- Welcome File List END -->
  
   <!-- 指定Spring用配置文件的位置  START -->
<context-param>

<param-name>contextConfigLocation</param-name>

<param-value>

<!-- ******* 具体项目需要/允许修改这个地方 ******* -->
classpath:config/applicationContext.xml,
classpath:config/applicationContext-config.xml,
classpath:config/applicationContext-tx.xml
<!-- ******* 具体项目需要/允许修改这个地方 ******* -->
</param-value>

</context-param>
   <!-- 指定Spring用配置文件的位置  END -->
  
   <!-- 指定tiles用配置文件的位置  START -->
<context-param>

<param-name>
org.apache.tiles.impl.BasicTilesContainer.DEFINITIONS_CONFIG
</param-name>

<!-- ******* tiles需要用到的配置文件位置 *******  -->
<param-value>
/WEB-INF/tiles-default.xml,
/WEB-INF/templates/example2/tiles-example.xml
</param-value>

</context-param>
   <!-- 指定tiles用配置文件的位置  END -->
  
   <context-param>
  
   <param-name>
   log4jConfigLocation
   </param-name>
  
   <param-value>
   classpath:log4j.properties
   </param-value>
  
   </context-param>

<!-- Spring容器启动Listener START  -->
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
<!-- Spring容器启动Listener END  -->

<!-- Struts2与Tiles结合用启动Listener START  -->
<listener>
<listener-class>
org.apache.struts2.tiles.StrutsTilesListener
</listener-class>
</listener>
<!-- Struts2与Tiles结合用启动Listener START  -->


<servlet>
<servlet-name>log4jConfigServlet</servlet-name>
<servlet-class>
org.springframework.web.util.Log4jConfigServlet
</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>



<!-- 在FreeMarker中使用其他JSP标签的支持 START -->
<servlet>
<servlet-name>JspSupportServlet</servlet-name>
<servlet-class>
org.apache.struts2.views.JspSupportServlet
</servlet-class>
<load-on-startup>2</load-on-startup>
</servlet>
<!-- 在FreeMarker中使用其他JSP标签的支持 END -->

<!-- Struts2主拦截器 START -->
<filter>
<filter-name>struts2</filter-name>
<filter-class>
org.apache.struts2.dispatcher.FilterDispatcher
</filter-class>
</filter>
<!-- Struts2主拦截器 END -->

<!-- Spring提供的对编码的过滤 START -->
<filter>
<filter-name>CharacterEncodingFilter</filter-name>
<filter-class>
org.springframework.web.filter.CharacterEncodingFilter
</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
<init-param>
<param-name>forceEncoding</param-name>
<param-value>true</param-value>
</init-param>
</filter>
<!-- Spring提供的对编码的过滤 START -->

<!-- 对编码的处理Mapping START -->
<filter-mapping>
<filter-name>CharacterEncodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<!-- 对编码的处理Mapping END -->

<!-- 交由Struts2处理的请求Mapping START -->
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<!-- 交由Struts2处理的请求Mapping START -->  
 
</web-app>

4 个解决方案

#1


自己顶一下。

大家都没有这个问题吗?

太奇怪了太奇怪了太奇怪了

#2


已经解决。

具体如下:

原来是
<param-value> 
<!-- ******* 具体项目需要/允许修改这个地方 ******* --> 
classpath:config/applicationContext.xml, 
classpath:config/applicationContext-config.xml, 
classpath:config/applicationContext-tx.xml 
<!-- ******* 具体项目需要/允许修改这个地方 ******* --> 
</param-value> 

是这些注释的位置导致了weblogic中不能初始化bean的问题。

解决办法也很简单。

或者挪到<param-value></param-value>标签外面


郁闷死了。为什么tomcat就没有错呢?
估计是不是weblogic和tomcat所使用的xml parser不一样有关呢?

有同样问题的同学来参考一下吧。

#3


已经解决。

具体如下:

原来是
<param-value> 
<!-- ******* 具体项目需要/允许修改这个地方 ******* --> 
classpath:config/applicationContext.xml, 
classpath:config/applicationContext-config.xml, 
classpath:config/applicationContext-tx.xml 
<!-- ******* 具体项目需要/允许修改这个地方 ******* --> 
</param-value> 

是这些注释的位置导致了weblogic中不能初始化bean的问题。

解决办法也很简单。

或者挪到<param-value></param-value>标签外面


郁闷死了。为什么tomcat就没有错呢?
估计是不是weblogic和tomcat所使用的xml parser不一样有关呢?

有同样问题的同学来参考一下吧。

#4


你的weblogic是什么版本的?

#1


自己顶一下。

大家都没有这个问题吗?

太奇怪了太奇怪了太奇怪了

#2


已经解决。

具体如下:

原来是
<param-value> 
<!-- ******* 具体项目需要/允许修改这个地方 ******* --> 
classpath:config/applicationContext.xml, 
classpath:config/applicationContext-config.xml, 
classpath:config/applicationContext-tx.xml 
<!-- ******* 具体项目需要/允许修改这个地方 ******* --> 
</param-value> 

是这些注释的位置导致了weblogic中不能初始化bean的问题。

解决办法也很简单。

或者挪到<param-value></param-value>标签外面


郁闷死了。为什么tomcat就没有错呢?
估计是不是weblogic和tomcat所使用的xml parser不一样有关呢?

有同样问题的同学来参考一下吧。

#3


已经解决。

具体如下:

原来是
<param-value> 
<!-- ******* 具体项目需要/允许修改这个地方 ******* --> 
classpath:config/applicationContext.xml, 
classpath:config/applicationContext-config.xml, 
classpath:config/applicationContext-tx.xml 
<!-- ******* 具体项目需要/允许修改这个地方 ******* --> 
</param-value> 

是这些注释的位置导致了weblogic中不能初始化bean的问题。

解决办法也很简单。

或者挪到<param-value></param-value>标签外面


郁闷死了。为什么tomcat就没有错呢?
估计是不是weblogic和tomcat所使用的xml parser不一样有关呢?

有同样问题的同学来参考一下吧。

#4


你的weblogic是什么版本的?