Home > Software design >  "java.lang.IllegalStateException: Could not initialize Logback logging from classpath:logback-s
"java.lang.IllegalStateException: Could not initialize Logback logging from classpath:logback-s

Time:12-29

I have added logback-spring.xml into the class path and it was working fine until I added below dependencies for some ISO message conversion.(crimson dependency is hardcoded in the JPOS library, so it cannot be removed)

<project>
<modelVersion>4.0.0</modelVersion>
<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.7.7</version>
    <relativePath/>
</parent>
<groupId>com.test</groupId>
<artifactId>iso-test</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>iso-test</name>
<description>test</description>
<properties>
    <java.version>11</java.version>
</properties>
<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <dependency>
        <groupId>org.modelmapper</groupId>
        <artifactId>modelmapper</artifactId>
        <version>2.4.4</version>
    </dependency>
    <dependency>
        <groupId>org.projectlombok</groupId>
        <artifactId>lombok</artifactId>
        <optional>true</optional>
    </dependency>
    <dependency>
        <groupId>org.jpos</groupId>
        <artifactId>jpos</artifactId>
        <version>2.1.0</version>
    </dependency>
    <dependency>
        <groupId>crimson</groupId>
        <artifactId>crimson</artifactId>
        <version>1.1.3</version>
        <optional>true</optional>
    </dependency>
</dependencies>
<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
    </plugins>
</build>
</project>

Then there is an issue with logback-spring.xml reading with below exceptions.

java.lang.IllegalStateException: Could not initialize Logback logging from classpath:logback-spring.xml'

and

Caused by: org.xml.sax.SAXNotSupportedException: Feature: http://xml.org/sax/features/external-general-entities

Below is where the JPOS packager(GenericValidatingPackager.class) used crimson library.

public void readFile(String filename) throws ISOException {
    XMLReader reader=XMLReaderFactory.createXMLReader(System.getProperty("sax.parser", "org.apache.crimson.parser.XMLReaderImpl"));
...
}

CodePudding user response:

crimson dependency is hardcoded in the JPOS library, so it cannot be removed

This is not correct, referring to JPOS packager(GenericValidatingPackager.class)

XMLReader reader = XMLReaderFactory.createXMLReader(System.getProperty("sax.parser", "org.apache.crimson.parser.XMLReaderImpl"));

This line just tell us that if we do not set the property "sax.parser", we use org.apache.crimson.parser.XMLReaderImpl as fallback.

So what we need:

  1. Remove crimson dependency
  2. set the property "sax.parser", e.g.
System.setProperty("sax.parser", "com.sun.org.apache.xerces.internal.parsers.SAXParser");

CodePudding user response:

Crimson is not required by jPOS if you use a modern JVM (1.8 and up).

It was used in the past, as a fallback if the JVM didn't provide an XMLReader, and org.xml.sax.driver was not configured.

Also, I suggest to use the latest version (see ChangeLog) as there has been a lot of improvements since 2.1.0 back in 2017.

  • Related