0

EDIT I can't upgrade tomcat now so the related answer isn't relevant here

We are using 8.5.50 and encounter bug which produce logs as:

2021-06-06 12:37:50,482 DEBUG [background-preinit] messageinterpolation.ResourceBundleMessageInterpolator (ResourceBundleMessageInterpolator.java:220) - Failed to load expression factory via classloader ParallelWebappClassLoader
  context: ROOT
  delegate: false
----------> Parent Classloader:
java.net.URLClassLoader@76f856a8

javax.el.ELException: Unable to find ExpressionFactory of type [# Licensed to the Apache Software Foundation (ASF) under one or more]
        at javax.el.ExpressionFactory.newInstance(ExpressionFactory.java:154) ~[el-api.jar:3.0.FR]
        at javax.el.ExpressionFactory.newInstance(ExpressionFactory.java:93) ~[el-api.jar:3.0.FR]
        at org.hibernate.validator.messageinterpolation.ResourceBundleMessageInterpolator.canLoadExpressionFactory(ResourceBundleMessageInterpolator.java:216) [hibernate-validator-6.2.0.Final.jar:6.2.0.Final]
        at org.hibernate.validator.messageinterpolation.ResourceBundleMessageInterpolator.buildExpressionFactory(ResourceBundleMessageInterpolator.java:170) [hibernate-validator-6.2.0.Final.jar:6.2.0.Final]
        at org.hibernate.validator.messageinterpolation.ResourceBundleMessageInterpolator.<init>(ResourceBundleMessageInterpolator.java:94) [hibernate-validator-6.2.0.Final.jar:6.2.0.Final]
        at org.hibernate.validator.internal.engine.AbstractConfigurationImpl.getDefaultMessageInterpolator(AbstractConfigurationImpl.java:573) [hibernate-validator-6.2.0.Final.jar:6.2.0.Final]
        at org.hibernate.validator.internal.engine.AbstractConfigurationImpl.getDefaultMessageInterpolatorConfiguredWithClassLoader(AbstractConfigurationImpl.java:822) [hibernate-validator-6.2.0.Final.jar:6.2.0.Final]
        at org.hibernate.validator.internal.engine.AbstractConfigurationImpl.getMessageInterpolator(AbstractConfigurationImpl.java:483) [hibernate-validator-6.2.0.Final.jar:6.2.0.Final]
        at org.hibernate.validator.internal.engine.ValidatorFactoryImpl.<init>(ValidatorFactoryImpl.java:153) [hibernate-validator-6.2.0.Final.jar:6.2.0.Final]
        at org.hibernate.validator.HibernateValidator.buildValidatorFactory(HibernateValidator.java:38) [hibernate-validator-6.2.0.Final.jar:6.2.0.Final]
        at org.hibernate.validator.internal.engine.AbstractConfigurationImpl.buildValidatorFactory(AbstractConfigurationImpl.java:451) [hibernate-validator-6.2.0.Final.jar:6.2.0.Final]
        at org.springframework.boot.autoconfigure.BackgroundPreinitializer$ValidationInitializer.run(BackgroundPreinitializer.java:149) [spring-boot-autoconfigure-2.5.0.jar:2.5.0]
        at org.springframework.boot.autoconfigure.BackgroundPreinitializer$1.runSafely(BackgroundPreinitializer.java:111) [spring-boot-autoconfigure-2.5.0.jar:2.5.0]
        at org.springframework.boot.autoconfigure.BackgroundPreinitializer$1.run(BackgroundPreinitializer.java:102) [spring-boot-autoconfigure-2.5.0.jar:2.5.0]
        at java.lang.Thread.run(Thread.java:748) [?:1.8.0_151]
Caused by: java.lang.ClassNotFoundException: # Licensed to the Apache Software Foundation (ASF) under one or more
        at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1358) ~[catalina.jar:8.5.50]
        at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1180) ~[catalina.jar:8.5.50]
        at javax.el.ExpressionFactory.newInstance(ExpressionFactory.java:147) ~[el-api.jar:3.0.FR]
        ... 14 more

I failed to remove the logs using application's log4j and also using tomcat/conf/logging.properties

messageinterpolation.ResourceBundleMessageInterpolator.level = INFO
org.hibernate.validator.messageinterpolation.ResourceBundleMessageInterpolator.level = INFO

How can such logs be removed?

