My spring MVC is not working and i am getting error resource not found.
I have heard about debug logging.
Is it something that i can turn on and i can see more detail that where is the problem or
is it something i need to program in every file only that message will be shown which i hard coded in file
Spring uses the Apache Commons Logging API, which in turn uses either internal Java logging, or log4j (if available). See this part of the docs for a fuller explanation.
"debug logging" refers to the fact that Spring does a lot of verbose logging at "debug level", which is normally not recorded. You can reconfigure your logging, however, to show this level of information if required. Again, see the above link.
In your log4j.properties, set the logging level for Spring to DEBUG, something along the lines of
log4j.logger.org.springframework = DEBUG, <Some appender>
From a personal blog post, the required maven dependencies are:
<properties>
...
<spring.version>3.1.2.RELEASE</spring.version>
<slf4j.version>1.7.1</slf4j.version>
<logback.version>0.9.30</logback.version>
</properties>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${spring.version}</version>
<exclusions>
<exclusion>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</exclusion>
</exclusions>
<type>jar</type>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jcl-over-slf4j</artifactId>
<version>${slf4j.version}</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${slf4j.version}</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>${logback.version}</version>
</dependency>
The above enables Logback. Check the corresponding documentation to set the desired logging level.
Related
I'm trying to store data with H2 and hibernate in my Spring project,
and i cant get rid of this:
SEVERE: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
java.lang.AbstractMethodError: ch.qos.logback.classic.Logger.log(Lorg/slf4j/Marker;Ljava/lang/String;ILjava/lang/String;Ljava/lang/Throwable;)V
at org.apache.commons.logging.impl.SLF4JLocationAwareLog.info(SLF4JLocationAwareLog.java:159)
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:187)
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:47)
my pom file:
http://pastebin.com/hxXyZi9b
Whats wrong?
There must be version mismatch between your mentioned slf4j dependencies and slf4j lib used spring-core in pom.xml.
If you are using eclipse, you can easily check(by searching) in Depedency Hierarchy tab in pom.xml.
From Spring references documentation:
A common choice might be to bridge Spring to SLF4J, and then provide explicit binding from SLF4J to
Log4J. You need to supply 4 dependencies (and exclude the existing commons-logging): the bridge,
the SLF4J API, the binding to Log4J, and the Log4J implementation itself. In Maven you would do that
like this
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>4.1.0.BUILD-SNAPSHOT</version>
<exclusions>
<exclusion>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jcl-over-slf4j</artifactId>
<version>1.5.8</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.5.8</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.5.8</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.14</version>
</dependency>
I'm trying to user Apache HTTPClient in my project. Here does not required any logging for this application. So Can I use HTTPClient without Commons-logging.jar. Otherwise it will be a extra unnecessary burden for my distribution package.
Yes you can. As Hannes suggested - here is my own HttpClient maven setup:
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.3.1</version>
<exclusions>
<exclusion>
<artifactId>commons-logging</artifactId>
<groupId>commons-logging</groupId>
</exclusion>
</exclusions>
</dependency>
Next, since common-logging is indeed a runtime dependency, you will need to define the SLF4J bridge for commons-logging:
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jcl-over-slf4j</artifactId>
<version>1.7.5</version>
</dependency>
And finally, you will of course need to have a valid SLF4J configuration - here is mine:
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.5</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.0.11</version>
</dependency>
Hope this helps.
You can use slf4j with the JCL bridge. This will forward JCL logging to slf4j. Than you add a slf4j adapter like log back or log4j and configure it properly.
When using maven, do not forget to exclude the JCL dependency.
http://www.slf4j.org/legacy.html
Below is what I have in my pom.xml, any comments or improvments? (this is for a spring mvc application)
Do I still need to exclude commons logging to use slf4j?
<!-- Spring -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${org.springframework-version}</version>
<exclusions>
<!-- Exclude Commons Logging in favor of SLF4j -->
<exclusion>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${org.springframework-version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
<version>${org.springframework-version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>${org.springframework-version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>${org.springframework-version}</version>
</dependency>
I've had this in a project like this for about 1 year now, and not sure if things have changed or need updating (especially around setting up the logging).
One thing I hate is when using IntelliJ and jetty (that reloads the project every x seconds), is that I get java out of memory (perm gen) errors and I believe it is because of a leak in the logging in the spring framework.
You should exclude commons-logging only when you have jcl-over-slf4j included. See for more info: http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html/overview.html#d0e787
About leaks: as far I understand there is not proper fix -- you could increase memory, but it will crash later. This is one of problems which JRebel may help to reduce.
Some days ago I started using ehcache in web app. All was fine, and I do remember that when ehcache was putting something in the cach, or retrieving existing value from cache - it was written in the log files.
I do not know what was changed since that time, and now ehcache is still working (I checked it attentively, in debug mode too), but without any logging.
What can be the cause of such behaviour?
The list of ehcache & log dependencies in my maven project:
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.6.1</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>1.6.1</version>
</dependency>
<dependency>
<groupId>com.googlecode.ehcache-spring-annotations</groupId>
<artifactId>ehcache-spring-annotations</artifactId>
<version>1.2.0</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<scope>provided</scope>
</dependency>
I can assure that log4j.properties was not changed since that time.
To get put/gets/removes and so on logged, the cache needs to have statistics enabled. You can control this either programmatically or in your ehcache.xml.
I would like to configure logging in my application with log4j.properties and instruct (somehow) all third-party packages/modules to log through this configuration. Now they log differently and it's a mess: OpenEJB, Hibernate, Apache HttpClient, Jersey, etc. How can I do this? I want to work with log4j only.
Use a framework which can redirect all kinds of logging frameworks to log4j: slf4j.
See "Bridging legacy APIs" for an overview.
[Edit] Maven pom.xml for slf4j:
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.6.1</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.6.1</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.16</version>
<!-- The usual exclusions here: javax.mail:mail, oro:oro -->
</dependency>