title: Glassfish Log4j JNDI: Cannot find appender
body: <p>I am using Glassfish and I created a JNDI custom resource called log4j that has these properties:</p>
  
  <pre><code>Name: log4j.appender.LOG Value: org.apache.log4j.RollingFileAppender
  Name: log4j.appender.LOG.layout Value: org.apache.log4j.PatternLayout
  Name: log4j.rootLogger Value: WARN, LOG
  Name: log4j.appender.LOG.layout.conversionPattern Value: %d{MMM dd, yyyy HH:mm:ss} %p %m%n
  Name: log4j.appender.LOG.File Value: ${com.sun.aas.instanceRoot}/logs/RestWebServices.log
  Name: log4j.appender.LOG.MaxFileSize Value: 10MB
  Name: log4j.appender.LOG.MaxBackupIndex Value: 10
  </code></pre>
  
  <p>The JNDI resource type is java.util.Properties and my spring application context contains these lines to find them:</p>
  
  <pre><code>&lt;jee:jndi-lookup id="log4jJndi" jndi-name="log4j" resource-ref="true" /&gt;
  &lt;jee:jndi-lookup id="configurationsJndi" jndi-name="configurations" resource-ref="true" /&gt;
  
  &lt;bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"&gt;
      &lt;property name="propertiesArray"&gt;
          &lt;list&gt;
              &lt;ref bean="configurationsJndi"/&gt;
              &lt;ref bean="log4jJndi"/&gt;
          &lt;/list&gt;
      &lt;/property&gt;
  &lt;/bean&gt;
  </code></pre>
  
  <p>It works fine for my configurations JNDI resource but log4j gives me this error when starting Glassfish:</p>
  
  <pre><code>SEVERE: log4j:WARN No appenders could be found for logger (org.springframework.web.context.ContextLoader).  
  SEVERE: log4j:WARN Please initialize the log4j system properly.  
  SEVERE: log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
  </code></pre>
  
  <p>When debugging the root logger was not the one I set in the JNDI resource. I tried adding the spring Log4jConfigListener to resolve this but it did not work. The version of Glassfish I am using is 3.1.</p>
  
  <p>Does anyone know why log4j is an issue?</p>
  
  <p>Edit: Now I am try to use JNDI that has the file location to my log4j properties file and my Spring application context gets the value from JNDI. My problem is I keep getting this error all the time with log4j:</p>
  
  <pre><code>Exception while loading the app : java.lang.IllegalStateException:  
  ContainerBase.addChild: start: org.apache.catalina.LifecycleException:
  org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'log4jJndi': Invocation of init method failed; 
  nested exception is javax.naming.CommunicationException: Communication exception for SerialContext[myEnv={java.naming.factory.initial=com.sun.enterprise.naming.impl.SerialInitContextFactory, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl, java.naming.factory.url.pkgs=com.sun.enterprise.naming} [Root exception is java.lang.IllegalAccessException: value cannot be null]|#]
  </code></pre>