【发布时间】:2022-01-18 20:21:21
【问题描述】:
spring-boot版本从2.1.8.RELEASE升级到2.5.6后,spring-boot-configuration-processor包升级到了。运行 WAR 时,我们得到下面的异常,它找不到类,实际上 WAR 不包含此包的 JAR(spring-boot-configuration-processor)。
作为解决方法,我们已将此包降级为 2.3.12.RELEASE,它可以在运行时运行。我们已尝试使用 2.3.6 / 2.4.14 / 2.4.7 / 2.4.0 版本,但 jar 不包含在 WAR 中。
据我了解,该包由 IDE 使用,所以我的问题是:为什么在运行时需要它?它应该包含在我的 WAR 中吗? Maven 如何决定从 WAR 中排除包?
Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name appointmentRepository defined in com.project.project.repositories.AppointmentRepository defined in @EnableJpaRepositories declared on JpaRepositoriesRegistrar.EnableJpaRepositoriesConfiguration: Cannot create inner bean (inner bean)#37291159 of type [org.springframework.orm.jpa.SharedEntityManagerCreator] while setting bean property entityManager;
nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name (inner bean)#37291159: Cannot resolve reference to bean entityManagerFactory while setting constructor argument;
nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name entityManagerFactory defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaConfiguration.class]: Invocation of init method failed; nested exception is java.lang.NoClassDefFoundError: org.springframework.boot.configurationprocessor.json.JSONException
application.properties:
com.project.file.maximumSize=5242880
com.project.file.contentTypes=application/pdf,image/png,image/jpeg
com.project.file.extensions=pdf,png,jpeg,jpg
com.project.file.maxFilesPerAttachmentType=5
附加-spring-configuration-metadata.json
{"properties": [
{
"name": "com.project.file.maximum-size",
"type": "java.lang.Long",
"description": "Sets the maximum valid size, in Bytes, for the uploaded attachments."
},
{
"name": "com.project.file.content-types",
"type": "java.util.List<java.lang.String>",
"description": "A list of the authorized content types for the uploaded attachments."
},
{
"name": "com.project.file.extensions",
"type": "java.util.List<java.lang.String>",
"description": "A list of the authorized extensions."
}
]}
【问题讨论】:
-
你能发布你的 pom 文件吗?那是 Maven 用来配置构建的文件(可能在那里发现错误)
-
我找到了根本原因,我是从 org.springframework.boot.configurationprocessor.json 而不是 org.json 导入 JSONObject 和 JSONException ,这就是在运行时调用它的原因。谢谢@JensBaitinger
标签: java spring spring-boot maven configuration