前言
本篇文章主要介绍的是SpringBoot一个完整的web项目整合storm以及在这过程遇到的一些问题和解决方案。
一、pom.xml
需要排除一些系统自带日志系统,通过在资源目录下引入logback.xml 记录日志
<!--其他详细的依赖见GitHub -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-to-slf4j</artifactId>
</exclusion>
</exclusions>
</dependency>
<!--storm相关jar -->
<dependency>
<groupId>org.apache.storm</groupId>
<artifactId>storm-core</artifactId>
<version>1.2.2</version>
<!--排除相关依赖 -->
<exclusions>
<exclusion>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j-impl</artifactId>
</exclusion>
<exclusion>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-1.2-api</artifactId>
</exclusion>
<exclusion>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-web</artifactId>
</exclusion>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
</exclusion>
<exclusion>
<artifactId>ring-cors</artifactId>
<groupId>ring-cors</groupId>
</exclusion>
</exclusions>
<!--<scope>provided</scope>-->
</dependency>
二、目录情况如下
image.png三、springboot启动
将storm引入springboot中启动
@SpringBootApplication
public class SpringbootStormApplication {
public static void main(String[] args) {
//SpringApplication.run(SpringbootStormApplication.class, args);
ConfigurableApplicationContext context = SpringApplication.run(SpringbootStormApplication.class, args);
GetSpringBean springBean=new GetSpringBean();
springBean.setApplicationContext(context);
TopologyApp app = context.getBean(TopologyApp.class);
try {
app.main(args);
} catch (InvalidTopologyException e) {
e.printStackTrace();
} catch (AuthorizationException e) {
e.printStackTrace();
} catch (AlreadyAliveException e) {
e.printStackTrace();
}
}
}
具体详见代码:https://github.com/CharmingGeeker/Storm-For-SpringBoot
网友评论