整合SSM中spring6.0.0-M4缺少核心类文件问题

就在今年的5月12日,Spring官网发布Spring Framework 6.0.00-M4 ,于是便用最新版整合SSM,无语了,新包果然不靠谱,来看看以下问题是否遇到过。


整合SSM中spring6.0.0-M4缺少核心类文件问题


问题1文件上传问题

在上传文件时,通常会使用bean进行声明multipartResolver解析器,来解析文件

往常做法是:



  
  

但是当你这么配置的时候,运行就报错,因为压根就没有comms目录,更别提类文件了

整合SSM中spring6.0.0-M4缺少核心类文件问题

然后便寻思着,既然没有CommonsMultipartResolver,看到有个带Resolver的看看能不能替换吧。

换了之后,居然提示multipart-config没有配置,然后网上搜了下,在web.xml的servlet中配置,然后继续运行,还真能用,就此解决了这个问题。


  ...此处省略其他配置...

      20848820
      418018841
      1048576
    

之后看了看官方文档解释,官方提供了两种处理方式:

一种是通过Apache Commons,这种方式既然官网提到那就应该可以配置,但却没有commons目录,估计是缺失了吧。。。

一种是通过Servlet Multipart Parsing,这种就需要在web.xml再做配置。

需要看详细内容的请查看官网:

https://docs.spring.io/spring-framework/docs/6.0.0-M4/reference/html/web.html#mvc-multipart

https://docs.spring.io/spring-framework/docs/6.0.0-M4/javadoc-api/org/springframework/web/multipart/support/StandardServletMultipartResolver.html


整合SSM中spring6.0.0-M4缺少核心类文件问题


问题2数据库链接问题

报错提示:

警告: Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping': Invocation of init method failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sqlSessionFactory': Lookup method resolution failed; nested exception is java.lang.IllegalStateException: Failed to introspect Class [org.mybatis.spring.SqlSessionFactoryBean] from ClassLoader [jdk.internal.loader.ClassLoaders$AppClassLoader@63947c6b]

6月 17, 2022 5:04:49 下午 org.springframework.test.context.TestContextManager prepareTestInstance
严重: Caught exception while allowing TestExecutionListener [org.springframework.test.context.support.DependencyInjectionTestExecutionListener@4e41089d] to prepare test instance [com.yzfstudy.dao.ActorDAOTest@5d1659ea]
java.lang.IllegalStateException: Failed to load ApplicationContext
	... ...
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping': Invocation of init method failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sqlSessionFactory': Lookup method resolution failed; nested exception is java.lang.IllegalStateException: Failed to introspect Class [org.mybatis.spring.SqlSessionFactoryBean] from ClassLoader [jdk.internal.loader.ClassLoaders$AppClassLoader@63947c6b]
	... ...
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sqlSessionFactory': Lookup method resolution failed; nested exception is java.lang.IllegalStateException: Failed to introspect Class [org.mybatis.spring.SqlSessionFactoryBean] from ClassLoader [jdk.internal.loader.ClassLoaders$AppClassLoader@63947c6b]
 ... ...
Caused by: java.lang.IllegalStateException: Failed to introspect Class [org.mybatis.spring.SqlSessionFactoryBean] from ClassLoader [jdk.internal.loader.ClassLoaders$AppClassLoader@63947c6b]
	... ...
Caused by: java.lang.NoClassDefFoundError: org/springframework/core/NestedIOException
... ...
Caused by: java.lang.ClassNotFoundException: org.springframework.core.NestedIOException
... ...

主要就是说初始化失败,找不到class文件报错 org/springframework/core/NestedIOException

一开始不知道怎么处理,网上找了好久,都没解决的方式,没办法只能去扒代码检查了。。。

检查步骤:

1、查看配置是否有问题,检查无误

2、检查数据库配置是否有问题,检查无误

3、检查是否能获取数据库连接池,写了测试类 进行测试,没想到还真报错了:

java.lang.NoClassDefFoundError: org/springframework/core/NestedIOException
@Configuration
public class MyBaitsConfigTest {
    private static DataSource dataSource;
    @Bean
    public SqlSessionFactory sqlSessionFactory() throws Exception {
        SqlSessionFactoryBean factoryBean = new SqlSessionFactoryBean();
        factoryBean.setDataSource(dataSource());

        return factoryBean.getObject();

    }

    public DataSource dataSource() throws Exception {
        Properties properties = new Properties();
        InputStream in = MyBaitsConfigTest.class.getClassLoader().getResourceAsStream("druid.properties");

        properties.load(in);
        dataSource = DruidDataSourceFactory.createDataSource(properties);
        return dataSource;
    }

    @Test
    public void sqlSession() throws Exception {
        System.out.println(sqlSessionFactory());
    }
}


整合SSM中spring6.0.0-M4缺少核心类文件问题

mybatis-srping2.0.7最新包里载入了这个文件,所以这文件必须有啊


查看了jar包,还真没NestedIOException这个文件,也是无语了。

然后,又是一顿各种搜索,没有解决办法,最后只能下载之前的版本来看了,没想到都有这个文件,估计6.0.0-M4是把这个文件缺失了吧,于是下载6.0.0-M3的jar包,将里边的NestedIOException.class文件拷贝到6.0.0-M4中,刷新,运行,居然成功运行了,花了我好几个小时,特么就是个坑!!!

好了,先到这里吧,小伙伴们遇到问题是怎么处理的,欢迎留言^_^

SSM
发表评论
留言与评论(共有 0 条评论) “”
   
验证码:

相关文章

推荐文章