log4j2 : Async logger is NOT starting - asynchronous

I have recently upgraded my application to use log4j2. I am trying to make use of its async logger feature. However looks like its not creating one.
As per Log4j Async config, it says,
To make all loggers asynchronous, add the disruptor jar to the classpath and set the system property Log4jContextSelector to org.apache.logging.log4j.core.async.AsyncLoggerContextSelector.
I also set the status="trace" in log4j.xml to see if it configures and instantiate async logger. But looks like it failing.
2017-01-25 01:58:30,799 main TRACE Reregistering context (1/1): 'AsyncContext#18b4aac2' org.apache.logging.log4j.core.async.AsyncLoggerContext#6bf08014
2017-01-25 01:58:30,800 main TRACE Unregistering but no MBeans found matching 'org.apache.logging.log4j2:type=AsyncContext#18b4aac2'
2017-01-25 01:58:30,800 main TRACE Unregistering but no MBeans found matching 'org.apache.logging.log4j2:type=AsyncContext#18b4aac2,component=StatusLogger'
2017-01-25 01:58:30,800 main TRACE Unregistering but no MBeans found matching 'org.apache.logging.log4j2:type=AsyncContext#18b4aac2,component=ContextSelector'
2017-01-25 01:58:30,801 main TRACE Unregistering but no MBeans found matching 'org.apache.logging.log4j2:type=AsyncContext#18b4aac2,component=Loggers,name='
2017-01-25 01:58:30,801 main TRACE Unregistering but no MBeans found matching 'org.apache.logging.log4j2:type=AsyncContext#18b4aac2,component=Appenders,name='
2017-01-25 01:58:30,801 main TRACE Unregistering but no MBeans found matching 'org.apache.logging.log4j2:type=AsyncContext#18b4aac2,component=AsyncAppenders,name='
2017-01-25 01:58:30,801 main TRACE Unregistering but no MBeans found matching 'org.apache.logging.log4j2:type=AsyncContext#18b4aac2,component=AsyncLoggerRingBuffer'
2017-01-25 01:58:30,802 main TRACE Unregistering but no MBeans found matching 'org.apache.logging.log4j2:type=AsyncContext#18b4aac2,component=Loggers,name=,subtype=RingBuffer'
2017-01-25 01:58:30,803 main DEBUG Registering MBean org.apache.logging.log4j2:type=AsyncContext#18b4aac2
2017-01-25 01:58:30,805 main DEBUG Registering MBean org.apache.logging.log4j2:type=AsyncContext#18b4aac2,component=AsyncLoggerRingBuffer
2017-01-25 01:58:30,806 main DEBUG Registering MBean org.apache.logging.log4j2:type=AsyncContext#18b4aac2,component=StatusLogger
2017-01-25 01:58:30,807 main DEBUG Registering MBean org.apache.logging.log4j2:type=AsyncContext#18b4aac2,component=ContextSelector
2017-01-25 01:58:30,816 main TRACE Using default SystemClock for timestamps.
2017-01-25 01:58:30,816 main TRACE Using DummyNanoClock for nanosecond timestamps.
2017-01-25 01:58:30,817 main DEBUG Reconfiguration complete for context[name=AsyncContext#18b4aac2] at URI /etc/opt/sun/im/default/config/log4j2.xml (org.apache.logging.log4j.core.async.AsyncLoggerContext#6bf08014) with optional ClassLoader: null
2017-01-25 01:58:30,817 main DEBUG Shutdown hook enabled. Registering a new one.
2017-01-25 01:58:30,818 main DEBUG LoggerContext[name=AsyncContext#18b4aac2, org.apache.logging.log4j.core.async.AsyncLoggerContext#6bf08014] started OK.
As I don't see anything like "Starting AsyncLogger disruptor".
Then as suggested, I tried using asyncLogger tag, I could see it printing,
2017-01-25 00:27:26,970 main TRACE AsyncLoggerConfigDisruptor creating new disruptor for this configuration.
2017-01-25 00:27:26,971 main TRACE property AsyncLoggerConfig.WaitStrategy=TIMEOUT
2017-01-25 00:27:26,987 main DEBUG Starting AsyncLoggerConfig disruptor for this configuration with ringbufferSize=4096, waitStrategy=TimeoutBlockingWaitStrategy, exceptionHandler=org.apache.logging.log4j.core.async.AsyncLoggerConfigDefaultExceptionHandler#7f284218...
2017-01-25 00:27:26,988 main TRACE AsyncLoggerConfig[xmppd] starting...
But again at later stage it throws exception for class not found,
2017-01-25 00:27:31,658 main ERROR Unable to invoke factory method in class class org.apache.logging.log4j.core.async.AsyncLoggerConfig for element AsyncLogger. java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.apache.logging.log4j.core.config.plugins.util.PluginBuilder.build(PluginBuilder.java:132)
at org.apache.logging.log4j.core.config.AbstractConfiguration.createPluginObject(AbstractConfiguration.java:942)
at org.apache.logging.log4j.core.config.AbstractConfiguration.createConfiguration(AbstractConfiguration.java:882)
at org.apache.logging.log4j.core.config.AbstractConfiguration.createConfiguration(AbstractConfiguration.java:874)
at org.apache.logging.log4j.core.config.AbstractConfiguration.doConfigure(AbstractConfiguration.java:498)
at org.apache.logging.log4j.core.config.AbstractConfiguration.initialize(AbstractConfiguration.java:227)
at org.apache.logging.log4j.core.config.AbstractConfiguration.start(AbstractConfiguration.java:239)
at org.apache.logging.log4j.core.LoggerContext.setConfiguration(LoggerContext.java:530)
at org.apache.logging.log4j.core.LoggerContext.reconfigure(LoggerContext.java:603)
at org.apache.logging.log4j.core.LoggerContext.reconfigure(LoggerContext.java:620)
at org.apache.logging.log4j.core.LoggerContext.start(LoggerContext.java:226)
at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:242)
at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:45)
at org.apache.logging.log4j.LogManager.getContext(LogManager.java:174)
at org.apache.logging.log4j.LogManager.getLogger(LogManager.java:618)
at org.apache.logging.log4j.LogManager.getRootLogger(LogManager.java:652)
Caused by: java.lang.NoClassDefFoundError: com/lmax/disruptor/EventFactory
at org.apache.logging.log4j.core.config.AbstractConfiguration.getAsyncLoggerConfigDelegate(AbstractConfiguration.java:197)
at org.apache.logging.log4j.core.async.AsyncLoggerConfig.(AsyncLoggerConfig.java:81)
at org.apache.logging.log4j.core.async.AsyncLoggerConfig.createLogger(AsyncLoggerConfig.java:188)
... 23 more
Caused by: java.lang.ClassNotFoundException: com.lmax.disruptor.EventFactory
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 26 more
I have verified, the disruptor jar which I included has this class. I am using disruptor-3.3.6.jar.
Also How to verify that the async logger has started ?
Any help would be appreciated.

