我正在构建一个Spring MVC项目,该项目在某些时候应该能够从Kafka主题中读取并将消耗的数据发送到某个前端。为此,我使用:
这就是我所拥有的:
KafkaConfig.java
@Configuration
@EnableKafka
public class KafkaConfig {
@Bean
KafkaListenerContainerFactory<ConcurrentMessageListenerContainer<String, String>>
kafkaListenerContainerFactory() {
ConcurrentKafkaListenerContainerFactory<String, String> factory =
new ConcurrentKafkaListenerContainerFactory<>();
factory.setConsumerFactory(consumerFactory());
factory.setConcurrency(3);
factory.getContainerProperties().setPollTimeout(3000);
return factory;
}
@Bean
public ConsumerFactory<String, String> consumerFactory() {
return new DefaultKafkaConsumerFactory<>(consumerConfigs());
}
@Bean
public Map<String, Object> consumerConfigs() {
Map<String, Object> props = new HashMap<>();
props.put("bootstrap.servers", "localhost:9092");
props.put("group.id", "metrics");
props.put("enable.auto.commit", "true");
props.put("auto.commit.interval.ms", "1000");
props.put("session.timeout.ms", "30000");
props.put("key.deserializer", "org.apache.kafka.common.serialization.StringDeserializer");
props.put("value.deserializer", "org.apache.kafka.common.serialization.StringDeserializer");
return props;
}
@Bean
public KafkaReceiver receiver() {
return new KafkaReceiver();
}
}
KafkaReceiver.java
public class KafkaReceiver {
@Autowired
private SimpMessagingTemplate simpMessagingTemplate;
@KafkaListener(topics = "metrics")
public void receive(ConsumerRecord<?, ?> record) {
MetricRecord m = new MetricRecord(new Long(record.offset()), record.key().toString(), record.value().toString());
this.simpMessagingTemplate.convertAndSend("/metrics/records", m.toString());
}
}
我也有WebSocketConfig。这时,它是:
@Configuration
@EnableWebSocketMessageBroker
public class WebSocketConfig extends AbstractWebSocketMessageBrokerConfigurer {
@Override
public void configureMessageBroker(MessageBrokerRegistry config) {
config.enableSimpleBroker("/metrics");
config.setApplicationDestinationPrefixes("/metricsApp");
}
@Override
public void registerStompEndpoints(StompEndpointRegistry registry) {
registry.addEndpoint("/kafka-metrics-websocket").withSockJS();
}
}
这是我的依赖树:
[INFO] +- org.springframework.kafka:spring-kafka:jar:2.0.0.RELEASE:compile
[INFO] | +- org.springframework:spring-context:jar:5.0.0.RELEASE:compile
[INFO] | +- org.springframework:spring-messaging:jar:5.0.0.RELEASE:compile
[INFO] | +- org.springframework:spring-tx:jar:5.0.0.RELEASE:compile
[INFO] | +- org.springframework.retry:spring-retry:jar:1.2.0.RELEASE:compile
[INFO] | \- org.apache.kafka:kafka-clients:jar:0.11.0.0:compile
[INFO] | +- net.jpountz.lz4:lz4:jar:1.3.0:compile
[INFO] | \- org.xerial.snappy:snappy-java:jar:1.1.2.6:compile
[INFO] +- org.springframework:spring-core:jar:4.3.11.RELEASE:compile
[INFO] | \- commons-logging:commons-logging:jar:1.2:compile
[INFO] +- org.springframework:spring-beans:jar:5.0.0.RELEASE:compile
[INFO] +- org.springframework:spring-websocket:jar:4.3.11.RELEASE:compile
[INFO] | \- org.springframework:spring-web:jar:4.3.11.RELEASE:compile
[INFO] +- org.apache.hbase:hbase-client:jar:1.3.1:compile
[INFO] | +- org.apache.hbase:hbase-annotations:jar:1.3.1:compile
[INFO] | | +- com.github.stephenc.findbugs:findbugs-annotations:jar:1.3.9-1:compile
[INFO] | | \- log4j:log4j:jar:1.2.17:compile
[INFO] | +- org.apache.hbase:hbase-common:jar:1.3.1:compile
[INFO] | | +- commons-collections:commons-collections:jar:3.2.2:compile
[INFO] | | \- org.mortbay.jetty:jetty-util:jar:6.1.26:compile
[INFO] | +- org.apache.hbase:hbase-protocol:jar:1.3.1:compile
[INFO] | +- commons-codec:commons-codec:jar:1.9:compile
[INFO] | +- commons-io:commons-io:jar:2.4:compile
[INFO] | +- commons-lang:commons-lang:jar:2.6:compile
[INFO] | +- com.google.guava:guava:jar:12.0.1:compile
[INFO] | +- com.google.protobuf:protobuf-java:jar:2.5.0:compile
[INFO] | +- io.netty:netty-all:jar:4.0.23.Final:compile
[INFO] | +- org.apache.zookeeper:zookeeper:jar:3.4.6:compile
[INFO] | | \- org.slf4j:slf4j-log4j12:jar:1.6.1:compile
[INFO] | +- org.apache.htrace:htrace-core:jar:3.1.0-incubating:compile
[INFO] | +- org.codehaus.jackson:jackson-mapper-asl:jar:1.9.13:compile
[INFO] | | \- org.codehaus.jackson:jackson-core-asl:jar:1.9.13:compile
[INFO] | +- org.jruby.jcodings:jcodings:jar:1.0.8:compile
[INFO] | +- org.jruby.joni:joni:jar:2.1.2:compile
[INFO] | +- com.yammer.metrics:metrics-core:jar:2.2.0:compile
[INFO] | +- org.apache.hadoop:hadoop-auth:jar:2.5.1:compile
[INFO] | | +- org.apache.httpcomponents:httpclient:jar:4.2.5:compile
[INFO] | | | \- org.apache.httpcomponents:httpcore:jar:4.2.4:compile
[INFO] | | \- org.apache.directory.server:apacheds-kerberos-codec:jar:2.0.0-M15:compile
[INFO] | | +- org.apache.directory.server:apacheds-i18n:jar:2.0.0-M15:compile
[INFO] | | +- org.apache.directory.api:api-asn1-api:jar:1.0.0-M20:compile
[INFO] | | \- org.apache.directory.api:api-util:jar:1.0.0-M20:compile
[INFO] | +- org.apache.hadoop:hadoop-common:jar:2.5.1:compile
[INFO] | | +- org.apache.hadoop:hadoop-annotations:jar:2.5.1:compile
[INFO] | | | \- jdk.tools:jdk.tools:jar:1.6:system
[INFO] | | +- commons-cli:commons-cli:jar:1.2:compile
[INFO] | | +- org.apache.commons:commons-math3:jar:3.1.1:compile
[INFO] | | +- xmlenc:xmlenc:jar:0.52:compile
[INFO] | | +- commons-httpclient:commons-httpclient:jar:3.1:compile
[INFO] | | +- commons-net:commons-net:jar:3.1:compile
[INFO] | | +- commons-el:commons-el:jar:1.0:runtime
[INFO] | | +- commons-configuration:commons-configuration:jar:1.6:compile
[INFO] | | | +- commons-digester:commons-digester:jar:1.8:compile
[INFO] | | | | \- commons-beanutils:commons-beanutils:jar:1.7.0:compile
[INFO] | | | \- commons-beanutils:commons-beanutils-core:jar:1.8.0:compile
[INFO] | | +- org.apache.avro:avro:jar:1.7.4:compile
[INFO] | | | \- com.thoughtworks.paranamer:paranamer:jar:2.3:compile
[INFO] | | +- com.jcraft:jsch:jar:0.1.42:compile
[INFO] | | +- com.google.code.findbugs:jsr305:jar:1.3.9:compile
[INFO] | | \- org.apache.commons:commons-compress:jar:1.4.1:compile
[INFO] | | \- org.tukaani:xz:jar:1.0:compile
[INFO] | +- org.apache.hadoop:hadoop-mapreduce-client-core:jar:2.5.1:compile
[INFO] | | +- org.apache.hadoop:hadoop-yarn-common:jar:2.5.1:compile
[INFO] | | | +- org.apache.hadoop:hadoop-yarn-api:jar:2.5.1:compile
[INFO] | | | \- javax.xml.bind:jaxb-api:jar:2.2.2:compile
[INFO] | | | +- javax.xml.stream:stax-api:jar:1.0-2:compile
[INFO] | | | \- javax.activation:activation:jar:1.1:compile
[INFO] | | \- io.netty:netty:jar:3.6.2.Final:compile
[INFO] | \- junit:junit:jar:4.12:compile
[INFO] | \- org.hamcrest:hamcrest-core:jar:1.3:compile
[INFO] +- org.springframework:spring-webmvc:jar:4.3.10.RELEASE:compile
[INFO] | +- org.springframework:spring-aop:jar:4.3.10.RELEASE:compile
[INFO] | \- org.springframework:spring-expression:jar:4.3.10.RELEASE:compile
[INFO] +- javax.servlet:javax.servlet-api:jar:4.0.0:provided
[INFO] +- org.thymeleaf:thymeleaf-spring4:jar:2.1.5.RELEASE:compile
[INFO] | +- org.thymeleaf:thymeleaf:jar:2.1.5.RELEASE:compile
[INFO] | | +- ognl:ognl:jar:3.0.8:compile
[INFO] | | +- org.javassist:javassist:jar:3.16.1-GA:compile
[INFO] | | \- org.unbescape:unbescape:jar:1.1.0.RELEASE:compile
[INFO] | \- org.slf4j:slf4j-api:jar:1.6.6:compile
[INFO] +- org.springframework.data:spring-data-hadoop:jar:2.5.0.RELEASE:compile
[INFO] | +- org.springframework.data:spring-data-hadoop-core:jar:2.5.0.RELEASE:compile
[INFO] | | +- org.apache.hadoop:hadoop-streaming:jar:2.7.3:compile
[INFO] | | +- org.apache.hadoop:hadoop-distcp:jar:2.7.3:compile
[INFO] | | +- org.apache.hadoop:hadoop-hdfs:jar:2.7.3:compile
[INFO] | | | +- org.mortbay.jetty:jetty:jar:6.1.26:compile
[INFO] | | | +- com.sun.jersey:jersey-core:jar:1.9:compile
[INFO] | | | +- com.sun.jersey:jersey-server:jar:1.9:compile
[INFO] | | | | \- asm:asm:jar:3.1:compile
[INFO] | | | +- commons-daemon:commons-daemon:jar:1.0.13:compile
[INFO] | | | +- javax.servlet:servlet-api:jar:2.5:compile
[INFO] | | | +- xerces:xercesImpl:jar:2.9.1:compile
[INFO] | | | | \- xml-apis:xml-apis:jar:1.3.04:compile
[INFO] | | | \- org.fusesource.leveldbjni:leveldbjni-all:jar:1.8:compile
[INFO] | | \- org.apache.hadoop:hadoop-mapreduce-client-jobclient:jar:2.7.3:compile
[INFO] | | +- org.apache.hadoop:hadoop-mapreduce-client-common:jar:2.7.3:compile
[INFO] | | | +- org.apache.hadoop:hadoop-yarn-client:jar:2.7.3:compile
[INFO] | | | \- org.apache.hadoop:hadoop-yarn-server-common:jar:2.7.3:compile
[INFO] | | +- org.apache.hadoop:hadoop-mapreduce-client-shuffle:jar:2.7.3:compile
[INFO] | | | \- org.apache.hadoop:hadoop-yarn-server-nodemanager:jar:2.7.3:compile
[INFO] | | | +- com.sun.jersey:jersey-client:jar:1.9:compile
[INFO] | | | +- com.sun.jersey:jersey-json:jar:1.9:compile
[INFO] | | | | +- com.sun.xml.bind:jaxb-impl:jar:2.2.3-1:compile
[INFO] | | | | +- org.codehaus.jackson:jackson-jaxrs:jar:1.8.3:compile
[INFO] | | | | \- org.codehaus.jackson:jackson-xc:jar:1.8.3:compile
[INFO] | | | \- com.sun.jersey.contribs:jersey-guice:jar:1.9:compile
[INFO] | | \- com.google.inject.extensions:guice-servlet:jar:3.0:compile
[INFO] | | \- com.google.inject:guice:jar:3.0:compile
[INFO] | | \- javax.inject:javax.inject:jar:1:compile
[INFO] | +- org.springframework.data:spring-data-hadoop-hive:jar:2.5.0.RELEASE:compile
[INFO] | | \- org.springframework.batch:spring-batch-core:jar:3.0.7.RELEASE:compile
[INFO] | | +- com.ibm.jbatch:com.ibm.jbatch-tck-spi:jar:1.0:compile
[INFO] | | | \- javax.batch:javax.batch-api:jar:1.0:compile
[INFO] | | +- com.thoughtworks.xstream:xstream:jar:1.4.7:compile
[INFO] | | | +- xmlpull:xmlpull:jar:1.1.3.1:compile
[INFO] | | | \- xpp3:xpp3_min:jar:1.1.4c:compile
[INFO] | | +- org.codehaus.jettison:jettison:jar:1.2:compile
[INFO] | | \- org.springframework.batch:spring-batch-infrastructure:jar:3.0.7.RELEASE:compile
[INFO] | +- org.springframework:spring-context-support:jar:4.3.9.RELEASE:compile
[INFO] | +- org.springframework.data:spring-data-hadoop-hbase:jar:2.5.0.RELEASE:compile
[INFO] | +- org.springframework:spring-jdbc:jar:4.3.9.RELEASE:compile
[INFO] | +- org.springframework.data:spring-data-hadoop-pig:jar:2.5.0.RELEASE:compile
[INFO] | \- org.springframework.data:spring-data-hadoop-batch:jar:2.5.0.RELEASE:compile
[INFO] +- org.springframework:spring-dao:jar:2.0.8:compile
[INFO] | \- aopalliance:aopalliance:jar:1.0:compile
[INFO] +- com.fasterxml.jackson.core:jackson-core:jar:2.9.0:compile
[INFO] \- com.fasterxml.jackson.core:jackson-databind:jar:2.9.0:compile
[INFO] \- com.fasterxml.jackson.core:jackson-annotations:jar:2.9.0:compile
运行此项目时,我收到以下错误(完整日志):
java.lang.NullPointerException
at org.springframework.context.annotation.AnnotationBeanNameGenerator.isStereotypeWithNameValue(AnnotationBeanNameGenerator.java:123)
at org.springframework.context.annotation.AnnotationBeanNameGenerator.determineBeanNameFromAnnotation(AnnotationBeanNameGenerator.java:94)
at org.springframework.context.annotation.AnnotationBeanNameGenerator.generateBeanName(AnnotationBeanNameGenerator.java:72)
at org.springframework.context.annotation.AnnotatedBeanDefinitionReader.doRegisterBean(AnnotatedBeanDefinitionReader.java:224)
at org.springframework.context.annotation.AnnotatedBeanDefinitionReader.registerBean(AnnotatedBeanDefinitionReader.java:145)
at org.springframework.context.annotation.AnnotatedBeanDefinitionReader.register(AnnotatedBeanDefinitionReader.java:135)
at org.springframework.web.context.support.AnnotationConfigWebApplicationContext.loadBeanDefinitions(AnnotationConfigWebApplicationContext.java:210)
at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:133)
at org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:620)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:521)
at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:443)
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:325)
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:107)
at org.eclipse.jetty.server.handler.ContextHandler.callContextInitialized(ContextHandler.java:890)
at org.eclipse.jetty.servlet.ServletContextHandler.callContextInitialized(ServletContextHandler.java:532)
at org.eclipse.jetty.server.handler.ContextHandler.startContext(ContextHandler.java:853)
at org.eclipse.jetty.servlet.ServletContextHandler.startContext(ServletContextHandler.java:344)
at org.eclipse.jetty.webapp.WebAppContext.startWebapp(WebAppContext.java:1501)
at org.eclipse.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1463)
at org.eclipse.jetty.server.handler.ContextHandler.doStart(ContextHandler.java:785)
at org.eclipse.jetty.servlet.ServletContextHandler.doStart(ServletContextHandler.java:261)
at org.eclipse.jetty.webapp.WebAppContext.doStart(WebAppContext.java:545)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)
at org.eclipse.jetty.deploy.bindings.StandardStarter.processBinding(StandardStarter.java:41)
at org.eclipse.jetty.deploy.AppLifeCycle.runBindings(AppLifeCycle.java:188)
at org.eclipse.jetty.deploy.DeploymentManager.requestAppGoal(DeploymentManager.java:502)
at org.eclipse.jetty.deploy.DeploymentManager.addApp(DeploymentManager.java:150)
at org.eclipse.jetty.deploy.providers.ScanningAppProvider.fileAdded(ScanningAppProvider.java:180)
at org.eclipse.jetty.deploy.providers.WebAppProvider.fileAdded(WebAppProvider.java:447)
at org.eclipse.jetty.deploy.providers.ScanningAppProvider$1.fileAdded(ScanningAppProvider.java:64)
at org.eclipse.jetty.util.Scanner.reportAddition(Scanner.java:610)
at org.eclipse.jetty.util.Scanner.reportDifferences(Scanner.java:529)
at org.eclipse.jetty.util.Scanner.scan(Scanner.java:392)
at org.eclipse.jetty.util.Scanner.doStart(Scanner.java:313)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)
at org.eclipse.jetty.deploy.providers.ScanningAppProvider.doStart(ScanningAppProvider.java:150)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)
at org.eclipse.jetty.deploy.DeploymentManager.startAppProvider(DeploymentManager.java:564)
at org.eclipse.jetty.deploy.DeploymentManager.doStart(DeploymentManager.java:239)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)
at org.eclipse.jetty.util.component.ContainerLifeCycle.start(ContainerLifeCycle.java:131)
at org.eclipse.jetty.server.Server.start(Server.java:452)
at org.eclipse.jetty.util.component.ContainerLifeCycle.doStart(ContainerLifeCycle.java:113)
at org.eclipse.jetty.server.handler.AbstractHandler.doStart(AbstractHandler.java:113)
at org.eclipse.jetty.server.Server.doStart(Server.java:419)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)
at org.eclipse.jetty.xml.XmlConfiguration$1.run(XmlConfiguration.java:1515)
at org.eclipse.jetty.xml.XmlConfiguration$1.run(XmlConfiguration.java:1439)
at java.security.AccessController.doPrivileged(Native Method)
at org.eclipse.jetty.xml.XmlConfiguration.main(XmlConfiguration.java:1438)
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:498)
at org.eclipse.jetty.start.Main.invokeMain(Main.java:221)
at org.eclipse.jetty.start.Main.start(Main.java:506)
at org.eclipse.jetty.start.Main.main(Main.java:78)
2017-10-02 16:25:35.967:INFO:oejs.AbstractConnector:main: Started ServerConnector@6b695b06{HTTP/1.1,[http/1.1]}{0.0.0.0:8082}
2017-10-02 16:25:35.970:INFO:oejs.Server:main: Started @7601ms
有什么想法吗?
答案 0 :(得分:0)
我认为确实有更多的堆栈跟踪来确定原因的根源。
另一方面,你提到了Spring Websockets,但我们真的没有看到任何声明。像@EnableWebSocketMessageBroker
?
<强>更新强>
您有多种版本:
[INFO] +- org.springframework:spring-beans:jar:5.0.0.RELEASE:compile
[INFO] +- org.springframework:spring-websocket:jar:4.3.11.RELEASE:compile
[INFO] | \- org.springframework:spring-web:jar:4.3.11.RELEASE:compile
考虑使用版本org.springframework
中5.0
的所有内容。