添加启动项。Edit Configurations->点击 号->Application添加一个启动项,然后填写如下内容
编辑启动项
在build.gradle中添加如下内容,其中2.12.0
改为你使用的对应版本即可
dependencies {
compile 'org.scala-lang:scala-library:2.12.0'
}
解决报错
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder"
代码语言:javascript复制SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
在build.gradle
的子项目core
中需要添加这两个依赖:
project(':core') {
println "Building project 'core' with Scala version ${versions.scala}"
...
dependencies {
...
// 添加以下两个依赖
// https://mvnrepository.com/artifact/org.slf4j/slf4j-api
compile group: 'org.slf4j', name: 'slf4j-api', version: '1.7.25'
// https://mvnrepository.com/artifact/org.slf4j/slf4j-log4j12
compile group: 'org.slf4j', name: 'slf4j-log4j12', version: '1.7.25'
}
这两行首先要添加slf4j的依赖,还要添加基于slf4j的log4j12的依赖。注意这里一定要用compile
而不是testCompile
,因为后者的意思是只在test环境下编译.
我当时就是因为直接从Maven官网上拷贝了如下内容翻了车:
代码语言:javascript复制testCompile group: 'org.slf4j', name: 'slf4j-log4j12', version: '1.7.25' // 不要这样写
log4j:WARN No appenders could be found for logger (LoggerMain).
代码语言:javascript复制log4j:WARN No appenders could be found for logger (LoggerMain).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
创建src/main/resources
文件夹,创建文件log4j.properties,并写入以下内容:
### 设置###
log4j.rootLogger = debug,stdout
### 输出信息到控制抬 ###
log4j.appender.stdout = org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target = System.out
log4j.appender.stdout.Threshold = INFO
log4j.appender.stdout.layout = org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern = [%-5p] %d{yyyy-MM-dd HH:mm:ss,SSS} method:%l%n%m%n
其它踩坑
- 项目gradle不使用国内源,否则
gradle idea
会很慢 - zookeeper启动时要绑定本地端口
- Cannot infer Scala class path because no Scala library Jar was found.
- kafka-console-producer.sh测试生产、消费