How to configure log4j in a Spring Mvc application configured with Java Annotations and using a log4j.properties file
<p>I'm working on a Maven Web application using <code>Spring MVC 4.2.5.RELEASE</code>, I'm using <code>Netbeans</code> IDE with <code>GlassFishSErver 4.1</code>, I want to use <code>log4j 1.2.17</code> so I created a log4j.properties file but it seems like my properties file it's not being found because I get the following error: </p>

<pre><code>log4j:WARN No appenders could be found for logger (org.springframework.web.servlet.DispatcherServlet).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
</code></pre>

<p>I configured my Spring application using java annotations here is my configuration</p>

<pre><code>@Configuration
@EnableWebMvc
@ComponentScan({"config", "controllers"})
public class ConfigMVC extends WebMvcConfigurerAdapter {

@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
    registry.addResourceHandler("/resources/**").addResourceLocations("/WEB-INF/resources/");
}

@Bean
public UrlBasedViewResolver setupViewResolver() {
    UrlBasedViewResolver resolver = new UrlBasedViewResolver();
    resolver.setPrefix("/WEB-INF/jsp/");
    resolver.setSuffix(".jsp");
    resolver.setViewClass(JstlView.class);
    return resolver;
}
</code></pre>

<p>}</p>

<p>here is my WebInitializer</p>

<pre><code>public class WebInicializar implements WebApplicationInitializer {

    @Override
    public void onStartup(ServletContext servletContext) throws ServletException {
        AnnotationConfigWebApplicationContext ctx = new AnnotationConfigWebApplicationContext();
        ctx.register(ConfigMVC.class);
        ctx.setServletContext(servletContext);
        Dynamic servlet = servletContext.addServlet("dispatcher", new DispatcherServlet(ctx));
        servlet.addMapping("/");
        servlet.setLoadOnStartup(1);
        servlet.setInitParameter("throwExceptionIfNoHandlerFound", "true");
    }
}
</code></pre>

<p>and here is my controller</p>

<pre><code>@Controller
public class HomeController {

    private static final Logger logger = Logger.getLogger(HomeController.class);

    @RequestMapping(value = "/myPage", method = RequestMethod.GET)
    public String paginaSinMap(ModelMap map) {

    logger.info("This is an info log entry");
    logger.error("This is an error log entry");

    return "myPage";
}
</code></pre>

<p>and here it's my <code>log4j.properties</code></p>

<pre><code># LOG4J configuration
log4j.rootLogger=INFO, Appender1, Appender2

log4j.appender.Appender1=org.apache.log4j.ConsoleAppender
log4j.appender.Appender1.layout=org.apache.log4j.PatternLayout
log4j.appender.Appender1.layout.ConversionPattern=%-7p %d [%t] %c %x - %m%n

log4j.appender.Appender2=org.apache.log4j.FileAppender
log4j.appender.Appender2.File=D:/Logs/SpringMVC.log
log4j.appender.Appender2.layout=org.apache.log4j.PatternLayout
log4j.appender.Appender2.layout.ConversionPattern=%-7p %d [%t] %c %x - %m%n
</code></pre>

<p>and I put this log4j.properties in my resources folder, here is my project structure</p>

<p>EDIT: I didn't mention that my project is a maven web application using spring 
and this is my project structure</p>

<pre><code>MyWebAppProjectName
--Web Pages
  --WEB-INF
    --jsp
         index.jsp
    --resources
      --js
         js.js
      --css
         site.css
      log4j.properties
--Source Packages
  --config
      ConfigMVC.java
      WebInitializaer.java
  --controllers
      HomeController.java
--Test Packages
--Other Resources
  --src/main/resources
    --default package
--Dependencies
--Java Dependencies
--Project FIles
</code></pre>

<p>So I put the log4j.properties in the <code>Other Resources/src/main/resources</code> and when I did this Netbeans created a <code>default Package</code> with the file inside like this <code>default package/log4j-properties</code> and it worked the logs starting to appear in the output and everything worked fine as expected. </p>

<p>I tried to create a package named <code>Log4jResource</code> inside this path <code>src/main/resources</code> but when I did this it stopped to work and the error showed again, so it's there a way to put this file in that folder but without having to use <code>default package</code> that NetBeans creates when I put the folder in there.</p>

<p>I tried doing refactor rename the default package but it shows me this error <code>Module JPA Refactoring threw java.lang.NullPointerException. Please report a bug against JPA Refactoring module and attach your var/log/messages.log.</code></p>

<p>My final project structure looks like this</p>

<pre><code>MyWebAppProjectName
--Web Pages
  --WEB-INF
    --jsp
         index.jsp
    --resources
      --js
         js.js
      --css
         site.css
      log4j.properties
--Source Packages
  --config
      ConfigMVC.java
      WebInitializaer.java
  --controllers
      HomeController.java
--Test Packages
--Other Resources
  --src/main/resources
    --default package
      --log4j.properties
--Dependencies
--Java Dependencies
--Project FIles
</code></pre>