struts全包导入问题

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

<listener> 
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> 
</listener> 

<filter> 
<filter-name>struts2</filter-name> 
<filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class> 
</filter> 

<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> 

在WEB-INF下新建applicationContext.xml: 
<?xml version="1.0" encoding="UTF-8"?> 
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd"> 
<beans> 

</beans> 

src下新建struts.xml: 
<?xml version="1.0" encoding="UTF-8"?> 
<!DOCTYPE struts PUBLIC "//Apache Software Foundation//DTD Struts Configuration 2.0//EN" "http://struts.apache.org/dtds/struts-2.0.dtd"> 
<struts> 
<package name="default" namespace="/" extends="struts-default"> 
<action name="HelloWorld" class="com.ghl.HelloWorld"> 
<result name="success">/success.jsp</result> 
</action> 
</package> 
<include file="user.xml"></include> 
</struts>   

src下新建com.ghl.HelloWorld.java: 
package com.ghl; 

import com.opensymphony.xwork2.ActionSupport; 
import com.opensymphony.xwork2.util.logging.Logger; 
import com.opensymphony.xwork2.util.logging.LoggerFactory; 

public class HelloWorld extends ActionSupport{ 
/** 

*/ 
private static final long serialVersionUID = -6452565149473931988L; 
Logger log = LoggerFactory.getLogger(HelloWorld.class); 

@Override 
public String execute() throws Exception { 
log.info("execute"); 
return SUCCESS; 


@Override 
public void validate() { 
log.info("validate"); 



部署在tomcat下,问题: 
警告: Unable to load config class org.apache.struts2.jsf.FacesSetupInterceptor at interceptor - jar:file:/D:/ghl/apache-tomcat-6.0.20/wtpwebapps/SS/WEB-INF/lib/struts2-jsf-plugin-2.1.8.1.jar!/struts-plugin.xml:35:97 probably due to a missing jar, which might be fine if you never plan to use the jsfSetup interceptor 
2010-6-10 14:14:21 com.opensymphony.xwork2.util.logging.commons.CommonsLogger error 
严重: Actual exception 
Could not load class org.apache.struts2.jsf.FacesSetupInterceptor. Perhaps it exists but certain dependencies are not available? - interceptor - jar:file:/D:/ghl/apache-tomcat-6.0.20/wtpwebapps/SS/WEB-INF/lib/struts2-jsf-plugin-2.1.8.1.jar!/struts-plugin.xml:35:97 
at com.opensymphony.xwork2.ObjectFactory.buildInterceptor(ObjectFactory.java:202) 

解决: 
删除:struts2-jsf-plugin-2.1.8.1.jar 

问题: 
警告: Unable to load config class org.apache.struts2.portlet.interceptor.PortletAwareInterceptor at interceptor - jar:file:/D:/ghl/apache-tomcat-6.0.20/wtpwebapps/SS/WEB-INF/lib/struts2-portlet-plugin-2.1.8.1.jar!/struts-plugin.xml:48:114 probably due to a missing jar, which might be fine if you never plan to use the portletAware interceptor 
2010-6-10 14:16:37 com.opensymphony.xwork2.util.logging.commons.CommonsLogger error 
严重: Actual exception 
Could not load class org.apache.struts2.portlet.interceptor.PortletAwareInterceptor. Perhaps it exists but certain dependencies are not available? - interceptor - jar:file:/D:/ghl/apache-tomcat-6.0.20/wtpwebapps/SS/WEB-INF/lib/struts2-portlet-plugin-2.1.8.1.jar!/struts-plugin.xml:48:114 
at com.opensymphony.xwork2.ObjectFactory.buildInterceptor(ObjectFactory.java:202) 

解决 
删除:struts2-portlet-plugin-2.1.8.1.jar 

问题: 
严重: Dispatcher initialization failed 
java.lang.NullPointerException 
at org.apache.struts2.osgi.OsgiConfigurationProvider.init(OsgiConfigurationProvider.java:70) 
解决: 
删除:struts2-osgi-plugin-2.1.8.1.jar 


问题: 
严重: Dispatcher initialization failed 
java.lang.RuntimeException: java.lang.RuntimeException: com.opensymphony.xwork2.inject.DependencyException: com.opensymphony.xwork2.inject.ContainerImpl$MissingDependencyException: No mapping found for dependency [type=java.lang.String, name='actionPackages'] in public void org.apache.struts2.config.ClasspathPackageProvider.setActionPackages(java.lang.String). 
at com.opensymphony.xwork2.inject.ContainerBuilder$4.create(ContainerBuilder.java:132) 
解决: 
修改web.xml: 
<filter> 
<filter-name>struts2</filter-name> 
<filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class> 
      <init-param> 
<param-name>actionPackages</param-name> 
<param-value>com.ghl</param-value> 
</init-param> 
</filter> 


问题: 
警告: Could not find action or result 
There is no Action mapped for namespace / and action name HelloWorld. - [unknown location] 
at com.opensymphony.xwork2.DefaultActionProxy.prepare(DefaultActionProxy.java:178) 
解决: 
把 struts.xml文件放到WEB-INF/classes目录下 

问题: 
java.lang.NoSuchMethodException: com.ghl.HelloWorld.index() 
java.lang.Class.getMethod(Unknown Source) 
org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor.getActionMethod(AnnotationValidationInterceptor.java:75)
解决: 
HelloWorld.java中追加方法: 
public String index(){ 
log.info("index"); 
return SUCCESS; 
}

问题:

异常:

com.opensymphony.xwork2.inject.ContainerImpl$MissingDependencyException: No mapping found for dependency [type=com.opensymphony.xwork2.ObjectFactory, name='default'] in public void com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.setObjectFactory(com.opensymphony.xwork2.ObjectFactory). - Class: com.opensymphony.xwork2.inject.ContainerImpl File: ContainerImpl.java
解决方法:
  <filter-name>struts2</filter-name>
  <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
      <init-param>  
        <param-name>config</param-name>  
        <param-value>struts-default.xml,struts-plugin.xml,struts2/struts-*.xml</param-value>  
    </init-param>  
 </filter>
即,必须添加
 
struts-default.xml(必须),struts-plugin.xml(可选)二个额外的配置文件.
原因:
struts-default.xml是默认配置文件,一些必须的框架参数都默认设置在此.
 
 
 
问题:
nable to load configuration. - package - file:/c:/clients/PSWD/eclipse/msc_workspace/PSWDBase/WebContent/WEB-INF/classes/struts.xml:14:71 
at com.opensymphony.xwork2.config.ConfigurationManager.getConfiguration(ConfigurationManager.java:58) 
at org.apache.struts2.dispatcher.Dispatcher.init_PreloadConfiguration(Dispatcher.java:360) 
at org.apache.struts2.dispatcher.Dispatcher.init(Dispatcher.java:403) 
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
    "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
    "http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
    <package name="default" extends="struts-default">
    </package>
    <!-- Add packages here -->
    <!-- 测试界面 -->
    <include file="cn/com/test/action/struts-admin-action.xml" />
</struts>

将上面的default改成test。

问题:

遇到一个Jetty tmp的陷阱

今天碰到一个古怪的问题,运行在Jetty服务器下的一个系统,忽然爆出一个“404,页面找不到”的错误,重启系统后问题就解决。之前也碰到一个类似的问题,当时也是重启后搞定,上次事件后,查找了一下原因,没有结果,这事情也就放下了。这次再次出现同样的问题,感觉问题比较严重,必须解决这个隐患了。

出现这个问题后,到服务器上看了一下,发现这个Jetty的进程还在,同样运行的其它几个服务也都正常。分析Jetty和应用日志后,也没有发现异常情况。再次回头看一下,抛出的错误信息:

HTTP ERROR 404

Problem accessing /pages/index.jsp. Reason:

Not Found

这个错误显示是index.jsp这个文件访问不到了。于是到Jetty部署解决war的默认目录/tmp去查看,这时其实已经于事无补了,因为刚才重启过,之前目录中的文件全部会被覆盖。

初步怀疑是war解压出的文件被删除了,问了一下SA有没有cron任务在晚上运行,会不会影响/tmp目录的文件,结果他表示没有。于是继续查看Nginx日志,发现在3点36分钟时,前一个请求返回的是200,后一个就变成404了。这时另外一个同事提醒说,系统默认的tmpwatch任务会清除/tmp目录下的文件。如下:

cat /etc/cron.daily/tmpwatch
#! /bin/sh
flags=-umc
/usr/sbin/tmpwatch “$flags” -x /tmp/.X11-unix -x /tmp/.XIM-unix \
-x /tmp/.font-unix -x /tmp/.ICE-unix -x /tmp/.Test-unix \
-X ‘/tmp/hsperfdata_*’ 10d /tmp
/usr/sbin/tmpwatch “$flags” 30d /var/tmp
for d in /var/{cache/man,catman}/{cat?,X11R6/cat?,local/cat?}; do
if [ -d "$d" ]; then
/usr/sbin/tmpwatch “$flags” -f 30d “$d”
fi
done

上面的脚本表示,tmpwatch分根据文件的修改(-m)/创建(-c)时间,清理/tmp下的10天前创建或修改的文件,问题就在这里了。如何解决呢?只要让Jetty解压war文件时,不放在/tmp下就能解决这个问题了。仔细查看Jetty的关于Temporary Directories 的描述文档,原来只需要在${jetty.home}目录下创建一个work目录就行了。Jetty的这个Trick害死人,为什么不在Jetty发布包中就默认包含这个目录呢?

教训:使用开源的东西,一定要认真读一下它的文档,对于比较关键的问题,一定要非常熟悉,否则出了问题才来想办法解决,已经晚了。

你可能感兴趣的:(struts)