The Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.p

来源:互联网 发布:淘宝店怎么开起来 编辑:程序博客网 时间:2024/04/28 21:38

运行环境是 Myeclipse6.0+struts1.3+spring2.0+hibernate3.1 +Tomcat6.0

今天在练习ssh的整合,其中遇到了不少的问题,其程序报的异常和解决方案归纳:

严重: action: null
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in ServletContext resource [/WEB-INF/classes/applicationContext.xml]: Invocation of init method failed; nested exception is java.lang.SecurityException: class "org.apache.commons.collections.SequencedHashMap"'s signer information does not match signer information of other classes in the same package
.......

解决方案:包冲突了  删除 WEB-INF/lib/asm-2.2.3.jar即可

 

随后这个异常不见了  但却又报了The Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path :、、、、

 

解决方案:   在http://tomcat.heanet.ie/native/下载dll文件:tcnative-1.dll(现在版本是1.1.14)

把它扔到jdk的bin目录下,即可。

 

其它的在罗列了点

  1. 1.地址栏中:http://localhost:8088/sshtest/user.do?act=register      
  2.       
  3.   报错:HTTP Status 404 - Servlet action is not available      
  4.       
  5.   原因是:struts-config.xml配置文件中的请求处理器类出错了(找不到类路径)      
  6.   <controller processorClass="com.xj.requestprocessor.MyProcessor"></controller>      
  7.   解决办法:      
  8.   <controller     processorClass="org.springframework.web.struts.DelegatingRequestProcessor">      
  9.   </controller>      
  10. -------------------------------------------------------------------------------------------   
  11. 2.报错 :javax.servlet.ServletException: Cannot find ActionMappings or ActionFormBeans collection      
  12.   原因: 工程里面的struts包.有损坏或某些struts包没有存在.      
  13.   解决办法:重新创建一个工程,并且导入struts,然后将导入的struts包copy到目前的工厂的      
  14.   WEB-INf/lib目录,重新部署,重新启动服务,就ok了      
  15. -------------------------------------------------------------------------------------------   
  16. 3.报错:java.lang.Long cannot be cast to java.lang.Integer        
  17.   Long 无法转化成Integer类型.      
  18.   这个异常 经常出现在hinbernate分页查询的时候.      
  19.   例如:        
  20.            注: super.pageQuery(hql,null,null,null);调用了一个父类的一个封装方法.查询时候使用      
  21.            List list = this.getHibernateTemplate().executeFind(new HibernateCallback(){});      
  22.       
  23.           /**     
  24.       * 查询所有用户记录总数     
  25.       */      
  26.       public Integer getUsersCount() {      
  27.         String hql = "select count(*) from Users";      
  28.         List list = super.pageQuery(hql, nullnullnull);      
  29.         return (Integer) list.get(0);      
  30.       }      
  31.       原因:      
  32.       
  33.         这里在Hibernate2.0之前版本list.get(0)返回的是Integer类型.      
  34.         但是在Hibernate3.0以后版本list.get(0)返回的是Long类型.      
  35.         所以在这里不可以由Long型强转成Integer类型.      
  36.           
  37.             
  38.          解决办法:      
  39.       
  40.          public Integer getUsersCount() {      
  41.         String hql = "select count(*) from Users";      
  42.         List list = super.pageQuery(hql, nullnullnull);      
  43.         Number num = (Number) list.get(0);      
  44.         return num.intValue();      
  45.      }      
  46.          注:java.lang.Number是Integer,Long的父类.     


