2015-07-16 10 views
8

Tôi đã phát triển một ứng dụng web với Spring Boot sử dụng Apache Spark để truy vấn dữ liệu từ các nguồn dữ liệu khác nhau (như Oracle). Lúc đầu, tôi đã lên kế hoạch để chạy ứng dụng mà không cần gửi nó bằng cách sử dụng kịch bản lệnh spark-submit, nhưng có vẻ như tôi không thể kết nối với cụm Master mà không cần gửi một cái bình. Tôi đã tạo thành công một lọ uber bao gồm tất cả các phụ thuộc và các dự án phụ mà tôi đang sử dụng, nhưng có vẻ như là Spark không thích các ứng dụng Khởi động mùa xuân. Khi tôi cố gắng trình ứng dụng, tia lửa cho thấy lỗi sau:Không thể gửi ứng dụng java khởi động Spring tới Spark cluster

Exception in thread "main" java.lang.IllegalArgumentException: LoggerFactory is not a Logback LoggerContext but Logback is on the classpath. Either remove Logback or the competing implementation (class org.slf4j.impl.Log4jLoggerFactory loaded from file:/home/rojasmi1/spark/spark-1.4.0/assembly/target/scala-2.10/spark-assembly-1.4.0-hadoop2.2.0.jar). If you are using Weblogic you will need to add 'org.slf4j' to prefer-application-packages in WEB-INF/weblogic.xml Object of class [org.slf4j.impl.Log4jLoggerFactory] must be an instance of class ch.qos.logback.classic.LoggerContext 
at org.springframework.util.Assert.isInstanceOf(Assert.java:339) 
at org.springframework.boot.logging.logback.LogbackLoggingSystem.getLoggerContext(LogbackLoggingSystem.java:151) 
at org.springframework.boot.logging.logback.LogbackLoggingSystem.getLogger(LogbackLoggingSystem.java:143) 
at org.springframework.boot.logging.logback.LogbackLoggingSystem.beforeInitialize(LogbackLoggingSystem.java:89) 
at org.springframework.boot.logging.LoggingApplicationListener.onApplicationStartedEvent(LoggingApplicationListener.java:152) 
at org.springframework.boot.logging.LoggingApplicationListener.onApplicationEvent(LoggingApplicationListener.java:139) 
at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:151) 
at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:128) 
at org.springframework.boot.context.event.EventPublishingRunListener.publishEvent(EventPublishingRunListener.java:100) 
at org.springframework.boot.context.event.EventPublishingRunListener.started(EventPublishingRunListener.java:54) 
at org.springframework.boot.SpringApplication.run(SpringApplication.java:277) 
at org.springframework.boot.SpringApplication.run(SpringApplication.java:957) 
at org.springframework.boot.SpringApplication.run(SpringApplication.java:946) 
at ch.dlx.QubidaOracleConnectorApplication.main(QubidaOracleConnectorApplication.java:12) 
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) 
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 
at java.lang.reflect.Method.invoke(Method.java:497) 
at org.apache.spark.deploy.SparkSubmit$.org$apache$spark$deploy$SparkSubmit$$runMain(SparkSubmit.scala:664) 
at org.apache.spark.deploy.SparkSubmit$.doRunMain$1(SparkSubmit.scala:169) 
at org.apache.spark.deploy.SparkSubmit$.submit(SparkSubmit.scala:192) 
at org.apache.spark.deploy.SparkSubmit$.main(SparkSubmit.scala:111) 
at org.apache.spark.deploy.SparkSubmit.main(SparkSubmit.scala) 

Sử dụng hồ sơ log4j mặc định Spark: org/apache/tia lửa/log4j-defaults.properties

Tôi đã cố gắng để loại trừ các slf4j- phụ thuộc log4j12 trong tệp pom, nhưng tôi vẫn nhận được lỗi tương tự.

Các tập tin pom chứa các cấu hình sau:

<?xml version="1.0" encoding="UTF-8"?> 
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 
<modelVersion>4.0.0</modelVersion> 

<groupId>ch.dlx</groupId> 
<artifactId>qubida-oracle-connector</artifactId> 
<version>0.0.1-SNAPSHOT</version> 

<name>qubida-oracle-connector</name> 
<description></description> 

<properties> 
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 
    <java.version>1.8</java.version> 
</properties> 

<dependencyManagement> 
    <dependencies> 
     <dependency> 
      <groupId>org.springframework.boot</groupId> 
      <artifactId>spring-boot-dependencies</artifactId> 
      <version>1.2.5.RELEASE</version> 
      <type>pom</type> 
      <scope>import</scope> 
     </dependency> 
    </dependencies> 
</dependencyManagement> 

