首先,感謝 http://www.manongjc.com/detail/42-hiwfjklnbpukjgd.html & https://huaweicloud.csdn.net/654a1218525bff6100e99afd.html
在jdk8 升級 jdk17,專案 docker 部署失敗。報錯:
### SQL: SELECT id, wechat_nick_name, open_id, name, take_effect, mobile, email, username, introduce, wechat_avatar, team_dept_id, create_user, create_time, update_user, update_time, is_deleted, hire_date, resignation_date, hire_enable, employment_length, honor, is_agent FROM team_user WHERE (open_id = ?) ### Cause: java.lang.reflect.InaccessibleObjectException: Unable to make field protected java.lang.reflect.InvocationHandler java.lang.reflect.Proxy.h accessible: module java.base does not "opens java.lang.reflect" to unnamed module @2be94b0f at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:30) ~[mybatis-3.5.13.jar!/:3.5.13] at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:156) ~[mybatis-3.5.13.jar!/:3.5.13] at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:147) ~[mybatis-3.5.13.jar!/:3.5.13] at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:142) ~[mybatis-3.5.13.jar!/:3.5.13] at jdk.internal.reflect.GeneratedMethodAccessor40.invoke(Unknown Source) ~[na:na] at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na] at java.base/java.lang.reflect.Method.invoke(Method.java:568) ~[na:na] at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:425) ~[mybatis-spring-2.1.1.jar!/:2.1.1] ... 112 common frames omitted
1. 幫助我找到問題原因之一:--add-opens=java.base/java.lang=ALL-UNNAMED 在 docker 部署時必須這麼寫。
oracle 官方說 vm-optins 需要設定成 --add-opens java.base/java.lang=ALL-UNNAMED,但是這麼寫在 docker 不認。
標準寫法是:
ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-Duser.timezone=Asia/Shanghai","--add-opens=java.base/java.lang=ALL-UNNAMED","--add-opens=java.base/java.lang.reflect=ALL-UNNAMED","--add-opens=java.base/java.io=ALL-UNNAMED","--add-opens=java.base/java.util=ALL-UNNAMED","-jar","app.jar"]
2. Dockerfile 裡面不能有換行
因為太長,我把 ENTRYPOINT 陣列按逗號換行了。但事實是 jenkins 日誌顯示 docker 不認。只讀取到了第一行。