Deprecated Garbage Collections – Kenny Lee Chee Wei

A truckload of garbage by Kenny Lee Chee Wei

Archive for the ‘Spring Framework’ Category

Debuging java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderListener in Eclipse, tomcat, maven

with 9 comments

If you’re developing a spring-enabled web application using the combination of Eclipse, Tomcat and Maven. You might encounter the following error when you try to start tomcat within eclipse.

Error configuring application listener of class org.springframework.web.context.ContextLoaderListener
java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderListener
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1358)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1204)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3773)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4337)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
at org.apache.catalina.core.StandardHost.start(StandardHost.java:719)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443)
at org.apache.catalina.core.StandardService.start(StandardService.java:516)
at org.apache.catalina.core.StandardServer.start(StandardServer.java:710)
at org.apache.catalina.startup.Catalina.start(Catalina.java:566)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:288)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:413)

You’ll need to configure your eclipse project settings by:

  1. Right click on the project in eclipse on the left panel under the package explorer view.
  2. Click Java EE Module Dependencies.
  3. Check (make sure the checkbox is ticked) the Maven Dependencies option (the last option).

Written by kennii

January 28, 2010 at 2:41 am

Posted in Spring Framework

Spring Hibernate DAO Implementation with interface

leave a comment »

Intro

Assuming we have a module called Account Management in our project called foo,

We might can make use of the following package structure.

  1. foo.service.AccountManagement
  2. foo.service.AccountManagementImpl
  3. foo.dao.AccountDAO
  4. foo.dao.hibernate.AccountDAOImpl (In this case hibernate)
  5. foo.model.Account

Sample Spring-Hibernate Hierarchy UML

Spring Wiring

<bean id="accountDAO" class="rb.dao.hibernate.AccountDAOImpl"></bean>

<bean id="accountManagement" class="foo.service.AccountManagementImpl">
<property name="accountDAO">
<ref bean="accountDAO"/>
</property>
</bean>

So note that you can replace the accountDAO with some other implementation class, probably using pure JDBC or ibatis.

Summary

As the experts say, always code to interfaces to cater for different implementations.

Written by kennii

August 7, 2007 at 9:52 am

Posted in Java, Spring Framework

Javascript support in Spring Velocity Macros

with 4 comments

I’m using Velocity templates as the “view” for a new Spring MVC project.

Velocity Spring macros are available which can be used to bind object attributes to the html form elements.

While reading Chapter 14 from Spring MVC documentation, i noticed the VTL definition for a html select element looks like #springFormSingleSelect( $path $options $attributes).

We can pass javascript behaviour into the $attribute parameter like,

#springFormSingleSelect( "new_match.competition" $competitions "onchange=updateTeams()")

which produces,

<select id="competition" name="competition" onchange=updateTeams()> <option value="1">English Premier League</option>

<option value="2">Spanish Primera Liga</option>

<option value="3">Italian Serie A</option>

</select>

Written by kennii

July 17, 2007 at 4:35 am

Posted in Spring Framework