Spark maven 依赖关系破坏了 spring-boot 应用程序
Spark maven dependency breaks down sprint-boot application
我有一个带有 Swing GUI 的 spring-boot 应用程序。它只是工作!但是一旦我将 spark 2.0 依赖项添加到 pom.xml 文件中,它就会在启动期间显示以下错误消息并且不会启动!
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/Users/ehsun7b/.m2/repository/ch/qos/logback/logback-classic/1.1.7/logback-classic-1.1.7.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/Users/ehsun7b/.m2/repository/org/slf4j/slf4j-log4j12/1.7.21/slf4j-log4j12-1.7.21.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [ch.qos.logback.classic.util.ContextSelectorStaticBinder]
. ____ _ __ _ _
/\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v1.4.1.RELEASE)
2016-10-21 00:02:23.795 INFO 1642 --- [ main] edu.mfldclin.mcrf.vakilabad.Application : Starting Application on Ehsuns-MacBook-Pro.local with PID 1642 (/Users/ehsun7b/NetBeansProjects/vakilabad/target/classes started by ehsun7b in /Users/ehsun7b/NetBeansProjects/vakilabad)
2016-10-21 00:02:23.797 INFO 1642 --- [ main] edu.mfldclin.mcrf.vakilabad.Application : No active profile set, falling back to default profiles: default
2016-10-21 00:02:23.839 INFO 1642 --- [ main] s.c.a.AnnotationConfigApplicationContext : Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext@67c27493: startup date [Fri Oct 21 00:02:23 MYT 2016]; root of context hierarchy
2016-10-21 00:02:24.290 INFO 1642 --- [ main] f.a.AutowiredAnnotationBeanPostProcessor : JSR-330 'javax.inject.Inject' annotation found and supported for autowiring
2016-10-21 00:02:25.650 INFO 1642 --- [ main] e.m.mcrf.vakilabad.log.LogService : LogService init.
2016-10-21 00:02:25.767 INFO 1642 --- [ main] e.mfldclin.mcrf.vakilabad.log.LogFrame : Adding LogFrame instance to the LogMonitors of LogService: edu.mfldclin.mcrf.vakilabad.log.LogFrame[frame0,0,2,511x390,invalid,hidden,layout=java.awt.BorderLayout,title=Log since 2016-10-21T00:02:25.750,resizable,normal,defaultCloseOperation=DISPOSE_ON_CLOSE,rootPane=javax.swing.JRootPane[,0,22,511x368,invalid,layout=javax.swing.JRootPane$RootLayout,alignmentX=0.0,alignmentY=0.0,border=,flags=16777673,maximumSize=,minimumSize=,preferredSize=],rootPaneCheckingEnabled=true]
2016-10-21 00:02:25.897 WARN 1642 --- [ main] s.c.a.AnnotationConfigApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'org.springframework.boot.autoconfigure.info.ProjectInfoAutoConfiguration': Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'spring.info-org.springframework.boot.autoconfigure.info.ProjectInfoProperties': Initialization of bean failed; nested exception is javax.validation.ValidationException: Unable to create a Configuration, because no Bean Validation provider could be found. Add a provider like Hibernate Validator (RI) to your classpath.
2016-10-21 00:02:25.897 INFO 1642 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Unregistering JMX-exposed beans on shutdown
2016-10-21 00:02:25.902 INFO 1642 --- [ main] utoConfigurationReportLoggingInitializer :
Error starting ApplicationContext. To display the auto-configuration report re-run your application with 'debug' enabled.
2016-10-21 00:02:25.906 ERROR 1642 --- [ main] o.s.b.d.LoggingFailureAnalysisReporter :
***************************
APPLICATION FAILED TO START
***************************
Description:
The Bean Validation API is on the classpath but no implementation could be found
Action:
Add an implementation, such as Hibernate Validator, to the classpath
这是我添加的依赖:
<dependency>
<groupId>org.apache.spark</groupId>
<artifactId>spark-core_2.11</artifactId>
<version>2.0.1</version>
</dependency>
我在 spark-core_2.11-2.0.1.jar\META-INF\DEPENDENCIES
中看到并且有:
// ------------------------------------------------------------------
// Transitive dependencies of this project determined from the
// maven pom organized by organization.
// ------------------------------------------------------------------
Spark Project Core
From: 'an unknown organization'
...
...
- Bean Validation API (http://beanvalidation.org) javax.validation:validation-api:jar:1.1.0.Final
License: The Apache Software License, Version 2.0 (http://www.apache.org/licenses/LICENSE-2.0.txt)
和 @EnableAutoConfiguration
spring 可能会看到这种对类路径的依赖并尝试找到 Java specification for Bean Validation. (Some interesting reading for spring validation).
的实现
在我看来,这是因为 spark 使用 jersey
作为一种向我们展示工作状态等信息的方式 jersey bean-validation - 但我不太确定这个声明。
但是你可以通过提供 Bean Validation
的实现来解决这个问题 - 只需将实现的依赖添加到 maven。
Hibernate 验证器
<!-- https://mvnrepository.com/artifact/org.hibernate/hibernate-validator -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<version>5.3.0.Final</version>
</dependency>
或更快 (source) Apache BeanValidation.
<!-- https://mvnrepository.com/artifact/org.apache.bval/bval-jsr303 -->
<dependency>
<groupId>org.apache.bval</groupId>
<artifactId>bval-jsr303</artifactId>
<version>0.5</version>
</dependency>
解决方案在评论中! (排除验证API)
我有一个带有 Swing GUI 的 spring-boot 应用程序。它只是工作!但是一旦我将 spark 2.0 依赖项添加到 pom.xml 文件中,它就会在启动期间显示以下错误消息并且不会启动!
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/Users/ehsun7b/.m2/repository/ch/qos/logback/logback-classic/1.1.7/logback-classic-1.1.7.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/Users/ehsun7b/.m2/repository/org/slf4j/slf4j-log4j12/1.7.21/slf4j-log4j12-1.7.21.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [ch.qos.logback.classic.util.ContextSelectorStaticBinder]
. ____ _ __ _ _
/\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v1.4.1.RELEASE)
2016-10-21 00:02:23.795 INFO 1642 --- [ main] edu.mfldclin.mcrf.vakilabad.Application : Starting Application on Ehsuns-MacBook-Pro.local with PID 1642 (/Users/ehsun7b/NetBeansProjects/vakilabad/target/classes started by ehsun7b in /Users/ehsun7b/NetBeansProjects/vakilabad)
2016-10-21 00:02:23.797 INFO 1642 --- [ main] edu.mfldclin.mcrf.vakilabad.Application : No active profile set, falling back to default profiles: default
2016-10-21 00:02:23.839 INFO 1642 --- [ main] s.c.a.AnnotationConfigApplicationContext : Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext@67c27493: startup date [Fri Oct 21 00:02:23 MYT 2016]; root of context hierarchy
2016-10-21 00:02:24.290 INFO 1642 --- [ main] f.a.AutowiredAnnotationBeanPostProcessor : JSR-330 'javax.inject.Inject' annotation found and supported for autowiring
2016-10-21 00:02:25.650 INFO 1642 --- [ main] e.m.mcrf.vakilabad.log.LogService : LogService init.
2016-10-21 00:02:25.767 INFO 1642 --- [ main] e.mfldclin.mcrf.vakilabad.log.LogFrame : Adding LogFrame instance to the LogMonitors of LogService: edu.mfldclin.mcrf.vakilabad.log.LogFrame[frame0,0,2,511x390,invalid,hidden,layout=java.awt.BorderLayout,title=Log since 2016-10-21T00:02:25.750,resizable,normal,defaultCloseOperation=DISPOSE_ON_CLOSE,rootPane=javax.swing.JRootPane[,0,22,511x368,invalid,layout=javax.swing.JRootPane$RootLayout,alignmentX=0.0,alignmentY=0.0,border=,flags=16777673,maximumSize=,minimumSize=,preferredSize=],rootPaneCheckingEnabled=true]
2016-10-21 00:02:25.897 WARN 1642 --- [ main] s.c.a.AnnotationConfigApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'org.springframework.boot.autoconfigure.info.ProjectInfoAutoConfiguration': Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'spring.info-org.springframework.boot.autoconfigure.info.ProjectInfoProperties': Initialization of bean failed; nested exception is javax.validation.ValidationException: Unable to create a Configuration, because no Bean Validation provider could be found. Add a provider like Hibernate Validator (RI) to your classpath.
2016-10-21 00:02:25.897 INFO 1642 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Unregistering JMX-exposed beans on shutdown
2016-10-21 00:02:25.902 INFO 1642 --- [ main] utoConfigurationReportLoggingInitializer :
Error starting ApplicationContext. To display the auto-configuration report re-run your application with 'debug' enabled.
2016-10-21 00:02:25.906 ERROR 1642 --- [ main] o.s.b.d.LoggingFailureAnalysisReporter :
***************************
APPLICATION FAILED TO START
***************************
Description:
The Bean Validation API is on the classpath but no implementation could be found
Action:
Add an implementation, such as Hibernate Validator, to the classpath
这是我添加的依赖:
<dependency>
<groupId>org.apache.spark</groupId>
<artifactId>spark-core_2.11</artifactId>
<version>2.0.1</version>
</dependency>
我在 spark-core_2.11-2.0.1.jar\META-INF\DEPENDENCIES
中看到并且有:
// ------------------------------------------------------------------
// Transitive dependencies of this project determined from the
// maven pom organized by organization.
// ------------------------------------------------------------------
Spark Project Core
From: 'an unknown organization'
...
...
- Bean Validation API (http://beanvalidation.org) javax.validation:validation-api:jar:1.1.0.Final
License: The Apache Software License, Version 2.0 (http://www.apache.org/licenses/LICENSE-2.0.txt)
和 @EnableAutoConfiguration
spring 可能会看到这种对类路径的依赖并尝试找到 Java specification for Bean Validation. (Some interesting reading for spring validation).
在我看来,这是因为 spark 使用 jersey
作为一种向我们展示工作状态等信息的方式 jersey bean-validation - 但我不太确定这个声明。
但是你可以通过提供 Bean Validation
的实现来解决这个问题 - 只需将实现的依赖添加到 maven。
Hibernate 验证器
<!-- https://mvnrepository.com/artifact/org.hibernate/hibernate-validator -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<version>5.3.0.Final</version>
</dependency>
或更快 (source) Apache BeanValidation.
<!-- https://mvnrepository.com/artifact/org.apache.bval/bval-jsr303 -->
<dependency>
<groupId>org.apache.bval</groupId>
<artifactId>bval-jsr303</artifactId>
<version>0.5</version>
</dependency>
解决方案在评论中! (排除验证API)