• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

How to configure log4j in a Spring Mvc application configured with Java Annotations and using a log4

 
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm working on a `Spring MVC 4.2.5.RELEASE` web application, I'm using `Netbeans` IDE with `GlassFishSErver 4.1`, I want to use `log4j 1.2.17` 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:



I configured my Spring application using java annotations here is my configuration



here is my WebInitializer



and here is my controller


and here it's my `log4j.properties`



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

 
Saloon Keeper
Posts: 28713
211
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Log4j properties are expected to be located in the application classpath. For web applications, that would be /WEB-INF/classes/log4j.properties or /WEB-INF/classes/log4j.xml

Any other log4 configuration would have to be done in application logic.
 
Jhon Parker
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Tim Holloway wrote:Log4j properties are expected to be located in the application classpath. For web applications, that would be /WEB-INF/classes/log4j.properties or /WEB-INF/classes/log4j.xml

Any other log4 configuration would have to be done in application logic.



but I don't have those folders do I need to create that classes folder inside my WEB inf??

Also I forgot to mention that it's a maven web aplication this is my project structure

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


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

I tried to create a package named Log4jResource inside this path src/main/resources 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 default package that NetBeans creates when I put the folder in there.

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

It would be better if I create that classes folder inside my WEB-INF??
 
Tim Holloway
Saloon Keeper
Posts: 28713
211
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Forget about NetBeans. If maven can create it, then NetBeans should be able to create it.

To ensure that the WEB-INF/classes/log4j.properties file build into its proper home in the target WAR, create a directory /src/main/resources/WEB-INF/classes in your Maven project directory and put the source log4j.property file there. Maven will automatically copy it.
reply
    Bookmark Topic Watch Topic
  • New Topic