一、首先不管三七二十一,把spring-2.5.6的包全删除了
引进spring-4.3.13的包
二、参考https://blog.csdn.net/weixin_33978016/article/details/92103733修改
web.xml修改,我原项目跟他一样,所以不用改
修改前
<servlet>
<servlet-name>context</servlet-name>
<servlet-class>
org.springframework.web.context.ContextLoaderServlet
</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
修改后
org.springframework.web.context.ContextLoaderListener
三,applicationContext.xml修改
命名空间修改前
命名空间修改后
四,applicationContext.xml语法差异
spring 4.x 去掉了 dependency-check
引用bean bean=代替了local=
我的项目没找到dependency-check,所以没有替代为local
我引用bean如下
【错误处理1】
1、信息: 至少有一个JAR被扫描用于TLD但尚未包含TLD。 为此记录器启用调试日志记录,以获取已扫描但未在其中找到TLD的完整JAR列表。 在扫描期间跳过不需要的JAR可以缩短启动时间和JSP编译时间。
9月 23, 2023 11:44:02 上午 org.apache.catalina.core.StandardContext listenerStart
严重: 配置应用程序监听器[org.springframework.web.context.ContextLoaderListener]错误
java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderListener
发现spring4的jar包没有发布到TomCat里面,所以直接把jar包复制到lib路径
【错误处理2】
信息: 至少有一个JAR被扫描用于TLD但尚未包含TLD。 为此记录器启用调试日志记录,以获取已扫描但未在其中找到TLD的完整JAR列表。 在扫描期间跳过不需要的JAR可以缩短启动时间和JSP编译时间。
9月 23, 2023 11:48:52 上午 org.apache.catalina.core.StandardContext filterStart
严重: 启动过滤器异常[struts2]
java.lang.ClassCastException: class org.apache.struts2.dispatcher.FilterDispatcher cannot be cast to class jakarta.servlet.Filter (org.apache.struts2.dispatcher.FilterDispatcher is in unnamed module of loader org.apache.catalina.loader.ParallelWebappClassLoader @5b057c8c; jakarta.servlet.Filter is in unnamed module of loader java.net.URLClassLoader @5b464ce8)
at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:243)
这个是web.xmll配置的struts2拦截器
在struts2.1版本之前,所使用的核心过滤器类是 org.apache.struts2.dispatcher.FilterDispatcher,
从struts2.1版本之后,已经不推荐使用,而是使用org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter类。
当struts2.5之后的版本时,推荐将类完全名称中的ng去掉,即使用org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter类。
可是我的项目是struts2-2.1.6,难道要一起升级一下吗?
百度了一下jakarta
原来TomCat10需要使用到 Jakarta 6.0 的版本,而我也刚好把TomCat升级为TomCat10;
而spring4.3 和struts2.1 项目使用的 javax 冲突了
理论上来讲,Java EE 8 (2017 年 8 月 31 日)已经结束了,之后就没有 Java EE 了。原文是这么说的 Oracle waves good-bye to Java Enterprise Edition, as the Eclipse Foundation takes over Java EE under a new name, Jakarta, and without the “Java” trademark 。所以以后基于 Java EE 的规范,比如 Servlet 等都需要做不兼容的升级
你可以使用工具来将原来的 javax 包名的项目转换到新的项目下:
GitHub 在这里: https://github.com/apache/tomcat-jakartaee-migration
或者这里: https://tomcat.apache.org/download-migration.cgi
参考资料:
https://www.cnblogs.com/cyq1162/p/16627619.html
https://www.nuomiphp.com/t/62f726597ac6e30c717413b1.html
对于这个错误,我选择不动,降级TomCat为8.5,因为我主要目的是升级spring就好了。
【错误处理3】
ERROR - Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘txAdvice1’: Cannot resolve reference to bean ‘transactionManager1’ while setting bean property ‘transactionManager’; nested exception is org.springframework.beans.factory.BeanCreationException:
Error creating bean with name ‘transactionManager1’ defined in class path resource [applicationContext-db1.xml]: Cannot resolve reference to bean ‘sessionFactory1’ while setting bean property ‘sessionFactory’; nested exception is org.springframework.beans.factory.BeanCreationException:
Error creating bean with name ‘sessionFactory1’: Failed to introspect bean class [org.springframework.orm.hibernate3.LocalSessionFactoryBean] for lookup method metadata: could not find class that it depends on; nested exception is java.lang.NoClassDefFoundError: org/hibernate/cache/RegionFactory
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:359)
看到这个applicationContext-db1.xml,就想到我这两个文件的标头还没改,于是也一起改了,参考applicationContext-db.xml
改完运行还是报这个错误
研究了一下这个文件,没看出啥
dataSource1–》sessionFactory1–》transactionManager1–》txAdvice1
最后再仔细看了那个错误,说是缺少org/hibernate/cache/RegionFactory
百度了一下 hibernate3.0版本压根就没有这个org.hibernate.cache.RegionFactory类,我看了一下我的是hibernate-3.2.6
因此最后把hibernate3.2.6版本换成4.2版本,再运行,就出现了下面的错误
【错误处理4】
Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘txAdvice1’: Cannot resolve reference to bean ‘transactionManager1’ while setting bean property ‘transactionManager’; nested exception is org.springframework.beans.factory.BeanCreationException:
Error creating bean with name ‘transactionManager1’ defined in class path resource [applicationContext-db1.xml]: Cannot resolve reference to bean ‘sessionFactory1’ while setting bean property ‘sessionFactory’; nested exception is org.springframework.beans.factory.BeanCreationException:
Error creating bean with name ‘sessionFactory1’: Failed to introspect bean class [org.springframework.orm.hibernate3.LocalSessionFactoryBean] for lookup method metadata: could not find class that it depends on; nested exception is java.lang.NoClassDefFoundError: [Lorg/hibernate/engine/FilterDefinition;
一大段英文,看到最后就是缺少这个Lorg/hibernate/engine/FilterDefinition
这是我改了Hibernate的版本为4.2,所以需要修改spring配置文具,上一步没有修改导致的,我改成4
改好之后,又出现以下问题
【错误处理5】
Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘txAdvice1’: Cannot resolve reference to bean ‘transactionManager1’ while setting bean property ‘transactionManager’; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘transactionManager1’ defined in class path resource [applicationContext-db1.xml]: Cannot resolve reference to bean ‘sessionFactory1’ while setting bean property ‘sessionFactory’; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘sessionFactory1’ defined in class path resource [applicationContext-db1.xml]: Invocation of init method failed; nested exception is java.lang.NoClassDefFoundError: org/jboss/logging/BasicLogger
这次不管,直接看最后,缺少org/jboss/logging/BasicLogger
原因:缺少jboss-logging的jar包
解决方法:添加jboss-logging.jar到lib下
这个挺奇怪的,之前怎么就不会缺少,换了Hibernate4就缺少了。
【错误处理6】
上面加人jar之后,重启又提示这个错误
Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘txAdvice1’: Cannot resolve reference to bean ‘transactionManager1’ while setting bean property ‘transactionManager’; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘transactionManager1’ defined in class path resource [applicationContext-db1.xml]: Cannot resolve reference to bean ‘sessionFactory1’ while setting bean property ‘sessionFactory’; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘sessionFactory1’ defined in class path resource [applicationContext-db1.xml]: Invocation of init method failed;
nested exception is java.util.ServiceConfigurationError: org.hibernate.integrator.spi.Integrator: Provider org.hibernate.search.hcore.impl.HibernateSearchIntegrator could not be instantiated
看最后面instantiated(实例化),org.hibernate.search.hcore.impl.HibernateSearchIntegrator 没法实例化
这个不知道哪里导致无法实例化
只能拉下去看其它错误,看到这句
Caused by: java.lang.ClassNotFoundException: org.jboss.logging.DelegatingBasicLogger
难道是我上面加的jboss-logging.jar包不对?重新下载了个jboss-logging-3.3.2.Final
重新运行,出现其它错误了
【错误处理7】
Caused by: java.lang.NoClassDefFoundError: org/apache/lucene/index/CorruptIndexException
Lucene是apache软件基金会 jakarta项目组的一个子项目,是一个开放源代码的全文检索引擎工具包,但它不是一个完整的全文检索引擎,而是一个全文检索引擎的架构,提供了完整的查询引擎和索引引擎,部分文本分析引擎(英文与德文两种西方语言)。
于是加入了lucene4.0常用jar包
重新运行,又有错误了
【错误处理8】
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘sessionFactory1’ defined in class path resource [applicationContext-db1.xml]: Invocation of init method failed; nested exception is java.lang.IncompatibleClassChangeError: class org.hibernate.search.util.impl.DelegateNamedAnalyzer overrides final method org.apache.lucene.analysis.Analyzer.tokenStream(Ljava/lang/String;Ljava/io/Reader;)Lorg/apache/lucene/analysis/TokenStream;
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1628)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:555)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:351)
… 34 more
Caused by: java.lang.IncompatibleClassChangeError: class org.hibernate.search.util.impl.DelegateNamedAnalyzer overrides final method org.apache.lucene.analysis.Analyzer.tokenStream(Ljava/lang/String;Ljava/io/Reader;)Lorg/apache/lucene/analysis/TokenStream;
at java.base/java.lang.ClassLoader.defineClass1(Native Method)
上面引入的lucene4.0版本不对,重新换个lucene-analyzers-3.5.0,换了lucene-core-7.0.1.jar,还是不行,应该是Lucene版本对不上,头痛不想搞了,还不如重新建个项目,把代买搬过去得了。哭死o(╥﹏╥)o
【错误处理9】
Hibernate 3.5+之后取消掉了 Hibernate.STRING
取而代之的就是StandardBasicTypes
SQLQuery q = this.session.createSQLQuery(sql);
q.addScalar(“isbn”, StandardBasicTypes.STRING);
q.addScalar(“bname”, StandardBasicTypes.STRING);
q.addScalar(“pubdate”, StandardBasicTypes.DATE);
q.addScalar(“press”, StandardBasicTypes.STRING);
q.addScalar(“author”, StandardBasicTypes.STRING);
q.addScalar(“price”, StandardBasicTypes.DOUBLE);
q.addScalar(“bkcount”, StandardBasicTypes.INTEGER);
q.addScalar(“descb”, StandardBasicTypes.STRING);
————————————————
版权声明:本文为CSDN博主「蜡基ZQ」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/qq_34239028/article/details/81293441