Add the LMAX Disruptor dependency.To use AsyncLogger, your pom.xml should be like this
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-log4j2</artifactId>
</dependency>
<dependency>
<groupId>com.lmax</groupId>
<artifactId>disruptor</artifactId>
<version>3.3.7</version>
</dependency>
Further reading : Performance of log4j2 compared to log4j1

Having tried all the suggestions, I had to look for another solution.
First, make sure you have a file called log4j2.component.properties in the classpath. ( in the same place you have log4j2 file src/main/resources)
its content is :
Log4jContextSelector=org.apache.logging.log4j.core.async.AsyncLoggerContextSelector
Next, verify you have this dependency ( I was getting this Exception in thread "main" java.lang.NoClassDefFoundError: com/lmax/disruptor/EventTranslatorVararg when I didn't have it)
<dependency>
<groupId>com.lmax</groupId>
<artifactId>disruptor</artifactId>
<version>3.4.1</version>
</dependency>

I need to investigate further but it seems that Log4j2 depends on a class com.lmax.disruptor.EventFactory which is no longer present in the disruptor version you are using. Can you use an older version? 3.3.2 should work.

Add these dependancy in your Pom file:
<!-- Exclude Spring Boot's Default Logging -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- Add Log4j2 Dependency -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-log4j2</artifactId>
</dependency>
<dependency>
<groupId>com.lmax</groupId>
<artifactId>disruptor</artifactId>
<version>3.3.7</version>
</dependency>

Adding this dependency solved the issue for me :
<dependency>
<groupId>com.lmax</groupId>
<artifactId>disruptor</artifactId>
<version>3.3.7</version>
</dependency>

Related

Embedded Kafka test cases are error after adding jsonschema2pojo-core

I have an application that created with Spring boot and Spring kafka libraries. Now I added jsonschema2pojo-core library to my pom file. After adding this jar file my test cases are failing with below error
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'embeddedKafka': Invocation of init method failed; nested exception is java.lang.NoClassDefFoundError: scala/runtime/java8/JFunction0$mcZ$sp
Caused by: java.lang.NoClassDefFoundError: scala/runtime/java8/JFunction0$mcZ$sp
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.1.RELEASE</version>
<relativePath />
</parent>
<dependency>
<groupId>org.springframework.kafka</groupId>
<artifactId>spring-kafka</artifactId>
</dependency>
<!-- Test Dependencies -->
<dependency>
<groupId>org.springframework.kafka</groupId>
<artifactId>spring-kafka-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jsonschema2pojo</groupId>
<artifactId>jsonschema2pojo-core</artifactId>
<version>1.0.2</version>
</dependency>
It's probably similar to this https://docs.spring.io/spring-kafka/docs/2.5.11.RELEASE/reference/html/#jacksonscala-incompatibility
with the library pulling in an incompatible scala library.
Yes, adding
<dependency>
<groupId>org.scala-lang</groupId>
<artifactId>scala-library</artifactId>
<version>2.12.11</version>
</dependency>
fixed it for me; but I can't guarantee that jsonschema2pojo will work with that version.
The scala folks are notorious for breaking API changes in patch releases.

Tomee+Microprofile UnsatisfiedResolutionException

everybody!
Could you give me advice about such an issue.
I have a simple test project in order to test using Microprofile config.
Field of my test class I test:
#Inject
#ConfigProperty(name = "injected.value")
private String injectedValue;
So this is the dependencies section of my pom:
<dependencies>
<!-- https://mvnrepository.com/artifact/org.eclipse.microprofile/microprofile -->
<dependency>
<groupId>org.eclipse.microprofile</groupId>
<artifactId>microprofile</artifactId>
<version>3.3</version>
<type>pom</type>
<scope>provided</scope>
</dependency>
</dependencies>
I build the war and then:
1. when i deploy war into the tomee 8.0.1-microprofile (tomee-maven-plugin with tomeeClassifier set up to microprofile) -> then all works OK.
2. BUT when i deploy war into the tomee 8.0.1-plus (tomee-maven-plugin with tomeeClassifier set up to plus) -> then i got exception:
org.apache.webbeans.exception.WebBeansDeploymentException: javax.enterprise.inject.UnsatisfiedResolutionException: Api type [java.lang.String] is not found with the qualifiers
Qualifiers: [#org.eclipse.microprofile.config.inject.ConfigProperty(name=injected.value, defaultValue=org.eclipse.microprofile.config.configproperty.unconfigureddvalue)]
for injection into Field Injection Point, field name : injectedValue, Bean Owner : ...
More over in case 1 (deploy to tomee 8.0.1-microprofile) when i change pom dependencies to:
<dependencies>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<version>8.0.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.eclipse.microprofile.config</groupId>
<artifactId>microprofile-config-api</artifactId>
<version>1.4</version>
</dependency>
</dependencies>
i got the error:
org.apache.webbeans.exception.WebBeansDeploymentException: javax.enterprise.inject.UnsatisfiedResolutionException: Api type [java.lang.String] is not found with the qualifiers
Qualifiers: [#org.eclipse.microprofile.config.inject.ConfigProperty(name=injected.value, defaultValue=org.eclipse.microprofile.config.configproperty.unconfigureddvalue)]...
Please could anybody help me with this issue?
I need to use Microptofile in the prod and for now, I can't do it.
for the plus and plume version to work, you must include the following property in system.properties:
tomee.mp.scan = all
reference:
http://tomee-openejb.979440.n4.nabble.com/MicroProfile-Integration-in-Plus-and-Plume-td4686818i60.html
another way is using the tomee plugin and adding this property in pom.xml :
<systemVariables>
<tomee.mp.scan>all</tomee.mp.scan>
</systemVariables>

Thymeleaf migration from 2 to 3 getting exception with use of thymeleaf-extras-conditionalcomments

I would like to migrate from Thymeleaf 2.1.3 to 3.0.8. I updated the pom.xml file like you can see below with the newest version of the resoucres. If I try to deploy the war file to Jboss I'm getting an BeanCreationException. The detailed Stacktrace you can find below.
I guess the exception is raised due to missing attributes in the superclass constructor of ConditionalCommentsDialect. ConditionalCommentsDialect is extending org.thymeleaf.dialect.AbstractDialect and the constructor is changed in the Thymeleaf 3 version. It seems that the ConditionalCommentsDialect is not compatible with Thymeleaf 3. So is my assumption right? Any ideas how to solve this? Thanks in advance.
pom.xml
<dependency>
<groupId>org.thymeleaf</groupId>
<artifactId>thymeleaf</artifactId>
<version>3.0.8.RELEASE</version>
</dependency>
<dependency>
<groupId>org.thymeleaf</groupId>
<artifactId>thymeleaf-spring4</artifactId>
<version>3.0.8.RELEASE</version>
</dependency>
<dependency>
<groupId>org.thymeleaf</groupId>
<artifactId>thymeleaf-testing</artifactId>
<version>3.0.3.RELEASE</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.attoparser</groupId>
<artifactId>attoparser</artifactId>
<version>2.0.4.RELEASE</version>
</dependency>
<dependency>
<groupId>org.thymeleaf.extras</groupId>
<artifactId>thymeleaf-extras-conditionalcomments</artifactId>
<version>2.1.2.RELEASE</version>
</dependency>
<dependency>
<groupId>nz.net.ultraq.thymeleaf</groupId>
<artifactId>thymeleaf-layout-dialect</artifactId>
<version>2.2.2</version>
</dependency>
spring configuration file
<util:set id="extraDialects">
<bean class="nz.net.ultraq.thymeleaf.LayoutDialect"/>
<bean class="org.thymeleaf.extras.conditionalcomments.dialect.ConditionalCommentsDialect"/>
</util:set>
<bean id="templateResolver"
class="org.thymeleaf.spring4.templateresolver.SpringResourceTemplateResolver"
p:prefix="classpath:/views/" p:suffix=".html"
p:templateMode="HTML5" p:characterEncoding="UTF-8"/>
<bean id="templateEngine"
class="org.thymeleaf.spring4.SpringTemplateEngine"
p:templateResolver-ref="templateResolver"
p:extraDialects-ref="extraDialects"/>
<bean id="viewResolver"
class="org.thymeleaf.spring4.view.ThymeleafViewResolver"
p:templateEngine-ref="templateEngine"
p:characterEncoding="UTF-8"/>
Exception
Error creating bean with name 'extraDialects': Cannot create inner bean org.thymeleaf.extras.conditionalcomments.dialect.ConditionalCommentsDialect#503d1586' of type [org.thymeleaf.extras.conditionalcomments.dialect.ConditionalCommentsDialect] while setting bean property 'sourceSet' with key [1];
nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.thymeleaf.extras.conditionalcomments.dialect.ConditionalCommentsDialect#503d1586' defined in class path resource [spring-webmvc.xml]: Instantiation of bean failed;
nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.thymeleaf.extras.conditionalcomments.dialect.ConditionalCommentsDialect]: Constructor threw exception;
nested exception is java.lang.NoSuchMethodError: org.thymeleaf.dialect.AbstractDialect: method <init>()V not found
Conditional comments are now provided as part of the Thymeleaf core (since version 3). You can simply remove that dependency.

Spring Boot Tomcat Container Deployment Errors

I would like to deploy my Spring Boot application as a WAR to a Tomcat Container, but Tomcat is unable to start the container. I have followed the documentation, Traditional Deployment Section from the Spring Boot Reference. The container's thread size is set to -Xss 4068, but I'm still getting a stack overflow error.
Here is the stack trace:
Dec 08, 2014 12:01:13 AM org.apache.catalina.loader.WebappClassLoader validateJarFile
INFO: validateJarFile(C:\Tomcat\customer\webapps\customer-site-0.0.1-SNAPSHOT\WEB-
INF\lib\javax.servlet-api-3.0.1.jar) - jar not loaded. See Servlet Spec 3.0, section 10.7.2.
Offending class: javax/servlet/Servlet.class
Dec 08, 2014 12:01:15 AM org.apache.catalina.core.ContainerBase addChildInternal
SEVERE: ContainerBase.addChild: start:
org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[customers-prototype.mydomain.com].StandardContext[/customer-site-0.0.1-SNAPSHOT]]
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:154)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:901)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:877)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:649)
at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:1081)
at org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:1877)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
at java.util.concurrent.FutureTask.run(FutureTask.java:166)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:722)
Caused by: java.lang.IllegalStateException: Unable to complete the scan for annotations for web application [/customer-site-0.0.1-SNAPSHOT] due to a StackOverflowError. Possible root causes include a too low setting for -Xss and illegal cyclic inheritance dependencies. The class hierarchy being processed was [com.ibm.db2.jcc.am.mf->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object]
at org.apache.catalina.startup.ContextConfig.checkHandlesTypes(ContextConfig.java:2126)
at org.apache.catalina.startup.ContextConfig.processAnnotationsStream(ContextConfig.java:2072)
at org.apache.catalina.startup.ContextConfig.processAnnotationsJar(ContextConfig.java:1947)
at org.apache.catalina.startup.ContextConfig.processAnnotationsUrl(ContextConfig.java:1913)
at org.apache.catalina.startup.ContextConfig.processAnnotations(ContextConfig.java:1898)
at org.apache.catalina.startup.ContextConfig.webConfig(ContextConfig.java:1330)
at org.apache.catalina.startup.ContextConfig.configureStart(ContextConfig.java:889)
at org.apache.catalina.startup.ContextConfig.lifecycleEvent(ContextConfig.java:386)
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:117)
at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:90)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5380)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
... 11 more
Dec 08, 2014 12:01:15 AM org.apache.catalina.startup.HostConfig deployWAR
SEVERE: Error deploying web application archive C:\Tomcat\customer\webapps\customer-site-0.0.1-SNAPSHOT.war
java.lang.IllegalStateException: ContainerBase.addChild: start: org.apache.catalina.LifecycleException: Failed to start component
[StandardEngine[Catalina].StandardHost[customers-prototype.mydomain.com].StandardContext[/customer-site-0.0.1-SNAPSHOT]]
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:904)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:877)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:649)
at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:1081)
at org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:1877)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
at java.util.concurrent.FutureTask.run(FutureTask.java:166)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:722)
Dec 08, 2014 12:01:15 AM org.apache.catalina.startup.HostConfig deployWAR
My pom.xml has the following Spring Boot dependency with the spring-boot-starter-tomcat scope set to provided as described in the documentation.
POM.XML
<!-- Spring Boot -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<!-- Spring Security -->
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-web</artifactId>
<version>${spring.security.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-config</artifactId>
<version>${spring.security.version}</version>
</dependency>
UPDATED: Additional pom dependencies:
<dependency>
<groupId>com.ibm.db2</groupId>
<artifactId>db2jcc4</artifactId>
<version>9.7.0.9</version>
</dependency>
<dependency>
<groupId>com.ibm.db2</groupId>
<artifactId>db2jcc_license</artifactId>
<version>9.7.0.9</version>
</dependency>
My main class extends the SpringBootServletInitializer as described in the documents:
CustomerSiteMain.java:
#Configuration
#ComponentScan("com.mydomain")
#EnableAutoConfiguration
public class CustomerMain extends SpringBootServletInitializer{
#Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application){
return application
.showBanner(true)
.parent(Global.class)
.sources(CustomerMain.class)
.profiles("container");
}
public static void main(String[] args) {
SpringApplication.run(CustomerMain.class, args);
}
#Bean
#Profile(CustomerSiteProfiles.STANDALONE)
public ServletRegistrationBean h2Console() {
ServletRegistrationBean reg = new ServletRegistrationBean(new WebServlet(), "/console/*");
reg.setLoadOnStartup(1);
return reg;
}
#Bean
public ServletRegistrationBean servletRegistrationBean(){
return new ServletRegistrationBean(new PhotoSheetPDFServlet(), "/items/factsheet/*");
}
}
The above helped me out as well. I had a similar issue and kept getting WebappClassLoader logs like this:
2015-03-06 20:32:53,741 org.apache.catalina.loader.WebappClassLoader validateJarFile INFO: validateJarFile(/usr/local/apache-tomcat-7.0.54/webapps/gs-producing-web-service-0.1.0/WEB-INF/lib/tomcat-embed-core-8.0.15.jar) - jar not loaded. See Servlet Spec 3.0, section 10.7.2. Offending class: javax/servlet/Servlet.class
2015-03-06 20:32:53,742 org.apache.catalina.loader.WebappClassLoader validateJarFile INFO: validateJarFile(/usr/local/apache-tomcat-7.0.54/webapps/gs-producing-web-service-0.1.0/WEB-INF/lib/tomcat-embed-el-8.0.15.jar) - jar not loaded. See Servlet Spec 3.0, section 10.7.2. Offending class: javax/el/Expression.class
which were a clue to this SEVERE error I got with the web application loading.
2015-03-06 20:32:54,704 org.apache.catalina.startup.HostConfig deployWAR SEVERE: Error deploying web application archive /usr/local/apache-tomcat-7.0.54/webapps/gs-producing-web-service-0.1.0.war
I was developing a web service in my case and these depencies (web service not web) in my pom.xml
<dependencies>
<!-- tag::springws[] -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-ws</artifactId>
</dependency>
<dependency>
<groupId>wsdl4j</groupId>
<artifactId>wsdl4j</artifactId>
</dependency>
<!-- end::springws[] -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
</dependencies>
But I was forgetting to do a clean as well before a maven install. This cost my a few hours because my tomcat libraries were still there.
USER BEWARE that you should also do a maven clean when you follow Springs https://spring.io/guides/gs/convert-jar-to-war/ and http://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#howto-create-a-deployable-war-file
This is great now for more rapid development. Thanks
It seems like your Tomcat is trying to load some classes that have already been loaded.
Try to exclude an embeded tomcat from spring-boot-starter-web dependency
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</exclusion>
</exclusions>
</dependency>

