Spring中的aware接口详情
1045
2022-08-27
springboot集成spark并使用spark
首先添加相关依赖:
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer"> implementation="org.springframework.boot.maven.PropertiesMergingResourceTransformer"> implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer"> implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer" /> implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
implementation="org.springframework.boot.maven.PropertiesMergingResourceTransformer">
implementation="org.springframework.boot.maven.PropertiesMergingResourceTransformer">
implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer" /> implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer" />
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
需要注意的是依赖中排除掉的日志模块,以及特殊的打包方式
定义配置类:
SparkContextBean.class
@Configuration
public class SparkContextBean {
private String appName = "sparkExp";
private String master = "local";
@Bean
@ConditionalOnMissingBean(SparkConf.class)
public SparkConf sparkConf() throws Exception {
SparkConf conf = new SparkConf().setAppName(appName).setMaster(master);
return conf;
}
@Bean
@ConditionalOnMissingBean
public JavaSparkContext javaSparkContext() throws Exception {
return new JavaSparkContext(sparkConf());
}
@Bean
@ConditionalOnMissingBean
publiDdTpJc HiveContext hiveContext() throws Exception {
return new HiveContext(javaSparkContext());
}
......
}
启动类:
StartApplication.class
@SpringBootApplication
public class StartApplication implements CommandLineRunner {
@Autowired
private HiveContext hc;
public static void main(String[] args) {
SpringApplication.run(StartApplication.class, args);
}
@Override
public void run(String... args) throws Exception {
DataFrame df = hc.sql("select count(1) from LCS_DB.STAFF_INFO");
List
return row.getLong(0);
}).collect();
result.stream().forEach(System.out::println);
}
执行方式:
spark-submit \
--class com.cord.StartApplication \
--executor-memory 4G \
--num-executors 8 \
--master yarn-client \
/data/cord/spark-example-1.0-SNAPSHOT.jar
参考链接:
https://stackoverflow.com/questions/45189701/submitting-spring-boot-application-jar-to-spark-submit
https://my.oschina.net/woter/blog/1843755
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
发表评论
暂时没有评论,来抢沙发吧~