GridPulse

as stimulating as black coffee and just as hard to sleep after.

Some tips on porting Spring web applications to OC4J

2 comments

As OC4J has some drawbacks, here are some tips on porting Spring Framework 2+ web applications.

1. Forget about XML Schema, use DTD’s

As I was about to touch the first base, after throwing my exploded WAR in j2ee applications, OC4J started complaining about XML issues. This is what I mean:


javax.xml.parsers.ParserConfigurationException: Unable to validate using XSD: Your JAXP provider [oracle.xml.jaxp.JXDocumentBuilderFactory@1571dff] does not support XML Schema. Are you running on Java 1.4 or below with Apache Crimson? Upgrade to Apache Xerces (or Java 1.5) for full XSD support.

Yea, …nasty. As you don’t want to place Xerces and Xalan in your JRE/JDK lib, all you must do is strip the XML Schema related information and use Spring DTD’s.

2. Use ContextLoaderServlet, bootstrap listeners are for smart containers!

Oracle IAS Logo

Don’t use ContextLoaderListener. It won’t work, as OC4J is Servlet 2.3 compliant and does not enforce loading of Listeners before load-on-startup Servlets. So, to escape the bean not found hell, use ContextLoaderServlet.


<servlet>
<servlet-name>context</servlet-name>
<servlet-class>
org.springframework.web.context.ContextLoaderServlet
</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>

Read more about it in the Spring Framework ContextLoaderServlet javadoc.

3. Specify UTF-8 encoding

No encoding filters needed, as oposed to the Tomcat crowd. All you need to do is edit global-web-application.xml and make sure that you specify default-charset. Read more about it in the web module configuration files documentation at Oracle.

Example:

<orion-web-app
jsp-cache-directory="./persistence"
servlet-webdir="/servlet"
development="false" jsp-timeout="0"
default-charset="UTF-8" >

Written by Bogdan

June 17th, 2008 at 7:51 pm

Posted in Development,Java

2 Responses to 'Some tips on porting Spring web applications to OC4J'

Subscribe to comments with RSS or TrackBack to 'Some tips on porting Spring web applications to OC4J'.

  1. Hi sir:
    i meet this question:Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
    org.springframework.beans.factory.BeanDefinitionStoreException: Parser configuration exception parsing XML from ServletContext resource [/WEB-INF/applicationContext.xml]; nested exception is javax.xml.parsers.ParserConfigurationException: Unable to validate using XSD: Your JAXP provider [org.apache.crimson.jaxp.DocumentBuilderFactoryImpl@12940b3] does not support XML Schema. Are you running on Java 1.4 or below with Apache Crimson? Upgrade to Apache Xerces (or Java 1.5) for full XSD support.
    Caused by: javax.xml.parsers.ParserConfigurationException: Unable to validate using XSD: Your JAXP provider [org.apache.crimson.jaxp.DocumentBuilderFactoryImpl@12940b3] does not support XML Schema. Are you running on Java 1.4 or below with Apache Crimson? Upgrade to Apache Xerces (or Java 1.5) for full XSD support.
    at org.springframework.beans.factory.xml.DefaultDocumentLoader.createDocumentBuilderFactory(DefaultDocumentLoader.java:101)
    at org.springframework.beans.factory.xml.DefaultDocumentLoader.loadDocument(DefaultDocumentLoader.java:70)
    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:361)
    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:313)
    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:290)
    at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:131)
    at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:147)
    at org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.java:124)
    at org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.java:92)
    at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:101)
    at org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:389)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:324)
    at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:245)
    at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:188)
    at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:49)
    at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3843)
    at org.apache.catalina.core.StandardContext.start(StandardContext.java:4350)
    at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:791)
    at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:771)
    at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:525)
    at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:924)
    at org.apache.catalina.startup.HostConfig.deployDirectories(HostConfig.java:887)
    at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:492)
    at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1147)
    at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:311)
    at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:117)
    at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1053)
    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:578)
    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)
    please replay my e_mail:ycwabc123@163.com thanks

    yangyang

    26 Mar 09 at 1:04 pm

  2. Great Notes. This solution Saved me big time.

    context

    org.springframework.web.context.ContextLoaderServlet

    1

    Vikas

    16 Jun 10 at 3:32 pm

Leave a Reply