at org.mapstruct.factory.Mappers.getMapper(Mappers.java:75)
时间: 2023-11-23 12:06:30 浏览: 249
这个异常是在调用 `Mappers.getMapper()` 方法时抛出的。根据异常信息,它是在 `Mappers.java` 文件的第 75 行发生的。
可能的原因是 `Mappers` 类没有找到对应的映射器(Mapper)。这通常是因为没有正确配置或初始化 MapStruct 库导致的。请确保已经正确引入 MapStruct 的依赖,并且在项目中配置了正确的映射器类。
另外,也要确保 `CarConvert` 类已经正确实现了 MapStruct 的 `Mapper` 接口或被注解为 `@Mapper`。如果这些都正确无误,那么请检查一下 `CarConvert` 类是否存在,并且是否位于正确的包路径下。
如果以上步骤都没有解决问题,建议查看详细的异常堆栈信息,以获取更多关于问题出现位置和原因的线索。
相关问题
java.lang.ExceptionInInitializerError at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) at java.lang.reflect.Constructor.newInstance(Constructor.java:422) at org.junit.runners.BlockJUnit4ClassRunner.createTest(BlockJUnit4ClassRunner.java:195) at org.junit.runners.BlockJUnit4ClassRunner$1.runReflectiveCall(BlockJUnit4ClassRunner.java:244) at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) at org.junit.runners.BlockJUnit4ClassRunner.methodBlock(BlockJUnit4ClassRunner.java:241) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50) at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238) at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63) at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236) at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53) at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229) at org.junit.runners.ParentRunner.run(ParentRunner.java:309) at org.junit.runner.JUnitCore.run(JUnitCore.java:160) at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:69) at com.intellij.rt.junit.IdeaTestRunner$Repeater$1.execute(IdeaTestRunner.java:38) at com.intellij.rt.execution.junit.TestsRepeater.repeat(TestsRepeater.java:11) at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:35) at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:235) at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:54) Caused by: org.apache.ibatis.exceptions.PersistenceException: ### Error building SqlSession. ### The error may exist in mappers/categoryMapper.xml ### Cause: org.apache.ibatis.builder.BuilderException: Error parsing SQL Mapper Configuration. Cause: java.io.IOException: Could not find resource mappers/categoryMapper.xml at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:30) at org.apache.ibatis.session.SqlSessionFactoryBuilder.build(SqlSessionFactoryBuilder.java:82) at org.apache.ibatis.session.SqlSessionFactoryBuilder.build(SqlSessionFactoryBuilder.java:66) at Test.<clinit>(Test.java:19) ... 23 more Caused by: org.apache.ibatis.builder.BuilderException: Error parsing SQL Mapper Configuration. Cause: java.io.IOException: Could not find resource mappers/categoryMapper.xml at org.apache.ibatis.builder.xml.XMLConfigBuilder.parseConfiguration(XMLConfigBuilder.java:115) at org.apache.ibatis.builder.xml.XMLConfigBuilder.parse(XMLConfigBuilder.java:95) at org.apache.ibatis.session.SqlSessionFactoryBuilder.build(SqlSessionFactoryBuilder.java:80) ... 25 more Caused by: java.io.IOException: Could not find resource mappers/categoryMapper.xml at org.apache.ibatis.io.Resources.getResourceAsStream(Resources.java:114) at org.apache.ibatis.io.Resources.getResourceAsStream(Resources.java:100) at org.apache.ibatis.builder.xml.XMLConfigBuilder.mapperElement(XMLConfigBuilder.java:338) at org.apache.ibatis.builder.xml.XMLConfigBuilder.parseConfiguration(XMLConfigBuilder.java:113) ... 27 more
这个错误是一个初始化错误(`ExceptionInInitializerError`),它是由于在初始化静态变量或静态代码块时抛出了异常导致的。根据堆栈跟踪,问题似乎是在构建`SqlSessionFactory`时出现的。
具体来说,问题出现在解析 MyBatis 的 XML 配置文件时。堆栈跟踪中提到了一个找不到资源的异常(`java.io.IOException: Could not find resource mappers/categoryMapper.xml`)。这意味着在 `mappers` 目录下找不到名为 `categoryMapper.xml` 的文件。
可能的解决方案是检查以下内容:
1. 确保 `categoryMapper.xml` 文件存在于正确的位置,并且文件名和路径都是正确的。
2. 确保 `categoryMapper.xml` 文件在项目的类路径下可访问。可以通过将该文件放置在类路径下的合适位置,或者将其添加到类路径中来实现。
3. 如果项目使用了 Maven 或其他构建工具,请确保 `categoryMapper.xml` 文件包含在构建过程中,并正确复制到目标输出目录。
如果以上步骤都已尝试但问题仍然存在,可以进一步检查 XML 文件的内容和语法是否正确,并确保 MyBatis 的配置文件中正确引用了该 XML 文件。
希望这些信息对你有帮助!如果还有其他问题,请随时提问。
Loading class `com.mysql.jdbc.Driver'. This is deprecated. The new driver class is `com.mysql.cj.jdbc.Driver'. The driver is automatically registered via the SPI and manual loading of the driver class is generally unnecessary. Exception in thread "main" org.apache.ibatis.exceptions.PersistenceException: ### Error querying database. Cause: java.sql.SQLNonTransientConnectionException: Public Key Retrieval is not allowed ### The error may exist in mysql/user/mappers/usermapper.xml ### The error may involve mysql.user.mappers.usermapper.selectAll ### The error occurred while executing a query ### Cause: java.sql.SQLNonTransientConnectionException: Public Key Retrieval is not allowed at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:30) at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:149) at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:140) at org.apache.ibatis.binding.MapperMethod.executeForMany(MapperMethod.java:147) at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:80) at org.apache.ibatis.binding.MapperProxy$PlainMethodInvoker.invoke(MapperProxy.java:152) at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:85) at com.sun.proxy.$Proxy4.selectAll(Unknown Source) at org.example.main2.main(main2.java:25) Caused by: java.sql.SQLNonTransientConnectionException: Public Key Retrieval is not allowed at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:110) at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:122) at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:829) at com.mysql.cj.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:449) at com.mysql.cj.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:242) at com.mysql.cj.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:198) at java.sql.DriverManager.getConnection(Driv
这个问题是因为你正在使用过时的MySQL驱动程序。新的驱动程序类是`com.mysql.cj.jdbc.Driver`。新的驱动程序类会自动通过SPI进行注册,不需要手动加载驱动程序类。此外,你遇到的错误是“Public Key Retrieval is not allowed”,这可能是由于MySQL连接配置的问题引起的。你可以尝试在连接URL中添加`allowPublicKeyRetrieval=true`来解决此问题。例如:
```java
String url = "jdbc:mysql://localhost:3306/database?allowPublicKeyRetrieval=true";
```
请确保将`localhost:3306`替换为您的MySQL服务器主机和端口,`database`替换为您要连接的数据库名称。
阅读全文