Apache MyFaces
UI-Component Sets
MyFaces Orchestra
Project Documentation
Foundation

Installation

The following configuration provides a blueprint for a single Tomcat installation using Spring 2.0, jpa ri and runtime weaving.

Prerequisites

  • Prerequisites - Knowledge: Basic Spring 2.0 configuration knowledge, knowledge about the jpa ri, to the level that knowing what runtime weaving is can be assumed.
  • Prerequisites - JDK Versions: JDK 5+ (on non Sun JDKs a working runtime weaving on 5 or a 6+ non Sun JDK)
  • Tomcat: 5.5+
  • Spring 2.x+

Spring configuration

The following configuration uses runtime weaving, and a connection pool. It should work on most Tomcat configurations.
  <?xml version="1.0" encoding="UTF-8"?>
  <beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:tx="http://www.springframework.org/schema/tx"
    xmlns:aop="http://www.springframework.org/schema/aop"
    xmlns:sa="https://spring-annotation.dev.java.net/context"

    xsi:schemaLocation="
    http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
    http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd
    http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd"
  >

    <tx:annotation-driven transaction-manager="transactionManager" />
    <bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor"/>
  
    <bean class="org.springframework.beans.factory.config.CustomScopeConfigurer">
      <property name="scopes">
        <map>
          <entry key="conversation.access">
            <bean class="org.apache.myfaces.orchestra.conversation.spring.SpringConversationScope">
              <property name="advices">
                <list>
                  <ref bean="persistentContextConversationInterceptor" />
                </list>
              </property>
            </bean>
          </entry>
        </map>
      </property>
    </bean>

    <bean id="thedataSource" class="org.apache.commons.dbcp.BasicDataSource">
      <property name="driverClassName" value="org.h2.Driver" />
      <property name="url"
        value="jdbc:h2:/DATA/dummydatabase;MODE=MYSQL" />
    
      <property name="username" value="theusername" />
      <property name="password" value="thepassword" />
    
      <property name="initialSize">
        <value>2</value>
      </property>
      <property name="maxActive">
        <value>100</value>
      </property>
      <property name="maxIdle">
        <value>2</value>
      </property>
    </bean>

    <bean id="entityManagerFactory"
        class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">

      <property name="dataSource" ref="thedataSource" />
      <property name="jpaDialect">
        <bean class="org.springframework.orm.jpa.vendor.TopLinkJpaDialect" />
      </property>   
      <property name="jpaVendorAdapter">
        <bean
            class="org.springframework.orm.jpa.vendor.TopLinkJpaVendorAdapter">
          <property name="showSql" value="false" />
          <property name="generateDdl" value="true" />
          <property name="databasePlatform" value="oracle.toplink.essentials.platform.database.MySQL4Platform" />
        </bean>
      </property>
    
      <property name="jpaProperties">
        
        <props>
          <prop key="toplink.logging.level">INFO</prop>
          <prop key="toplink.target-database">oracle.toplink.essentials.platform.database.MySQL4Platform</prop>
          <prop key="toplink.ddl-generation">create-tables</prop>
          <prop key="toplink.cache.type.default">HardWeak</prop>
          <prop key="toplink.cache.size.default">5000</prop>
        </props>
      </property>    
      <property name="loadTimeWeaver">
        <bean
            class="org.springframework.instrument.classloading.InstrumentationLoadTimeWeaver" />
      </property>
    </bean>

    <bean id="transactionManager"
        class="org.springframework.orm.jpa.JpaTransactionManager">
      <property name="entityManagerFactory"
        ref="entityManagerFactory" />
    
    </bean>
    
    <bean id="jpaPersistentContextFactory" class="org.apache.myfaces.orchestra.conversation.persistenceContexts.JpaPersistenceContextFactory">
      <property name="entityManagerFactory" ref="entityManagerFactory" />
    </bean>
    <bean id="persistentContextConversationInterceptor" class="org.apache.myfaces.orchestra.conversation.spring.PersistenceContextConversationInterceptor">
      <property name="persistenceContextFactory" ref="jpaPersistentContextFactory" />
    </bean>

  </beans>    
    
This configuration enables load time weaving of the orm classes and thus allows lazy instantiation of classes. The main issue with this configuration is, that Tomcat still needs a javaagent passed down as parameter. If this is not done the loadtime weaving ultimately will fail. the required javaagent is:
-javaagent:<path to the spring weavers>/weavers/spring-agent.jar
    
There are weaverless configurations as well, in spring 2.0.2 it was not yet possible to enable them for jpa and Tomcat. This situation might change soon, please refer to the Spring documentation for additional information on how to enable the loadtime weaving of jpa classes.

Key differences to the original configuration

Following key differences can be found:
  • Load time weaving enabled via: <property name="loadTimeWeaver">
  • A connection pool was used instead of a plain jdbc connection
  • Tomcat has to be started with an appropriate javaagent statement