I am using log4j2 and slf4j in my project & using maven for the build. I am using the following pom file (releveant dependencies shown only) but I am getting the error
I think your first pom.xml is correct, (dependency is correct), maybe config file location is wrong
pom.xml
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.25</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>2.7</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.7</version>
</dependency>
Your log4j2 configuration in correct (POM side), but you never say to slf4j where it should write (backend part).
Your should add that to your pom file
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j-impl</artifactId>
<version>2.0.1</version>
</dependency>
It is the Log4j 2 SLF4J Binding. According to Log4j 2 SLF4J Binding documentation The Log4j 2 SLF4J Binding allows applications coded to the SLF4J API to use Log4j 2 as the implementation
If it still does not work, you may have an Eclipse problem because Eclipse m2e is known to be weird regarding slf4j. According to this detailed post from SO SLF4J: Failed to load class “org.slf4j.impl.StaticLoggerBinder”. error a workaround could be to use an external maven to do the build.
Apart from the log4j-slf4j-impl dependency, you also need the slf4j-ext dependency.
See http://logging.apache.org/log4j/2.x/log4j-slf4j-impl/dependencies.html
You seem to be missing the following from your pom file.
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j-impl</artifactId>
<version>2.0.1</version>
</dependency>