Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3443908
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T08:50:57+00:00 2026-05-18T08:50:57+00:00

I have a Java web application that uses the SLF4J logging facade. To date,

  • 0

I have a Java web application that uses the SLF4J logging facade. To date, we use the Log4J implementation underneath (though we are considering a switch to Logback). Log4J is currently configured via a log4j.xml configuration file that is placed in the root of our classpath.

In any event, we use JNDI to configure other aspects of our application so I am very familiar with how to set that up and pull a string from JNDI into a Spring configuration file.

However, I am at a loss to figure out how to create a Log4J appender from within a Spring configuration file. Better yet, can one completely configure Log4J via Spring and skip the log4j.xml configuration file altogether? I am hoping I don’t have to do this programmatically.

I found a Spring class called Log4jWebConfigurer but this requires that the WAR run exploded (don’t want that if I can help it) and also that the log file resides within the web-app directory (definitely don’t want that).

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T08:50:58+00:00Added an answer on May 18, 2026 at 8:50 am

    First get the main directory via JNDI:

    <jee:jndi-lookup id="myAppHome" jndi-name="myAppHome" />
    

    Then use that bean in a Spring Expression Language statement in the the following way:

    <bean id="log4jInitialization" class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
        <property name="targetClass" value="org.springframework.util.Log4jConfigurer" />
        <property name="targetMethod" value="initLogging" />
        <property name="arguments">
            <list>
                <value>#{ myAppHome + '/conf/log4j.xml'}</value>
            </list>
        </property>
    </bean>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have a Java web application that uses Spring and Hibernate and has a
I have a Flex/Java web application that uses Maven as a build tool. Currently,
I'm maintaining a Java web application that uses a java.util.Hashtable to cache values. This
I have a web based application that uses userName and password for login. now
I have a Java web application which stores some data in the session. The
I've written a layered web application that consists of a rich-web client (PHP) that
I'm using RabbitMQ and trying to refactor my current native java implementation to using
Sorry about the length of this question. I'm new to Java and I've come
I didn't notice it until today during some testing locally on my pc, that

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.