myeclipse下大家ssh常见问题

有包冲突,

1.在搭建SSH开发平台的时候,由MyEclipse自动导入的包存在一些冲突,主要有
(1) asm.jar与asm-2.2.3.jar
asm-2.2.3是spring所依赖,而asm.jar是hibernate依赖的,应该删除asm-2.2.3.jar这个包
 
(2). commons-logging-1.0.4.jar与commons-logging-api-1.1.jar
这两个包中commons-logging-1.0.4.jar是spring和hibernate以及struts都要用的包,但是struts2.1以上的版本还需要commons-logging-api-1.1.jar,其实这两个包几乎一样,commons-logging-api-1.1.jar版本较新而已。
 
(3)异常
严重: Exception starting filter struts2
java.lang.NullPointerException
    at com.opensymphony.xwork2.spring.SpringObjectFactory.getClassInstance(SpringObjectFactory.java:203)
   ...
可能的原因是spring的默认配置文件applicationContext.xml改了名,或者没有放在classpath的根路径下面,并且没有在web.xml文件中配置spring的监听器,解决办法在web.xml中添加
<listener>
    <listener-class>
        org.springframework.web.context.ContextLoaderListener
    </listener-class>
</listener>
(4)异常
严重: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListenerorg.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from ServletContext resource [/WEB-INF/applicationContext.xml]; nested exception is java.io.FileNotFoundException: Could not open ServletContext resource [/WEB-INF/applicationContext.xml]
 
可能的原因是虽然配置了spring的监听器,但是没有在web.xml中配置contextConfigLocation来指定spring配置文件列表及相应的具体路径。解决的办法是在web.xml文件中添加,例如:
<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>/WEB-INF/csdn-spring*.xml</param-value>
</context-param> 
 
(5)异常
org.springframework.transaction.CannotCreateTransactionException: Could not open Hibernate Session for transaction; nested exception is org.hibernate.exception.GenericJDBCException: Cannot open connection
可能的原因是缺少相应的JDBC驱动包,请把驱动包拷贝到/WEB-INF/lib下面,或者是数据源的配置有问题,例如用户名、者密码或者URL错误。
 
