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 580377
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T14:27:59+00:00 2026-05-13T14:27:59+00:00

I am trying to use Log4j as part of the Spring Framework, as far

  • 0

I am trying to use Log4j as part of the Spring Framework,
as far as i understand through the use of a an appropriate bean
the system is supposed to map a singleton instance accessible in the code
while mapping the logging depth automatically to the class

Similar to the normal use of Log4J as in

Logger log = Logger.getLogger(getClass());

i have been using the following Spring bean definition

<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>conf\log4j.xml</value>
        </list>
    </property>
</bean>

But i am unable to map this bean to a specific member in a given class
nor am i able to use it through @autowired

Please let me know if there are any better ways to integrate Log4j and Spring

Best Regards

Mark

  • 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-13T14:27:59+00:00Added an answer on May 13, 2026 at 2:27 pm

    The short answer to your question is that log4j is not DI friendly.

    The Log4jConfigurer.initLogging() method has a void return value, so there’s nothing to inject. The idea is that you call that method, which bootstraps log4j, and then you use the Log4j API as usual (using Logger.getLogger(getClass())).

    You generally wouldn’t configure Log4jConfigurer as a Spring bean, though, but more usually you’d invoke it directly from your own code during application startup.

    If this is a webapp, then Spring provides alternatives to Log4jConfigurer that are better suited to that environment (Log4jWebConfigurer, Log4jConfigListener).

    Incidentally, 2 years ago I filed a feature request to allow loggers to be autowired, and it’s finally been marked as fix for Spring 3.1. Horray.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to use log4j my log4j.propreties: log4j.rootLogger=DEBUG, out log4j.logger.org.springframework=INFO log4j.logger.org.apache.activemq=INFO log4j.logger.org.apache.activemq.spring=WARN log4j.logger.org.apache.servicemix=DEBUG, stdout
I was trying use a set of filter functions to run the appropriate routine,
Why amd I getting warnings from Log4J 1.2.17? I am trying to use log4j
Hy ppl, I'm having a problem trying to use Log4J's NTEventLogAppender. I've set my
i'm trying to convert my log4j.properties into log4j.xml because i need to use some
I am trying to produce a proof of concept shipping logging from Log4J through
Trying to use log4j's built-in JMSAppender to log messages to a local message queue
I am trying to use SLF4J-Log4j for the first time. In every Java class,
I'm trying to use log4j to handle the logs for a web-service which is
I'm currently trying to configure log4j to use 2 appenders. Debug info should be

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.