Reputation: 7215
I am using these log4j, slf4j and ch.qos.logback dependencies in my pom.xml of my java project:
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.6.4</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-core</artifactId>
<version>1.1.2</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jcl-over-slf4j</artifactId>
<version>1.6.4</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>log4j-over-slf4j</artifactId>
<version>1.6.4</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jul-to-slf4j</artifactId>
<version>1.6.4</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.14</version>
</dependency>
I recently wanted to use an external servlet library and defined that dependency in pom. The init method of this servlet looks like this:
import org.apache.log4j.Level;
import org.apache.log4j.Logger;
....
public class HealthpageServlet extends HttpServlet{
private static final long serialVersionUID = 1L;
private final Logger logger = Logger.getLogger(HealthpageServlet.class.getName());
protected HealthpageService service;
public static final String VERSION = "Healthpage-Version 0.0.4";
public void init() throws ServletException {
logger.setLevel(Level.INFO);
.....
}
My Weblogic Server shows me this exception from the init method, when i start the server:
java.lang.NoSuchMethodError: org/apache/log4j/Logger.setLevel(Lorg/apache/log4j/Level;)V
When i in eclipse open that HealthpageServlet jar content, it has a log4j-1.2.15 jar inside the WEB-INF/lib folder. But even if i exclude that dependency from pom.xml, i see this exception and my server does not start. What is the problem?
Upvotes: 1
Views: 20943
Reputation: 625
I know it's too late to answer but adding this answer which might help others. In my case, by trying different configuration I concluded that the log4j and slf4j to work successfully we need to find out the version match. The versions mismatch between spring-mvc and above two dependencies will result in the above error. So try to find out the right version match between 3 dependencies. I tried with below dependencies to get work done.
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>4.1.6.RELEASE</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j13</artifactId>
<version>1.0.1</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
Upvotes: 0
Reputation: 7215
Since the log4j Version (1.2.15) of my external jar was incompatible with the slf4j Version (1.6.4) of my parent project (where logger.setLevel() is not available), i had to update my slf4j to version 1.7.7.
Upvotes: 1