Adding javax.servlet-api dependency throws exception that org.slf4j.impl.StaticLoggerBinder faild to load but i don't use sl4j, i use thymeleaf - spring

Basicaly title. I'm trying to run simple spring5 + thymeleaf project. If i don't add servlet-api i get an error that
cannot access javax.servlet.ServletException
But if i add servlet-api, project starts and works fine , but i get an error on startup:
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
But i don't use sl4j, i use thymeleaf. How does servlet exception connected with sl4j and how should i manage it?
UPD
I understand that my question is wrong. But i need help with connected problem:
As someone suggested i added
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.5</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.7.5</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
</dependency>
But i still get Failed to load class "org.slf4j.impl.StaticLoggerBinder". exception. Any ideas?
UPD
as someone mentioned here this is a bug of ide

Add slf4j.jar in your dependency or your project. Spring internally use slf4j for its own logging.

I'm using IntelIj idea.
As someone sugested i added log4j and sl4j dependencies becouse servlet-api uses loging by default. And my exception that class is failed to load is just a bug of ide as it was mentioned in another question and everything including logging works fine.

Related

Missing newline character in rawlogs using log4j and slf4j

I am working on a bug using log4j2 and slf4j. I have been reviewing the commit history in Github, but cannot find where the bug was introduced. In the log file rawlogs.log the newline character %n has been replaced by %replace%n. Please see the example below:
applog.line=16,applog.msg=ConfigChangeListener Initilized!%replace%nXXXXXXXX03172 123456789 2019-06-11 15:06:35.080 devHostname
I am using the following dependencies:
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>2.10.0</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.10.0</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-to-slf4j</artifactId>
<version>2.10.0</version>
</dependency>
In the files with logs the LoggerFactory is created with the example below:
private static final Logger LOGGER = LoggerFactory.getLogger(ClassName.class);
I have tried using both a log4j2.properties, and log4j2.xml files from log4j2 examples, but always get this error on startup:
2019-06-11 15:19:16,063 warmup - 7 ERROR No log4j2 configuration file found. Using default configuration: logging only errors to the console.
The rawlogs.log file is created and populated on startup.
Has anyone experienced this before? Any insight is appreciated.
EDIT: To clarify, project did not use a .xml or .properties file for configurations. I introduced them in an attempt to expose the root cause of the bug, but have not had success.

Setting Logger Implementation to Test Scope with Maven for IntelliJ

For automated tests of an API, I need to have an implementation of a logger present. But the logger is supposed to not ship with the API itself. To that end I set up the relevant part of the pom.xml of the API module itself like so:
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.25</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.2.3</version>
<scope>test</scope>
</dependency>
When I manually run maven from the command line the test where the logger is relevant passes. But when I run the test file from within Intellij I get the following error:
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.
I have spent several hours now trying to figure out what is wrong and followed multiple tutorials. None actually covered the sort of setup I need though and so I am still stuck with this error.
Do you know what the actual problem is here and how to set this up correctly?

Cannot load JDBC Driver class in Birt 4.6.0-20160607

