![](/img/trans.png)
[英]Maven mapstruct issue when running mvn install/mvn test
[英]Intellij/Maven: Error creating bean when running mvn install
當嘗試通過在終端中使用 mvn install 運行 Maven 項目(我正在使用 IntelliJ 執行相同的操作)時,出現以下錯誤:
[ERROR] com.scopic.javachallenge.controllers.TeamProcessControllerTest.testSample Time elapsed: 0 s <<< ERROR!
java.lang.IllegalStateException: Failed to load ApplicationContext
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityMapper' defined in file [C:\Users\ronit\Documents\Repos\target\classes\com\scopic\javachallenge\mappers\EntityMapper.class]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanIn
stantiationException: Failed to instantiate [com.scopic.javachallenge.mappers.EntityMapper]: Constructor threw exception; nested exception is java.lang.reflect.InaccessibleObjectException: Unable to make protected native java.lang.Object java.lang.Object.clone() throws java.lang.CloneNotSupportedException acces
sible: module java.base does not "opens java.lang" to unnamed module @66d1af89
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.scopic.javachallenge.mappers.EntityMapper]: Constructor threw exception; nested exception is java.lang.reflect.InaccessibleObjectException: Unable to make protected native java.lang.Object java.lang.Object.clone() throws
java.lang.CloneNotSupportedException accessible: module java.base does not "opens java.lang" to unnamed module @66d1af89
Caused by: java.lang.reflect.InaccessibleObjectException: Unable to make protected native java.lang.Object java.lang.Object.clone() throws java.lang.CloneNotSupportedException accessible: module java.base does not "opens java.lang" to unnamed module @66d1af89
有問題的 class EntityMapper 看起來像這樣簡化了:
public class EntityMapper {
private final MapperFactory mapperFactory = new DefaultMapperFactory.Builder().build();
private final MapperFacade mapper = mapperFactory.getMapperFacade();
public EntityMapper() throws Exception {
// public constructor
}
}
我嘗試了其他站點的多種解決方案,包括在默認構造函數中使用throws NullPointException()
並在運行mvn install
時更改 VM 選項以包括--add-opens java.base/java.lang=ALL-UNNAMED
。 這些都沒有成功。 我不知道我的代碼中是否缺少某些東西,或者我是否沒有正確設置環境——但讓我感到困惑的是 EntityMapper 實際上似乎並沒有在任何地方被調用。 我怎樣才能 go 解決這個問題?
編輯:將 --add-opens 添加到 pom.xml 文件后, mvn install
運行正常。 但是,現在mvn spring-boot:run
出現相同的錯誤。 這是如何解決的,為什么 pom.xml 解決方案只適用於第一個命令?
嘗試在您的 pom.xml 中添加“--add-opens java.base/java.lang=ALL-UNNAMED”。 請參閱: https://stackoverflow.com/a/71296829/13774637
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.