springBoot 整合storm

本文介绍了如何将Storm集成到SpringBoot应用中,包括添加依赖、编写Spout和Bolt、启动类设置以及注意事项。强调了Storm的组件在集群运行时的序列化问题,以及不能直接使用SpringBoot常规启动方式和获取Bean的方法。最后提到了特殊的打包要求。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1、添加依赖

<properties>
		<java.version>1.8</java.version>
		<storm.version>1.2.2</storm.version>
	</properties>

	<dependencies>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter</artifactId>
			<exclusions>
				<exclusion>
					<groupId>org.apache.logging.log4j</groupId>
					<artifactId>log4j-to-slf4j</artifactId>
				</exclusion>
				<exclusion>
					<groupId>ch.qos.logback</groupId>
					<artifactId>logback-classic</artifactId>
				</exclusion>
			</exclusions>
		</dependency>

		<!-- kafka -->
		<dependency>
            <groupId>org.apache.storm</groupId>
            <artifactId>storm-kafka-client</artifactId>
            <version>1.2.2</version>
        </dependency>

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

		<!-- storm -->
		<dependency>
			<groupId>org.apache.storm</groupId>
			<artifactId>storm-core</artifactId>
			<version>${storm.version}</version>
			<scope>provided</scope>
		</dependency>

		<dependency>
			<groupId>com.codahale.metrics</groupId>
			<artifactId>metrics-core</artifactId>
			<version>3.0.2</version>
			<scope>provided</scope>
		</dependency>
	</dependencies>

	<build>
		<plugins>
			<!-- <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> 
				<configuration> <fork>true</fork> </configuration> </plugin> -->
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-shade-plugin</artifactId>
				<executions>
					<execution>
						<phase>package</phase>
						<goals>
							<goal>shade</goal>
						</goals>
					</execution>
				</executions>
				<configuration>
					<createDependencyReducedPom>false</createDependencyReducedPom>
					<artifactSet>
						<excludes>
							<exclude>commons-logging:commons-logging</exclude>
							<exclude>javax.servlet:servlet-api</exclude>
							<exclude>javax.mail:javax.mail-api</exclude>
						</excludes>
					</artifactSet>
				</configuration>
			</plugin>
		</plugins>
	</build>

2、编写application工具类

@Component
public class SpringBeanUtils implements ApplicationContextAware {
    
    /**
     * 上下文对象实例
     */
    priva
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值