i am having a Java EE project in which i include the Birt runtime as a maven dependency:
<dependency>
<groupId>org.eclipse.birt.runtime</groupId>
<artifactId>org.eclipse.birt.runtime</artifactId>
<version>4.6.0-20160607</version>
<exclusions>
<exclusion>
<groupId>org.eclipse.birt.runtime</groupId>
<artifactId>org.apache.xerces</artifactId>
</exclusion>
<exclusion>
<artifactId>org.apache.poi</artifactId>
<groupId>org.eclipse.birt.runtime</groupId>
</exclusion>
</exclusions>
</dependency>
The engine seems to be created (i hope at least) . In my report i have defined the datasource settings.
<data-sources>
<oda-data-source extensionID="org.eclipse.birt.report.data.oda.jdbc" name="somename" id="43">
<list-property name="privateDriverProperties">
<ex-property>
<name>contentBidiFormatStr</name>
<value>ILYNN</value>
</ex-property>
<ex-property>
<name>metadataBidiFormatStr</name>
<value>ILYNN</value>
</ex-property>
</list-property>
<property name="odaDriverClass">oracle.jdbc.driver.OracleDriver</property>
<property name="odaURL">jdbc:oracle:thin:#host...</property>
<property name="odaUser">username</property>
<encrypted-property name="odaPassword" encryptionID="base64">password</encrypted-property>
</oda-data-source>
</data-sources>
Unfortunately it seems that Birt cannot find the ojdbc driver (Note, we use an oracle database) and we get the following error:
SEVERE [org.eclipse.birt.data.engine.odaconsumer] (default task-20)
Unable to open connection.:
org.eclipse.birt.report.data.oda.jdbc.JDBCException: Cannot load JDBC
Driver class: oracle.jdbc.driver.OracleDriver.
I have included in my Web module under WEB-INF/lib the following jar org.eclipse.birt.report.data.oda.jdbc_4.6.0.v201606072122.jar but i am still getting the same error.
Is there any way to solve this by adding the ojdbc as a maven dependency or is there any other workaround ?
Update: I have tried to also to add the also the org.eclipse.birt.report.data.oda.jdbc_4.6.0.v201606072122.jar as a maven dependency.
<!-- Oracle JDBC driver -->
<dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc6</artifactId>
<version>11.2.0.4.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.eclipse.birt</groupId>
<artifactId>ojdbc</artifactId>
<scope>system</scope>
<version>1.0</version>
<systemPath>${basedir}\src\main\resources\lib\org.eclipse.birt.report.data.oda.jdbc_4.6.0.v201606072122.jar</systemPath>
</dependency>
I am getting the same error. Bellow some part of the stacktrace:
2017-01-05 13:07:11,990 SEVERE
[org.eclipse.birt.report.data.oda.jdbc.JDBCDriverManager] (default
task-45) DriverClassLoader failed to load class:
oracle.jdbc.driver.OracleDriver: java.lang.ClassNotFoundException:
oracle.jdbc.driver.OracleDriver
at org.eclipse.birt.core.framework.URLClassLoader.findClass1(URLClassLoader.java:188)
......
......
2017-01-05 13:07:12,020 SEVERE
[org.eclipse.birt.data.engine.odaconsumer] (default task-45) Unable to
open connection.: org.eclipse.birt.report.data.oda.jdbc.JDBCException:
Cannot load JDBC Driver class: oracle.jdbc.driver.OracleDriver.
at org.eclipse.birt.report.data.oda.jdbc.JDBCDriverManager.findDriver(JDBCDriverManager.java:881)
Update 2: I made further changes but still without success. I added the org.eclipse.birt.report.data.oda.jdbc_4.6.0.v201606072122.jar library in all my modules under WEB-INF and MEtA-INF
\src\main\webapp\WEB-INF\lib\org.eclipse.birt.report.data.oda.jdbc_4.6.0.v201606072122.jar
The results are quite the same:
2017-01-05 15:40:49,927 SEVERE
[org.eclipse.birt.report.data.oda.jdbc.JDBCDriverManager] (default
task-19) DriverClassLoader failed to load class:
org.eclipse.birt.report.data.oda.jdbc:
java.lang.ClassNotFoundException:
org.eclipse.birt.report.data.oda.jdbc
I would also like to note here something. For our persistence in the application, we use a datasource on our wildfly in which we use the ojdbc driver as a module in Wildfly 10 .
I am slowly running out of ideas with Birt + ojdbc
Finally solved the problem. I had to install the oda jdbc driver in my local manen repository and add it as a dependency in my ejb module.
<dependency>
<groupId>org.eclipse.birt.ojdbc</groupId>
<artifactId>odajdbc</artifactId>
<version>4.6.0-201606072122</version>
</dependency>
Furthermore, for some reason which i cannot yet explain, Birt required also the ojdbc6 driver in my web module. I honestly cannot understand why, since the entire birt implementation and runtime is in the ejb module.
<dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc6</artifactId>
<version>11.2.0.4.0</version>
</dependency>
That solved the problem and now the reports are getting generated.
I am now facing two new problems which i have to solve.
1) java.lang.OutOfMemoryError: Java heap space : I found in Eclipse bugzilla that this problem can be solved with the ojdbc7 driver. The reports are not generated unless i push my servers -Xmx above 1400mb
2) [org.eclipse.birt.report.data.oda.jdbc.JDBCDriverManager] (default task-20) DriverClassLoader failed to load class: oracle.jdbc.driver.OracleDriver: java.lang.ClassNotFoundException: oracle.jdbc.driver.OracleDriver: For some reason i get this error only one time when i want to generate a report. The report is generated without problems and the exception never appears again.
At least the reports are working now and can continue solving the other issues.

