0

I am developing a Java desktop application and I am using Spring with it. Now I want to inject log4j to my classes using applicationContext.xml. My log4j properties file is placed in a source folder Resources/log4j.properties

During my search I found out that there are many way to it when its a web application but I found out no help regarding a desktop application.

I am using Apache commons interfaces in my source code and now I want to inject log4j dependency.

Kindly, help me out..

1 Answers1

0

By default, Log4J will simply read its configuration from a "log4j.properties" file in the root of the class path. Since you placed your log4.properties file in the resources source folder, this should work.

If you do not want to store your log4j configuration in your class path then you can use something like this :

<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>myPropertiesFolder/log4j.xml</value>
      </list>
   </property>
</bean>
AxxA Osiris
  • 1,219
  • 17
  • 26