Java代码 复制代码
  1. 4.报错:java.lang.NoSuchMethodError org.objectweb.asm.ClassVisitor.visit       
  2. (IILjavalangString;LjavalangString;[LjavalangString;LjavalangString;)V.txt      
  3.                
  4.      原因: 由于某些Spring和Hibernate的版本问题,其中导入包的时候,某些jar包发生了冲突.      
  5.                  
  6.      解决办法: 删除工程下面WEB-INF/lib/asm-2.2.3.jar,然后在MyEclipse中刷新工程,      
  7.                再重新部署工程,然后重启 Tomcat.     
  8. ----------------------------------------------------------------------------------------------------------------------------------   
  9.   
  10. 5. 报错 : Servlet Action is not available       
  11.          
  12.     (1). 将struts-config.xml文件中的      
  13.     <plug-in      
  14.         className="org.springframework.web.struts.ContextLoaderPlugIn">      
  15.         <set-property property="contextConfigLocation"     
  16.         value="/WEB-INF/applicationContext.xml" />      
  17.    </plug-in>   去掉      
  18.          
  19.      
  20.     (2).然后在web.xml文件中加上这段代码就可以了.      
  21.             
  22.     <context-param>      
  23.         <param-name>contextConfigLocation</param-name>      
  24.         <param-value>/WEB-INF/applicationContext.xml</param-value>      
  25.     </context-param>      
  26.     <servlet>      
  27.         <servlet-name>context</servlet-name>      
  28.         <servlet-class>      
  29.             org.springframework.web.context.ContextLoaderServlet      
  30.         </servlet-class>      
  31.         <load-on-startup>1</load-on-startup>      
  32.         </servlet>     
  33. ----------------------------------------------------------------------------------------------------------------------------------   
  34. 6.报错:'sessionFactory' or 'hibernateTemplate' is required       
  35.            
  36.         原因: 在dao操作类中需要注入HibernateTemplate来创建sessionFactory.      
  37.               或者直接注入sessionFactory.      
  38.         
  39.         错误的写法:      
  40.        <bean id="depsdao" class="com.xj.dao.impl.DepsDao"     
  41.         lazy-init="true">      
  42.     </bean>      
  43.           
  44.         <bean id="userdao" class="com.xj.dao.impl.UsersDao"     
  45.         lazy-init="true">      
  46.     </bean>      
  47.      
  48.       解决办法:      
  49.      
  50.       要将这2个对象中的某一个注入到dao中.      
  51.     第一种方法:      
  52.                <bean id="depsdao" class="com.xj.dao.impl.DepsDao"     
  53.          lazy-init="true">      
  54.          <property name="sessionFactory">      
  55.             <ref bean="sessionFactory" />      
  56.          </property>      
  57.            </bean>      
  58.          第二种方法:      
  59.                <bean id="hibernateTemplate"     
  60.         class="org.springframework.orm.hibernate3.HibernateTemplate">      
  61.         <property name="sessionFactory" ref="sessionFactory"></property>      
  62.            </bean>      
  63.              
  64.                 <bean id="depsdao" class="com.xj.dao.impl.DepsDao"     
  65.         lazy-init="true">      
  66.         <property name="hibernateTemplate">      
  67.             <ref bean="hibernateTemplate" />      
  68.         </property>      
  69.             </bean>    


Java代码 复制代码
  1.     
  2.     
  3. 7.报错: java.lang.IllegalStateException:   No   WebApplicationContext   found:        
  4. no  ContextLoaderListener   registered?      
  5.      
  6.    原因: web.xml文件中的配置写错了        
  7.           解决办法:在web.xml中加上      
  8.         <context-param>      
  9.         <param-name> contextConfigLocation </param-name>      
  10.         <param-value>      
  11.         /WEB-INF/classes/applicationContext.xml      
  12.         </param-value>      
  13.         </context-param>      
  14.         <servlet>      
  15.         <servlet-name> context </servlet-name>      
  16.         <servlet-class>      
  17.             org.springframework.web.context.ContextLoaderServlet      
  18.         </servlet-class>      
  19.         <load-on-startup> 1 </load-on-startup>      
  20.         </servlet>     
  21. -----------------------------------------------------------------------------------------------------------------------------------------------   
  22. 8.报错:No bean named 'sessionFactory' is defined      
  23.    错误可能原因1:      
  24.                  在web.xml中加载applicationContext.xml文件的时候没有加载成功,看你的路径是否 正确   
  25. ,      
  26.                  这个配置错误,服务器启动的时候不会报错      
  27.    错误可能原因2:      
  28.                  没有删除asm-2.2.3.jar文件.一定要直接从磁盘目录删除.然后刷新工程,重新部署  重启服   
  29. 务.     
  30. -----------------------------------------------------------------------------------------------------------------------------------------------   
  31. 9.报错:sessionFactory或者hibernateTemplate找不到   
  32.        有的时候,我们明明就在dao中注入了sessionFactory或hibernate,但是还是总是报错,说   
  33.        sessionFactory或者hibernateTemplate找不到   
  34.        
  35.   下面这种情况会引发这种情况:    
  36.          在struts中的formbean中的reset方法,往往我们用来初始化界面的一些显示值.   
  37.          如一个注册,可能在这里先查询数据库,找到所有的部门信息,然后绑定在界面的下拉框中.   
  38.          所以可能会在reset方法中调用业务层方法.(也有可能请求页面之前,先经过一个servlet或jsp,   
  39.                                                                    在servlet里面调用业务层方法)    
  40.          如果你在formbean中是这样写会报上面的错误:   
  41.           ApplicationContext ap = new FileSystemXmlApplicationContext(   
  42.    new String[] {   
  43. "E://MyWorkPlace//sshtest//WebRoot//WEB-INF//applicationContext.xml",   
  44. "E://MyWorkPlace//sshtest//WebRoot//WEB-INF//operatorbeans.xml",   
  45.         "E://MyWorkPlace//sshtest//WebRoot//WEB-INF//actionbeans.xml" });   
  46.   
  47.          IUserService us = (IUserService) ap.getBean("userservice");   
  48.          然后用us 直接调用方法.   
  49.             
  50.          原因: 在这里ApplicationContext ap = new FileSystemXmlApplicationContext(   
  51.    new String[] {});    
  52.         启动的实际上是另外一个spring容器,而不是刚刚启动服务的时候创建的那个spring容器.   
  53.         
  54.     解决办法:   
  55.           在reset方法中:     
  56.            ServletContext context = servlet.getServletContext();    
  57.           ApplicationContext app = (ApplicationContext) context.getAttribute    
  58.               (WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE);     
  59.                  
  60.                 IDeptService ds = (IDeptService) app.getBean("deptservice");     
  61.                 this.depList = ds.selectAllDeps();   
  62.             注:servlet是struts框架中间的一个对象,保存了web容器的很多信息   
  63.              那么之前是怎样设置进去的呢?   
  64.          // context.setAttribute(   
  65. WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE,启动的时候创建的那个spring容器);   
  66. ------------------------------------------------------------------------------------------------------------------------------------------------------------------   
  67. 10.报错:  org.apache.jasper.JasperException: $Proxy3 cannot be cast to       
  68.             com.xj.service.impl.RoleService        
  69.           java.lang.ClassCastException: $Proxy3 cannot be cast to com.xj.service.impl.RoleService     
  70.   
  71.      
  72.     原因:很明显又是一个代理时候,强转错误:      
  73.                 
  74.                ServletContext context = servlet.getServletContext();       
  75.             ApplicationContext app = (ApplicationContext) context.getAttribute      
  76.              (WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE);        
  77.                 IDeptService ds = (DeptService) app.getBean("deptservice");        
  78.                 this.depList = ds.selectAllDeps();      
  79.                   就是这段示例代码中的   IDeptService ds = (DeptService) app.getBean    
  80. ("deptservice");出错了       
  81.                 不能直接强转成接口的实现类,一定要转成接口.      
  82.                IDeptService ds = (IDeptService) app.getBean("deptservice   
原创粉丝点击