Spring boot and apache spark - container conflict

I am trying to use spring boot 1.1.5 and apache spark 1.0.2 together in project. Look like apache spark uses Jetty container internally and I have configured spring-boot to use Tomcat container. However application startup fails with some securityException at root cause. If I see full stack trace looks like spring boot trying to initialize "jettyEmbeddedServletContainerFactory" which it shouldn't in first place. It probably picks it up from classpath due to jetty presence via spark. If I exclude jetty from spark and run again I don't see same error again but then SparkContext initialization fails due to not finding jetty. How do i tell spring-boot runtime to look for "TomcatEmbeddedServletContainerFactory" instead of jetty one?
I got "java.lang.SecurityException: class "javax.servlet.http.HttpSessionIdListener"'s signer information does not match signer information of other classes in the same package"
To fix this issue I was need to remove all javax.servlet dependencies.
<dependency>
<groupId>org.apache.spark</groupId>
<artifactId>spark-core_2.10</artifactId>
<version>1.3.1</version>
<exclusions>
<exclusion>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
</exclusion>
<exclusion>
<groupId>org.glassfish</groupId>
<artifactId>javax.servlet</artifactId>
</exclusion>
<exclusion>
<groupId>org.eclipse.jetty.orbit</groupId>
<artifactId>javax.servlet</artifactId>
</exclusion>
</exclusions>
</dependency>
#Joakim Erdfelt, Thanks.
I was just waiting to see if someone is familiar with this situation and if it's just a small configuration change. As it turns out it is! #Configuration
#EnableAutoConfiguration(exclude={EmbeddedServletContainerFactory.class})
public class MyConfiguration { }
I defined my own "EmbeddedServletContainerFactory" bean as a "org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContaine‌​rFactory" and it started working as I expected.

Glassfish incremental deployment failes when including Selenium

I have a Java EE project which is meant to run on Glassfish 4.1. I want to use Selenium to collect information from some web pages, i.e. I need to include Selenium in the deployment (not just for tests).
I am using Eclipse IDE and have previously utilized the incremental deployment function in Eclipse to automatically deploy all saved changes to the project. But when I included (with Maven) the dependencies for Selenium incremental deployment stopped working. The project can still be deployed to Glassfish but I have to restart Glassfish between every change. I get the following error in Eclipse:
Exception while loading the app : java.lang.IllegalStateException: ContainerBase.addChild: start: org.apache.catalina.LifecycleException: java.lang.RuntimeException: com.sun.faces.config.ConfigurationException: java.util.concurrent.ExecutionException: com.sun.faces.config.ConfigurationException: Unable to parse document 'bundle://136.0:1/com/sun/faces/jsf-ri-runtime.xml': DTD factory class org.apache.xerces.impl.dv.dtd.DTDDVFactoryImpl does not extend from DTDDVFactory.. Please see server.log for more details.
org.apache.xerces.impl.dv.dtd.DTDDVFactoryImpl is included with Selenium as a transitive dependency (xerces:xercesImpl:2.11.0).
Here are my Maven dependencies:
<dependency>
<groupId>org.jboss.arquillian.selenium</groupId>
<artifactId>selenium-bom</artifactId>
<version>2.44.0</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-htmlunit-driver</artifactId>
</dependency>
I hope there is a solution to this but after reading Jens Schauder's response in Dealing with "Xerces hell" in Java/Maven? I'm afraid there might not be. Anyone?
I currently can't reproduce the issue with a simple project, did you make sure that you don't have any other dependencies which are importing another version of xercesImpl?
You can try to place the xercesImpl-2.11.0.jar and the transitive dependency xml-apis-1.4.01.jar in the lib folder of your Glassfish domain and exclude it from your dependencies like this:
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-htmlunit-driver</artifactId>
<version>2.44.0</version>
<exclusions>
<exclusion>
<artifactId>xercesImpl</artifactId>
<groupId>xerces</groupId>
</exclusion>
</exclusions>
</dependency>
See also:
org.apache.xerces.impl.dv.DVFactoryException: DTD factory class org.apache.xerces.impl.dv.dtd.DTDDVFactoryImpl does not extend from DTDDVFactory
Xerces error: org.apache.xerces.impl.dv.dtd.DTDDVFactoryImpl

Resources