(6)错误提示:Error creating bean with name 'sessionFactory' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Invocation of init method failed; nested exception is java.lang.NoSuchMethodError: org.objectweb.asm.ClassVisitor.visit(IILjava/lang/String;Ljava/lang/String;[Ljava/lang/String;Ljava/lang/String;)V

解决方法如下:
当你把spring包和hibernate相应包打进项目里,然后在打包的文件里把把
asm.jar,asm-attrs.jar,cglib-2.1.3.jar三个文件从项目里导出,并删掉就OK了
原因:由于cglib-2.1.3 依赖的asm 跟在外边的asm版本不一致导致, 
把cglib换成 cglib-nodep版本的就可以了

Error creating bean with name 'sessionFactory' defined in ServletContext resource [/WEB-INF/spring_config/applicationContext.xml]: Invocation of init method failed; nested exception is java.lang.NoClassDefFoundError: Serializable 
 
ID的属性搞错了,用逆向工程重新生成一下*.hbm.xml,发现它的<id name="id" type="java.lang.Integer">
<column name="id" />
<generator class="native" />
</id>
generator class="native" 而之前手写的是identity

(7)错误提示:CGLIB Enhancement failed
解决:
Spring的AOP编程时,会用到这几个lib:
asm-2.2.3.jar
asm-commons-2.2.3.jar
asm-util-2.2.3.jar
cglib-nodep-2.1_3.jar
 
Hibernate也包含类似的包lib:
asm.jar
asm-attrs.jar
cglib-2.1.3.jar
而导致的包冲突。
只要将hibernate用到的三个包都删掉就应该没有问题了,可是正常情况下这样是解决不了问题的,因为tomcat下已经放在webapps文件夹下的包却还没有删除,所以我们要手工删除它,找到C:/Program Files/Apache Software Foundation/Tomcat 5.5/webapps/目录下,你的项目,WEB-INF文件夹,lib文件夹,将三个包删除就ok了

原因:其实是包冲突的问题。
Spring2.0 AOP Liberaries里的asm2.2.3.jar和Hiberate中的生成代理用的asm.jar冲突
把asm2.2.3.jar , asm-util-2.2.3.jar, asm-commons-2.2.3.jar 这三个包删除就可以了。。。 

(8)java.lang.AbstractMethodError:com.microsoft.jdbc.base.BaseDatabaseMetaData.supportsGetGeneratedKeys()Z 
说是MS SQL Server 的driver有bug:Hibernate3与SQL连接时出现的java.lang.AbstractMethodError: com..... 
解决办法的不用msbase.jar、mssqlserver.jar、msutil.jar三个驱动包,而是使用jtds-1.2.5.jar,并修改更改hibernate配置文件: 
原驱动连接配置: 
<property name="connection.driver_class">com.microsoft.jdbc.sqlserver.SQLServerDriver</property> <property name="connection.url">jdbc:microsoft:sqlserver://127.0.0.1:1433;DatabaseName=hibernate</property>更改jtds连接: <property name="connection.driver_class">net.sourceforge.jtds.jdbc.Driver</property> <property name="connection.url">jdbc:jtds:sqlserver://127.0.0.1:1433;DatabaseName=hibernate</property> 
经测试确实可以,但也可能是spring和hibernate的jar包冲突的问题: 
如果先为项目增加spring capability并带好Spring3.0 AOP Libraries、Spring 3.0 Core Libraries、Spring 3.0 Persistence Core Libraries、Spring 3.0 Persistence JDBC Libraries四个类库,而在添加Hibernate capability时不选这四个类库,则不会出现问题。 
 
(9)java.lang.NoClassDefFoundError: org/objectweb/asm/Type 
缺少asm.jar包,增加即可。 
 
(10)java.lang.NoSuchMethodError: org.objectweb.asm.ClassWriter 
删除cglib-*.jar和asm-*.jar删除,添加spring中的cglib-2.1.3.jar,hibernate中可能引入了cglibb-2.2.jar这个包,应该用cglib-2.1.3.jar。 
 
(11)java.lang.ClassNotFoundException: org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter 
web.xml中的struts2配置: 
<filter> 
<filter-name>struts2</filter-name> 
<!-- 工具自动添加的处理类,用下面的FilterDispatcher替代 <filter-class> org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class> --> 
<filter-class>cn.venice.util.AuthorityFilter</filter-class> 
</filter> 
AuthorityFilter类是自写的过滤类。出现这个异常的原因未知,重启了一次tomcat消失了 
 
(12)Cannot locate the chosen ObjectFactory implementation: spring 
用struts2,在struts.xml中写了 
<constant name="struts.objectFactory" value="spring" /> 
但忘了导入struts2-spring-plugin-*.jar包,导入即可。

(6)异常
javax.servlet.ServletException: Error applying decorator: null
 org.apache.struts2.sitemesh.FreeMarkerPageFilter.applyDecorator(FreeMarkerPageFilter.java:164)
 org.apache.struts2.sitemesh.TemplatePageFilter.applyDecorator(TemplatePageFilter.java:116)
 com.opensymphony.module.sitemesh.filter.PageFilter.doFilter(PageFilter.java:62)
 org.apache.struts2.dispatcher.ActionContextCleanUp.doFilter(ActionContextCleanUp.java:102)
 org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:96)
 org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
 
Struts2的sitemesh插件struts2-sitemesh-plugin-2.1.6的一个BUG,是FreeMarkerPageFilter的getLocale方法没有对invocation添加非空判断造成的,解决办法是解压包,然后找到org.apache.struts2.sitemesh.FreeMarkerPageFilter这个类,将
view plaincopy to clipboardprint?
1.        protected Locale getLocale(ActionInvocation invocation, Configuration configuration) {       
2.                if (invocation.getAction() instanceof LocaleProvider) {       
3.                    return ((LocaleProvider) invocation.getAction()).getLocale();       
4.                 } else {       
5.                    return configuration.getLocale();       
6.                 }       
7.        }      
修改为:
view plaincopy to clipboardprint?
1.        protected Locale getLocale(ActionInvocation invocation, Configuration configuration) {       
2.            if (invocation != null && invocation.getAction() instanceof LocaleProvider) {       
3.                return ((LocaleProvider) invocation.getAction()).getLocale();       
4.             } else {       
5.                return configuration.getLocale();       
6.             }       
7.        }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值