【场景复现】
jdk21环境变量springboot3.x、mybatisplus generator3.5.3构建工程启动:
【原因分析】
显示 'factoryBeanObjectType' 属性的值类型不正确,应该是一个实现了 FactoryBean
接口的类的全限定名。
注解注入每层对象,找不到FactoryBean对象,基本还是IDEA自身缓存清理不干净。MyBatis Plus的版本在使用Freemaker生成的代码和Springboot3.2.x有点问题。
【解决】
SpringBoot3.1.x、MyBatisPlus3.5.3、JDK21、maven3.6.3启动工程
- pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion><parent><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-parent</artifactId><version>3.1.6</version><relativePath/> <!-- lookup parent from repository --></parent><groupId>com.hu</groupId><artifactId>test-jdk21</artifactId><version>0.0.1-SNAPSHOT</version><name>test-jdk21</name><description>Demo project for Spring Boot</description><properties><java.version>21</java.version></properties><dependencies><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency><dependency><groupId>org.projectlombok</groupId><artifactId>lombok</artifactId><optional>true</optional></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-test</artifactId><scope>test</scope></dependency><!-- mysql驱动 --><dependency><groupId>mysql</groupId><artifactId>mysql-connector-java</artifactId><version>8.0.20</version><scope>runtime</scope></dependency><!-- druid --><dependency><groupId>com.alibaba</groupId><artifactId>druid</artifactId><version>1.1.18</version></dependency><!-- mybatis-plus-boot-starter --><dependency><groupId>com.baomidou</groupId><artifactId>mybatis-plus-boot-starter</artifactId><version>3.5.3</version></dependency><dependency><groupId>com.baomidou</groupId><artifactId>mybatis-plus-generator</artifactId><version>3.5.3</version></dependency><!-- freemarker --><dependency><groupId>org.freemarker</groupId><artifactId>freemarker</artifactId><version>2.3.32</version></dependency></dependencies><build><plugins><plugin><groupId>org.springframework.boot</groupId><artifactId>spring-boot-maven-plugin</artifactId><version>3.1.6</version><configuration><image><builder>paketobuildpacks/builder-jammy-base:latest</builder></image><excludes><exclude><groupId>org.projectlombok</groupId><artifactId>lombok</artifactId></exclude></excludes></configuration></plugin></plugins></build></project>
- application.yml
server:port: 8081
logging:level:com.hu: debug
spring:# 数据源配置datasource:type: com.alibaba.druid.pool.DruidDataSourcedriver-class-name: com.mysql.cj.jdbc.Driverurl: jdbc:mysql://127.0.0.1:3306/simpledemo?charactEncoding=UTF-8&serverTimezone=UTCusername: rootpassword: rootservlet:multipart:enabled: truemax-file-size: 2000MBmax-request-size: 2000MB
mybatis-plus:global-config:db-config:logic-delete-value: 1logic-not-delete-value: 0
【测试】
@GetMapping("/view/{id}")public Result<Org> queryOrgById(@PathVariable("id") Long id){return orgService.queryOrgById(id);}