I'm interested in using Log4j2's JPAAppender for logging. See https://logging.apache.org/log4j/2.x/manual/appenders.html#JPAAppender In the docs it states that this should be configured in an own persistenceunit besides the main one you're using etc, and thats all fine. However, As my Main persistenceunit is not configured in the persistence.xml (besides the name of it of course) but in my Spring-context, I would like to do the same for JPAAppender, and only have minimal configuration in the persistence.xml.
Something like:
<persistence xmlns="http://xmlns.jcp.org/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence
http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd"
version="2.1">
<persistence-unit name="MainPU"/>
<persistence-unit name="loggingPU" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
<class>com.LogEvent</class>
<shared-cache-mode>NONE</shared-cache-mode>
</persistence-unit>
However, the log4j2 LoggingContext refereing to the JPAAppender is loaded before my Springcontext, and so any initialization (forcing me to declare db-properties like database url etc in the persistence.xml for JPAAppender.) will be to late. How can I to solve this?