Spring MVC Initialization Causes Log4J Exception

In my webapp, I am using Spring MVC as my controller layer. However, using the tags provided by the MVC context:
<mvn:annotation-driven />
<mvc:resources />
causes a log4j exception:
<Mar 26, 2012 1:49:50 PM EDT> <Warning> <HTTP> <BEA-101162> <User defined listener
org.springframework.web.context.ContextLoaderListener failed:
java.lang.NoClassDefFoundError: org/apache/log4j/spi/ThrowableInformation.
java.lang.NoClassDefFoundError: org/apache/log4j/spi/ThrowableInformation
at org.apache.log4j.spi.LoggingEvent.<init>(LoggingEvent.java:165)
at org.apache.log4j.Category.forcedLog(Category.java:391)
at org.apache.log4j.Category.log(Category.java:856)
at org.slf4j.impl.Log4jLoggerAdapter.log(Log4jLoggerAdapter.java:597)
at org.apache.commons.logging.impl.SLF4JLocationAwareLog.error(SLF4JLocationAwareLog.java:225)
Truncated. see log file for complete stacktrace
(LoggingEvent.java:165)
at org.apache.log4j.Category.forcedLog(Category.java:391)
at org.apache.log4j.Category.log(Category.java:856)
at org.slf4j.impl.Log4jLoggerAdapter.log(Log4jLoggerAdapter.java:597)
at org.apache.commons.logging.impl.SLF4JLocationAwareLog.error(SLF4JLocationAwareLog.java:225)
Truncated. see log file for complete stacktrace
Basic stuff:
log4j-1.2.16.jar is defined in the maven POM and is in the application library.
Since it's a weblogic server, I have the following in the weblogic.xml file to try to prevent conflicts:
<wls:prefer-application-packages>
<wls:package-name>org.apache.log4j.*</wls:package-name>
</wls:prefer-application-packages>
(Update) I manually excluded commons-logging in the maven POM for the application.
(Update) I already had the slf4j jars in my Maven POM (removing the jcl-over-slf4j has no effect):
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jcl-over-slf4j</artifactId>
<version>1.5.8</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.5.8</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.5.8</version>
<scope>runtime</scope>
</dependency>
Basically, I need to exclude the basic css and js directories as web as a single directory under WEB-INF/ that contains some jspf files that I do NOT wish to write a controller for (dropdown menus definitions used by jquery superfish).
Any help?
Add slf4j-log4 connector to the POM:
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>${slf4j-version}</version>
<scope>runtime</scope>
</dependency>

Resources