【发布时间】:2018-10-19 13:33:39
【问题描述】:
我已将 Gradle 构建脚本更改为使用 Spring 2.0.1 而不是 1.5.9。当我运行gradle build 时,我得到error: cannot find symbol Logger logger = Logger.getLogger(this.getClass().getName())。它与以前的 Spring Boot 版本配合得很好。代码使用import org.apache.log4j.Logger;。如何解决这个问题?
build.gradle文件:
buildscript {
ext {
springBootVersion = '2.0.1.RELEASE'
}
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
apply plugin: 'jacoco'
apply plugin: 'war'
sourceCompatibility = 1.8
repositories {
mavenCentral()
maven { url "https://repo.spring.io/snapshot" }
maven { url "https://repo.spring.io/milestone" }
}
bootRun {
sourceResources sourceSets.main
}
sourceSets {
main {
java {
srcDirs = ["src/main/java", "src/generated/main/java"]
}
}
}
dependencies {
compile("org.springframework.boot:spring-boot-starter-web") {
exclude module: "spring-boot-starter-tomcat"
}
providedRuntime group: 'org.springframework.boot', name: 'spring-boot-starter-tomcat'
compile 'org.springframework.boot:spring-boot-starter-actuator'
compile 'org.springframework.boot:spring-boot-starter'
compile 'org.springframework.boot:spring-boot-starter-data-jpa'
compile 'org.springframework.boot:spring-boot-starter-velocity:1.4.7.RELEASE'
compile 'com.fasterxml.jackson.datatype:jackson-datatype-jsr310'
compile 'com.ryantenney.metrics:metrics-spring:3.1.3'
compile 'com.github.ben-manes.caffeine:caffeine:2.6.2'
compile 'org.hibernate:hibernate-java8'
compile 'org.postgresql:postgresql'
compile 'org.apache.commons:commons-lang3:3.5'
compile 'commons-codec:commons-codec:1.9'
compile 'io.springfox:springfox-swagger2:2.6.1'
compile 'io.springfox:springfox-swagger-ui:2.6.1'
compile 'javax.mail:mail:1.4.7'
compile 'org.imgscalr:imgscalr-lib:4.2'
compile 'com.restfb:restfb:1.37.0'
compile 'com.google.apis:google-api-services-oauth2:v2-rev134-1.23.0'
compile 'eu.bitwalker:UserAgentUtils:1.19'
compile 'com.twilio.sdk:twilio:7.17.+'
testCompile('com.h2database:h2')
testCompile("org.springframework.boot:spring-boot-starter-test")
compile fileTree(dir: 'libs', include: '*.jar')
}
【问题讨论】:
-
考虑到 Spring boot 默认使用 logback,而 log4j 1.x 的 Spring boot starter 只能到 1.3.x.RELEASE,我猜你自己包含了这些依赖项。你能发布你的 Gradle 文件吗?
-
已发布 Gradle 文件。
标签: java spring spring-boot log4j