Skip to main content

By clicking Submit, you agree to the developerWorks terms of use.

The first time you sign into developerWorks, a profile is created for you. Select information in your profile (name, country/region, and company) is displayed to the public and will accompany any content you post. You may update your IBM account at any time.

All information submitted is secure.

  • Close [x]

The first time you sign in to developerWorks, a profile is created for you, so you need to choose a display name. Your display name accompanies the content you post on developerworks.

Please choose a display name between 3-31 characters. Your display name must be unique in the developerWorks community and should not be your email address for privacy reasons.

By clicking Submit, you agree to the developerWorks terms of use.

All information submitted is secure.

  • Close [x]

Develop Spring applications for WebSphere Application Server Community Edition, Part 1: Spring MVC

Develop and deploy a sample application using the Spring MVC framework

Sunil Patil (spatil@atech.com), Software Engineer, Ascendant Technology LLC
Sunil Patil is a software engineer with more than seven years of experience. His interests include Spring, Struts, and various object relational mapping frameworks, such as Hibernate and iBatis.

Summary:  If you're at all active in the Java™ community, or even if you just read Java-related online magazines or blog sites, you've probably heard of the Spring Framework, which has gained a lot of attention in the past few years. Now's your chance to try it out! This multipart tutorial series shows you how to develop Spring applications that you can use with IBM® WebSphere® Application Server Community Edition, a free, lightweight Java 2 Platform, Enterprise Edition (J2EE) application server. This installment introduces you to various database connection management options available to you while developing Spring applications. Learn about Spring's own implementation of DataSource, how to use an open source connection pool implementation, and how to use connection pools maintained by WebSphere Application Server Community Edition from your Spring application. Also, find out how Spring makes it easy for you to switch from one connection pool implementation to another without making any changes in your Java code.

View more content in this series

Date:  28 Feb 2007
Level:  Intermediate PDF:  A4 and Letter (161 KB | 21 pages)Get Adobe® Reader®

Activity:  27060 views
Comments:  

Considerations

Problem in using Jakarta Commons Logging

If you've added commons-logging.jar in the WEB-INF/lib folder of the contact management application to get rid of a compilation error, you'll get the errors shown in Listing 12 when you try to deploy the application.

An issue WebSphere Application Server Community Edition has with regard to Commons Logging is that you won't be able to use your custom commons-logging configuration in your Web application that you deploy into WebSphere Application Server Community Edition. This is not to say that you can't use the Commons Logging library in your application -- you can. However, you can't configure the logging fashion particular to your own specific application. That means that you can't have commons-logging.jar in your WEB-INF/lib; instead, you should use commons-logging.jar in your WASCE/lib folder. Also, you should change WASCE/var/log/server-logging.properties for specifying logging properties of your application. Note that you're using the Commons Logging API in your contact management application.


Listing 12. Stack trace if you include commons-logging.jar in WEB-INF/lib folder
                    

15:43:24,319 ERROR [[/contact]] Exception sending context 
initialized event to listener instance of class 
org.springframework.web.context.ContextLoaderListener
org.apache.commons.logging.LogConfigurationException: 
org.apache.commons.logging.LogConfigurationException: 
org.apache.commons.logging.LogConfigurationException: 
Invalid class loader hierarchy.  You have more than one 
version of 'org.apache.commons.logging.Log' visible, 
which is not allowed. 
(Caused by org.apache.commons.logging.LogConfigurationException: 
Invalid class loader hierarchy.  
You have more than one version of 'org.apache.commons.logging.Log' 
visible, which is not allowed.) 

(Caused by org.apache.commons.logging.LogConfigurationException:
org.apache.commons.logging.LogConfigurationException: 
Invalid class loader hierarchy.  You have more than one 
version of 'org.apache.commons.logging.Log' visible, 
which is not allowed. 
(Caused by org.apache.commons.logging.LogConfigurationException: 
Invalid class loader hierarchy.  You have more than one 
version of 'org.apache.commons.logging.Log' visible, 
which is not allowed.))
at org.apache.commons.logging.impl.LogFactoryImpl.newInstance
(LogFactoryImpl.java:543)
at org.apache.commons.logging.impl.LogFactoryImpl.getInstance
(LogFactoryImpl.java:235)

Generate trace information

Follow these steps to configure WebSphere Application Server Community Edition to generate trace information for Spring and your contact management application:

  • Remove commons-loggin.jar and log4j.jar from ContactMang application's WEB-INF/lib folder. In the sample application, these two .jar files are included in the lib folder with a compile-time dependency on them. When you use the build.xml file to build the ContactMang application, the resultant .war file won't have these two .jar files in the WEB-INF/lib folder.
  • Deploy the ContactMang.war file on the server.
  • Open the C:\util\WASCE\var\log\server-log4j.properties file, and include the two lines shown in Listing 13 in it.

    Listing 13. Stack trace if you include commons-logging.jar in WEB-INF/lib folder
                                
    log4j.category.org.springframework=DEBUG
    log4j.category.com.sample=TRACE

    Note that server-log4j.properties also contains logging configuration information for the server itself, so if you want to know what's going on inside the server, change the logging level for root logger to DEBUG, and restart the server. When the server is restarted, open the WASCE/var/log/server.log file to take a look at the log generated by WebSphere Application Server Community Edition, Spring, and the ContactMang application.

Note: You're likely to face a similar problem if you try to include cglib.jar in the WEB-INF/lib folder of your Web application.

4 of 8 | Previous | Next

Comments



static.content.url=http://www.ibm.com/developerworks/js/artrating/
SITE_ID=1
Zone=WebSphere, Open source
ArticleID=199111
TutorialTitle=Develop Spring applications for WebSphere Application Server Community Edition, Part 1: Spring MVC
publish-date=02282007
author1-email=spatil@atech.com
author1-email-cc=pppsunil@gmail.com