@Configuration
class sparkConfig {
@Autowired
@transient
var sparkInfo: SparkInfo = _
@Bean
def getSparkSession(): SparkSession = {
val sparkSession = SparkSession.builder()
.appName(sparkInfo.getAppName)
.master(sparkInfo.getMaster)
.config("spark.driver.memory", sparkInfo.getDriverMemory)
.config("spark.worker.memory", sparkInfo.getWorkerMemory)
.config("spark.executor.memory", sparkInfo.getExecutorMemory)
.config("spark.serializer", classOf[KryoSerializer].getName)
.getOrCreate()
sparkSession
}
@Bean
@ConditionalOnMissingBean(Array(classOf[SparkSession]))
def getSparkStreaming(@Autowired sparkSession: SparkSession): StreamingContext = {
val ssc = new StreamingContext(sparkSession.sparkContext, Seconds(sparkInfo.getPeriod))
ssc
}
}
其他类中如何调用getSparkStreaming方法?
临摹微笑