Relevant dependencies:

    <apache.commons.logging-version>1.1.3</apache.commons.logging-version>
    <apache.httpcomponents-version>4.5.2</apache.httpcomponents-version>
    <apache.log4j-new-version>2.0.2</apache.log4j-new-version>
    <apache.log4j-old-version>1.2.17</apache.log4j-old-version>
    
    <org.slf4j-version>1.7.21</org.slf4j-version>
    <hibernate-version>5.5.0.Final</hibernate-version>
    
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-entitymanager</artifactId>
        <version>${hibernate-version}</version>
    </dependency>

    <dependency>
        <groupId>org.apache.logging.log4j</groupId>
        <artifactId>log4j-core</artifactId>
        <version>${apache.log4j-new-version}</version>
    </dependency>
    <dependency>
        <groupId>log4j</groupId>
        <artifactId>log4j</artifactId>
        <version>${apache.log4j-old-version}</version>
        <exclusions>
            <exclusion>
                <groupId>com.sun.jmx</groupId>
                <artifactId>jmxri</artifactId>
            </exclusion>
            <exclusion>
                <groupId>com.sun.jdmk</groupId>
                <artifactId>jmxtools</artifactId>
            </exclusion>
            <exclusion>
                <groupId>javax.jms</groupId>
                <artifactId>jms</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>log4j</groupId>
        <artifactId>apache-log4j-extras</artifactId>
        <version>${apache.log4j-old-version}</version>
    </dependency>
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-simple</artifactId>
        <version>${org.slf4j-version}</version>
    </dependency>
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>jcl-over-slf4j</artifactId>
        <version>${org.slf4j-version}</version>
    </dependency>
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>jul-to-slf4j</artifactId>
        <version>${org.slf4j-version}</version>
    </dependency>
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>log4j-over-slf4j</artifactId>
        <version>${org.slf4j-version}</version>
    </dependency>
    
    <dependency>
        <groupId>commons-logging</groupId>
        <artifactId>commons-logging</artifactId>
        <version>${apache.commons.logging-version}</version>
    </dependency>
Ori Marko
  • 56,308
  • 23
  • 131
  • 233
  • Does this answer your question? [Spring migration 4.3 to 5 on tomcat 8.5 el-api error](https://stackoverflow.com/questions/67857751/spring-migration-4-3-to-5-on-tomcat-8-5-el-api-error) – Piotr P. Karwasz Jun 27 '21 at 10:54
  • @PiotrP.Karwasz no, I can't upgrade tomcat now, I want to stop seeing the errors in log – Ori Marko Jun 27 '21 at 10:56
  • you should upgrade, since the version you are using has [multiple vulnerabilities](https://tomcat.apache.org/security-8.html). – Piotr P. Karwasz Jun 27 '21 at 12:16
  • @PiotrP.Karwasz yes, but we upgrading other components and tomcat won't be upgraded soon – Ori Marko Jun 27 '21 at 12:17
  • Can you provide your dependencies? Hibernate uses [JBoss logging](https://docs.jboss.org/hibernate/orm/4.3/topical/html/logging/Logging.html), which chooses the logging framework according to the classpath (like JCL). BTW: the properties in your question lack the final `.level`. – Piotr P. Karwasz Jun 27 '21 at 20:24
  • @PiotrP.Karwasz Thank you, Not working also with `.level` and added my log related pom – Ori Marko Jun 28 '21 at 05:06
  • Can you add your Log4j 2 configuration (`log4j2.xml` or equivalent)? – Piotr P. Karwasz Jun 28 '21 at 06:16
  • @PiotrP.Karwasz adding logger in log4j2 helped, you can add an answer and I'll accept it – Ori Marko Jun 28 '21 at 10:54

1 Answers1

1

Hibernate 4.x and higher uses JBoss Logging as logging interface (cf. documentation). In order to ignore those messages, you need to identify which logging system is generating them.

With your dependencies all Hibernate messages should go to Log4j 2. Setting:

<Logger name="org.hibernate.validator.messageinterpolation" level="INFO" />

should disable the messages.

Remark: Your Log4j 1.x logging system is misconfigured: you have both log4j and log4j-over-slf4j (a replacement for Log4j 1.x, which sends everything to SLF4j) among your dependencies. Which one of the two implementation will be chosen is random.

Piotr P. Karwasz
  • 12,857
  • 3
  • 20
  • 43