错误信息:
java.lang.reflect.InaccessibleObjectException: Unable to make protected final java.lang.Class java.lang.ClassLoader.defineClass(...) accessible: module java.base does not "opens java.lang" to unnamed module
原因:
将Spring Boot从1.5.22.RELEASE升级到2.7.18(支持Java 17)
1.5.22.RELEASE 升级到 2.7.183.8.1 升级到 3.11.07 升级到 171.3.2 升级到 2.3.1mysql-connector-java 5.1.49 升级到 mysql-connector-j 8.0.33com.mysql.jdbc.Driver 改为 com.mysql.cj.jdbc.Driver<skip>true</skip> 配置WebMvcConfigurerAdapter 改为 WebMvcConfigurerWebMvcConfigurerAdapter 已废弃postHandle 和 afterCompletion 方法com.mysql.jdbc.Driver 改为 com.mysql.cj.jdbc.Driver| 组件 | 旧版本 | 新版本 |
|---|---|---|
| Spring Boot | 1.5.22.RELEASE | 2.7.18 |
| MyBatis | 1.3.2 | 2.3.1 |
| MySQL驱动 | 5.1.49 | 8.0.33 |
| Java版本 | 7/8 | 17 |
WebMvcConfigurerAdapterWebMvcConfigurercom.mysql.jdbc.Drivercom.mysql.cj.jdbc.Drivercd book
mvn clean compile
mvn spring-boot:run
访问:http://localhost:8081/api/admin/login
com.mysql.cj.jdbc.Driver启动后应该看到:
Started BookApplication
Tomcat started on port(s): 8081
# 测试登录接口
curl -X POST http://localhost:8081/api/admin/login \
-H "Content-Type: application/json" \
-d '{"username":"admin","password":"admin123"}'
http://localhost:8000/pages/login.html