<dependencies> 
    <dependency> 
     <groupId>org.springframework.boot</groupId> 
     <artifactId>spring-boot-starter-web</artifactId> 
     <exclusions> 
      <exclusion> 
       <groupId>org.slf4j</groupId> 
       <artifactId>log4j-over-slf4j</artifactId> 
      </exclusion> 

     </exclusions> 
    </dependency> 

    <dependency> 
     <groupId>org.springframework.boot</groupId> 
     <artifactId>spring-boot-starter-tomcat</artifactId> 
    </dependency> 

    <dependency> 
     <groupId>org.springframework.boot</groupId> 
     <artifactId>spring-boot-starter-test</artifactId> 
     <scope>test</scope> 
    </dependency> 

    <!-- Spark --> 

    <dependency> 
     <groupId>org.apache.spark</groupId> 
     <artifactId>spark-core_2.11</artifactId> 
     <version>1.4.0</version> 
     <scope>provided</scope> 
     <exclusions> 
        <exclusion> 
    <groupId>org.slf4j</groupId> 
    <artifactId>slf4j-log4j12</artifactId> 
    </exclusion> 
     </exclusions> 
    </dependency> 

    <dependency> 
     <groupId>org.apache.spark</groupId> 
     <artifactId>spark-sql_2.11</artifactId> 
     <version>1.4.0</version> 
     <scope>provided</scope> 
    </dependency> 

    <dependency> 
     <groupId>org.mongodb</groupId> 
     <artifactId>mongo-hadoop-core</artifactId> 
     <version>1.3.0</version> 
     <exclusions> 
      <exclusion> 
       <groupId>org.slf4j</groupId> 
       <artifactId>log4j-over-slf4j</artifactId> 
      </exclusion> 
     </exclusions> 
    </dependency> 

    <!-- DB Drivers --> 

    <dependency> 
     <groupId>com.oracle</groupId> 
     <artifactId>ojdbc14</artifactId> 
     <version>10.2.0.4.0</version> 
    </dependency> 


</dependencies> 

<build> 
    <plugins> 
     <plugin> 
      <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-shade-plugin</artifactId> 
      <configuration> 
       <createDependencyReducedPom>false</createDependencyReducedPom> 
       <keepDependenciesWithProvidedScope>true</keepDependenciesWithProvidedScope> 

       <artifactSet> 
        <excludes> 
         <exclude>org.slf4j</exclude> 
        </excludes> 
       </artifactSet> 
      </configuration> 
      <executions> 
       <execution> 
        <phase>package</phase> 
        <goals> 
         <goal>shade</goal> 
        </goals> 
       </execution> 
      </executions> 
     </plugin> 
    </plugins> 
</build> 

Có cách nào để nộp đơn khởi động mùa xuân vào cluster? Tôi có nên sử dụng một loại dự án khác có tính đến việc tôi cần hiển thị API RESTful không? Có cách nào để kết nối với cụm tia lửa mà không cần gửi .jar?

Cảm ơn trước sự giúp đỡ của bạn.

Trả lời

4

Tôi đã có một vấn đề tương tự, để giải quyết nó cố gắng loại bỏ xuân Boot đăng nhập với việc loại trừ sau:

<dependency> 
     <groupId>org.springframework.boot</groupId> 
     <artifactId>spring-boot-starter-web</artifactId> 
     <exclusions> 
      <exclusion> 
       <groupId>org.springframework.boot</groupId> 
       <artifactId>spring-boot-starter-logging</artifactId> 
      </exclusion> 
     </exclusions> 
    </dependency> 

Nếu bạn vẫn nhận được một lỗi khi khởi tạo servlet

java.lang.NoSuchMethodError: javax.servlet.ServletContext.getVirtualServerName()Ljava/lang/String;

Sau đó, hãy thử sử dụng phiên bản 1.2.1.RELEASE của cha mẹ khởi động, vì điều đó được gây ra vì phiên bản servlet-api được sử dụng bởi cụm Spark.

+0

Đây chính là giải pháp cho vấn đề của tôi. Xin chào 5! –

1

Khi khởi động Spring Boot thời gian xây dựng, hãy xem bạn đã bao gồm triển khai ghi nhật ký cụ thể trong bản dựng của bạn chưa và sử dụng Logback theo mặc định. Rõ ràng Spark đang thêm Log4J vào classpath khi chạy ứng dụng của bạn, do đó nó gây ra lỗi thời gian chạy vì Spring Boot bây giờ tìm thấy hai cài đặt logger trên classpath: nó được bao gồm trong build-time (Logback) và Spark thêm vào thời gian chạy (Log4J).

Nếu Spark cung cấp cách ngăn chặn sự bao gồm của Log4J vào thời gian chạy, bạn có thể thực hiện điều đó và chỉ để cho dây khởi động mùa xuân trong Logback theo mặc định.

Nếu Spark buộc Log4J vào bạn, thì giải pháp sẽ bao gồm Log4J (không Logback) trong bản dựng của bạn sao cho Spring Boot sẽ "xem" nó là thời gian xây dựng, và do đó không bao gồm Logback.

EDIT: Tôi nên kiểm tra giả định của mình bằng cách xem tài liệu Khởi động mùa xuân. Bạn cũng phải loại trừ rõ ràng Log4J. Xem Spring Boot's Logging Docs.

+0

Kính gửi RichW. Tôi đã làm theo cách tiếp cận thứ hai mà bạn đề xuất (Nếu Spark buộc Log4J vào bạn, thì giải pháp sẽ bao gồm Log4J (không Logback) trong bản build của bạn để Spring Boot sẽ "xem" nó là build-time, và do đó không bao gồm Logback), nhưng vấn đề không may vẫn còn. Đây là cách tôi một cách rõ ràng thêm depedency Log4j: ' log4j log4j 'Bạn có biết những gì khác tôi có thể thử? –

+0

Xin lỗi về điều đó, Stefan, tôi bị lừa. Tôi đã chỉnh sửa câu trả lời của mình. – RichW

0

Spark chỉ hỗ trợ log4j. Để buộc spring-boot sử dụng log4j thay vì logback theo mặc định, hãy áp dụng this procedure from spring-boot reference documentation nhưng đảm bảo thay đổi log4j2 thành log4j và cung cấp cho nó một phiên bản, ví dụ: 1.2.17. Bạn cũng sẽ cần phải đặt một tệp log4j.properties trong src/main/resources. Bạn có thể sao chép log4j.properties.mẫu từ thư mục Spark/conf và đổi tên nó thành log4j.properties.

Các vấn đề liên quan