Handling Exceptions in Spring MVC with Logging

In your Spring servlet.xml, add a HandlerExceptionResolver.

	<bean id="exceptionResolver" class="org.springframework.web.servlet.handler.SimpleMappingExceptionResolver">
		<property name="exceptionMappings">
				<prop key="java.lang.Exception">/error/default</prop>
		<property name="defaultErrorView" value="/error/default" />
		<property name="warnLogCategory" value="org.springframework.web.servlet.handler.SimpleMappingExceptionResolver" />

“/error/default” is the URL it will go to that will display an error message to the user. warnLogCategory is the logger category. Exceptions will be logged under the warning level and not the error level. The category value can be anything. Here we just set it to the full name of SimpleMappingExceptionResolver.

Spring HandlerExceptionResolver won’t handle errors in the view, so capture these using web.xml


Apache 2 Performance Tuning

Here’s a list of performance tips taken from the official Apache Performance Tuning documentation. This is meant to serve as a quick cheat sheet. For the details, the trade-offs, the why and when to use these optimizations, please read the complete documentation. All these are for tuning your Apache server for every last ounce of performance, and a few are not applicable to many real world Apache installations.

  • Configure MaxClients to prevent swapping. Use top to determine the size of the average Apache process, and divide it by the total available memory. Make sure to leave room for other processes.
  • Use HostnameLookups off.
  • Use IP addresses instead of Allow from domain or Deny from domain.
  • Set FollowSymLinks. Do not set SymLinksIfOwnerMatch.
  • Use AllowOverride None.
  • Do not use wildcards in DirectoryIndex.
  • Creating a type-map file provides better performance than using MultiViews.
  • Remove unused modules. Minimum modules are mod_mime, mod_dir, and mod_log_config.
  • Compile the appropriate MPM.
  • Use –enable-nonportable-atomics during compilation.
  • Set ExtendedStatus off.
  • Disable dynamically loaded modules during compilcation using -DDYNAMIC_MODULE_LIMIT=0.

It’s now unnecessary to configure the MinSpareServers, MaxSpareServers and StartServers settings.