Skip to main content

Notice: This Wiki is now read only and edits are no longer possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

Difference between revisions of "EclipseLink/Examples/JPA/Spring Web Tutorial"

m (WebLogic 10.3.3.0 Default Spring Support)
m
 
(25 intermediate revisions by the same user not shown)
Line 1: Line 1:
=EclipseLink JPA Deployed on Spring=
+
<!--=EclipseLink JPA Deployed on Spring=
 +
<div style="border: 3px red solid;" align="center" ><font color="red">DISCLAIMER: This page reflects investigation into how EclipseLink users can use EclipseLink JPA and the Spring Framework inside existing WebLogic and Spring releases. It does NOT imply any formal certification from Oracle or SpringSource on any technical details or configuration within this document this time.</font></div>
  
This content is undergoing an expansion as of '''<font color="red">20101220</font>''' in enhancement # '''[http://bugs.eclipse.org/332953 332953]'''
+
This content is undergoing an expansion as of '''<font color="red">20101220</font>''' in enhancement # '''[http://bugs.eclipse.org/332953 332953]''' from an EE enthusiast.
  
  
 
==Purpose==
 
==Purpose==
 +
*A portion of enterprise development uses the Spring framework which is an alternative to traditional JEE/EJB distributed transactions(1.0), local transactions (2.0) and transactional SE frameworks (3.0).  Spring has grown into as large a framework as JEE6 from its original goal of providing a simpler less verbose enterprise MVC framework.  The spring framework can be used in conjunction with or as a replacement for EJB 3.1 technologies.
 +
*This document is for Spring developers that wish to use EclipseLink JPA as their persistence provider or for Spring developers that are migrating from another ORM/JPA provider.
 
*The open source persistence provider - EclipseLink JPA or native EclipseLink can be the ''JPA'' or ''ORM'' provider for Spring beans in Spring based applications.
 
*The open source persistence provider - EclipseLink JPA or native EclipseLink can be the ''JPA'' or ''ORM'' provider for Spring beans in Spring based applications.
 
*The API provided by the Spring framework can range from using the dependency injection ('''DI''') features along with the Aspect Oriented Programming ('''AOP''') support - all the way to using declarative transactions and management of remote resources.
 
*The API provided by the Spring framework can range from using the dependency injection ('''DI''') features along with the Aspect Oriented Programming ('''AOP''') support - all the way to using declarative transactions and management of remote resources.
Line 43: Line 46:
 
==Installation==
 
==Installation==
 
===WebLogic 10.3.3.0===
 
===WebLogic 10.3.3.0===
*In WebLogic 10.3.3.0 there exists 3 spring jars in the modules directory - these are internally wrapped API that support the 2.5.3 version of Spring as indicated.  We may upgrade these to work with Spring 3 as long as we do not encounter issues between 2.5.3 and 3.0 dependency injection.  The pitchfork jar is part of the Oracle open source project for metadata translation of [http://www.jcp.org/en/jsr/detail?id=250 JSR-250] annotations.
+
*Oracle WebLogic [http://www.oracle.com/technetwork/middleware/ias/downloads/fusion-certification-100350.html officially] supports Spring 2.5.x - we will be verifying this July 2008 statement in the ''[http://www.oracle.com/technetwork/middleware/ias/downloads/oracle-wls-certification-10gr3-matr-129284.xls System Requirements and Supported Platforms for Oracle WebLogic Server 10.3 spreadsheet - page 2]''.
 +
*In WebLogic 10.3.3.0 there exists 3 spring jars in the modules directory - these are internally wrapped API that support the 2.5.3 version of Spring as indicated.  We may upgrade these to work with Spring 3 as long as we do not encounter issues between 2.5.3 and 3.0 dependency injection.  The [http://www.springsource.com/products/pitchfork/pitchfork-faq pitchfork] jar is part of the combined '''Oracle''' and '''SpringSource''' open source project for metadata translation of [http://www.jcp.org/en/jsr/detail?id=250 JSR-250] annotations for both WebLogic ans Spring - started by Rod Johnson of Interface21 and Michael Chen of BEA under both the Apache and EPL licenses.
 +
*WebLogic has used Spring as its AOP (Aspect Oriented Programming) engine since June 2005 to provide support for DI (Dependency Injection) of resources and functionality in a '''Proxy''' implementation on the server that contains a reference to the actual business object (Bean or EJB).  The container uses Spring AOP to bytecode weave - at runtime - the proxy so that '''cross-cutting concerns''' can be architected properly.  By instrumenting a business object at runtime using [http://en.wikipedia.org/wiki/Aspect-oriented_programming AOP] we are able to provide dynamic functionality before and after a client operation in support of pre and post operations for transactions and security for example.
 
**<font color="red">[http://oss.oracle.com/projects/pitchfork/ com.bea.core.repackaged.springframework.pitchfork_1.3.0.0_2-0.jar]</font>
 
**<font color="red">[http://oss.oracle.com/projects/pitchfork/ com.bea.core.repackaged.springframework.pitchfork_1.3.0.0_2-0.jar]</font>
 
**<font color="green">com.bea.core.repackaged.springframework.spring_1.1.0.0_'''2-5-3'''.jar</font>
 
**<font color="green">com.bea.core.repackaged.springframework.spring_1.1.0.0_'''2-5-3'''.jar</font>
 
**com.bea.core.weblogic.spring.instrument_1.2.0.0.jar
 
**com.bea.core.weblogic.spring.instrument_1.2.0.0.jar
 
*The notable thing about using the '''com.bea.core''' namespace is that it will not confict with any '''com.springsource''' Spring versions shipped with Spring EAR applications.
 
*The notable thing about using the '''com.bea.core''' namespace is that it will not confict with any '''com.springsource''' Spring versions shipped with Spring EAR applications.
 +
*From what I can see there is a bit of history on Spring and WebLogic cooperation
 
*The '''wlserver_10.3/server/lib/weblogic-spring.jar''' contains WebLogic specific integration with the above 3 spring jars
 
*The '''wlserver_10.3/server/lib/weblogic-spring.jar''' contains WebLogic specific integration with the above 3 spring jars
 
*The '''wlserver_10.3/server/lib/console-ext/spring-console.jar''' contains WebLogic specific [http://download.oracle.com/docs/cd/E12839_01/web.1111/e14453/enable_console_ext.htm#CIHCAIBE integration with the WebLogic admin console]
 
*The '''wlserver_10.3/server/lib/console-ext/spring-console.jar''' contains WebLogic specific [http://download.oracle.com/docs/cd/E12839_01/web.1111/e14453/enable_console_ext.htm#CIHCAIBE integration with the WebLogic admin console]
 +
 
===WebLogic 10.3.3.0 Default Spring Support===
 
===WebLogic 10.3.3.0 Default Spring Support===
 
*If you try to deploy a Spring framework based application - you will see the following CNFE (ClassNotFoundException) or similar depending on what Spring JSR-250 annotations or XML markup you use.
 
*If you try to deploy a Spring framework based application - you will see the following CNFE (ClassNotFoundException) or similar depending on what Spring JSR-250 annotations or XML markup you use.
Line 79: Line 86:
 
         </init-param>
 
         </init-param>
 
     </servlet>
 
     </servlet>
    <!-- standard web.xml (non-Spring) - leave commented -->
 
    <!-- servlet>
 
      <description></description>
 
      <display-name>FrontController</display-name>
 
      <servlet-name>FrontController</servlet-name>
 
      <servlet-class>org.eclipse.persistence.example.jpa.spring.presentation.FrontController</servlet-class>
 
    </servlet-->
 
 
</source>
 
</source>
 +
*The reason that the '''org.springframework.web.servlet.DispatcherServlet''' class cannot be loaded by WebLogic is either that it is unavailable or that there is another version in the classpath (not likely or we would get a ClassCastException).
 +
*The '''DispatcherServlet''' is inside '''org.springframework.web.servlet-3.0.5.RELEASE.jar'''
 
*You therefore need to distribute the Spring jars or place them on the server as explained in the section
 
*You therefore need to distribute the Spring jars or place them on the server as explained in the section
 +
====Systematic Inclusion of Spring libraries in WebLogic====
 +
*The goal is to get the latest Spring 3.0.5 working with the latest WebLogic 10.3.3.0.  Hopefully we do not need to rever to using the supported Spring 3.5.3 or 3.5.6 versions.
 +
*The following ClassNotFoundExceptions are being eradicated one at a time usually be easily matching the class with the appropriate 1 of 20 Spring module.  It would be nice to use some sort of OSGI support for dynamic module loading - we are only using PDE at this point.
 +
**1) '''org.springframework.web.servlet.DispatcherServlet''' is in ''org.springframework.web.servlet-3.0.5.RELEASE.jar''
 +
**2) '''org.apache.commons.logging.Log''' is in ''commons-logging.jar''
 +
**3) '''org.springframework.web.util.UrlPathHelper''' is in ''org.springframework.web-3.0.5.RELEASE.jar''
 +
**4) '''org.springframework.context.ApplicationContext''' is in ''org.springframework.context-3.0.5.RELEASE.jar''
 +
**5) '''org.springframework.beans.factory.ListableBeanFactory''' is in ''org.springframework.beans-3.0.5.RELEASE.jar''
 +
**6) '''org.springframework.core.io.support.ResourcePatternResolver''' is in ''org.springframework.core-3.0.5.RELEASE.jar''
 +
*Alright, we are now deployed and at the point where we are looking for the persistence unit - which is not properly configured yet.
 +
<source lang="java">
 +
Caused By: java.lang.IllegalArgumentException: No persistence unit named 'spring' is available in scope springhypercube. Available persistence units: []
 +
at weblogic.deployment.ModulePersistenceUnitRegistry.getPersistenceUnit(ModulePersistenceUnitRegistry.java:132)
 +
at weblogic.deployment.BasePersistenceContextProxyImpl.<init>(BasePersistenceContextProxyImpl.java:39)
 +
</source>
 +
*We are currently running on a modified server (so we do not have to ship the Spring modules with the EAR/WAR) with the following change to '''$WLS_Server/wlserver_10.3/common/bin/commEnv.cml:151
 +
<source lang="java">
 +
set SPRING_CP=C:/opt/spring305/dist
 +
set WEBLOGIC_CLASSPATH=%SPRING_CP%/org.springframework.web.servlet-3.0.5.RELEASE.jar;C:/opt/spring3/commons-logging.jar;%SPRING_CP%/org.springframework.web-3.0.5.RELEASE.jar;%SPRING_CP%/org.springframework.context-3.0.5.RELEASE.jar;%SPRING_CP%/org.springframework.beans-3.0.5.RELEASE.jar;%SPRING_CP%/org.springframework.core-3.0.5.RELEASE.jar;%JAVA_HOME%\lib\tools.jar;%WL_HOME%\server\lib\weblogic_sp.jar;%WL_HOME%\server\lib\weblogic.jar;%FEATURES_DIR%\weblogic.server.modules_10.3.4.0.jar;%WL_HOME%\server\lib\webservices.jar;%ANT_HOME%/lib/ant-all.jar;%ANT_CONTRIB%/lib/ant-contrib.jar
 +
 +
</source>
  
 
===Spring 3 Download===
 
===Spring 3 Download===
Line 130: Line 153:
  
 
*Where the following '''classpath variables''' need to be defined
 
*Where the following '''classpath variables''' need to be defined
 +
**SPRING_AOP=org.springframework.aop-3.0.5.RELEASE.jar
 +
**SPRING_ASM=org.springframework.asm-3.0.5.RELEASE.jar
 +
**SPRING_ASPECTS=org.springframework.aspects-3.0.5.RELEASE.jar
 +
**SPRING_BEANS=org.springframework.beans-3.0.5.RELEASE.jar
 +
**SPRING_CONTEXT=org.springframework.context-3.0.5.RELEASE.jar
 +
**SPRING_CONTEXT_SUPPORT=org.springframework.context.support-3.0.5.RELEASE.jar
 +
**SPRING_CORE=org.springframework.core-3.0.5.RELEASE.jar
 +
**SPRING_EXPRESSION=org.springframework.expression-3.0.5.RELEASE.jar
 +
**SPRING_INSTRUMENT=org.springframework.instrument-3.0.5.RELEASE.jar
 +
**SPRING_INSTRUMENT_TOMCAT=org.springframework.instrument.tomcat-3.0.5.RELEASE.jar
 +
**SPRING_JDBC=org.springframework.jdbc-3.0.5.RELEASE.jar
 +
**SPRING_JMS=org.springframework.jms-3.0.5.RELEASE.jar
 +
**SPRING_ORM=org.springframework.orm-3.0.5.RELEASE.jar
 +
**SPRING_OXM=org.springframework.oxm-3.0.5.RELEASE.jar
 +
**SPRING_TEST=org.springframework.test-3.0.5.RELEASE.jar
 +
**SPRING_TRANSACTION=org.springframework.transaction-3.0.5.RELEASE.jar
 +
**SPRING_WEB=org.springframework.web-3.0.5.RELEASE.jar
 +
**SPRING_PORTLET=org.springframework.web.portlet-3.0.5.RELEASE.jar
 +
**SPRING_SERVLET=org.springframework.web.servlet-3.0.5.RELEASE.jar
 +
**SPRING_STRUTS=org.springframework.web.struts-3.0.5.RELEASE.jar
 +
===Spring Integration with WebLogic===
  
SPRING_AOP=org.springframework.aop-3.0.5.RELEASE.jar
+
*There are several options for getting the Spring framework enabled for your Spring WAR in WebLogic Server. I have ordered them in decreasing impact on the WebLogic server config and increasing application managed state.
SPRING_ASM=org.springframework.asm-3.0.5.RELEASE.jar
+
====Option 1: <font color="green">'''Spring library jars highest in WEBLOGIC_CLASSPATH var in commEnv.cmd script'''</font> - in use====
SPRING_ASPECTS=org.springframework.aspects-3.0.5.RELEASE.jar
+
*This option will override anything on the server and deployed WAR's (except '''prefer-application-packages''' overrides). It will deal with most classLoader and CNFE issues. Later we may want to refactor how the Spring modules are packaged to minimize server impact.
SPRING_BEANS=org.springframework.beans-3.0.5.RELEASE.jar
+
 
SPRING_CONTEXT=org.springframework.context-3.0.5.RELEASE.jar
+
====Option 2: Spring library jars in WebLogic modules directory====
SPRING_CONTEXT_SUPPORT=org.springframework.context.support-3.0.5.RELEASE.jar
+
====Option 3: Spring library jars in WebLogic Domain lib directory====
SPRING_CORE=org.springframework.core-3.0.5.RELEASE.jar
+
====Option 4: Spring library jars in shared separate EAR library====
SPRING_EXPRESSION=org.springframework.expression-3.0.5.RELEASE.jar
+
====Option 5: Spring library jars deployed with EAR APP-INF/lib directory using <font color="red">'''prefer-application-packages'''</font> override====
SPRING_INSTRUMENT=org.springframework.instrument-3.0.5.RELEASE.jar
+
====Option 6: Spring library jars deployed with WAR lib directory====
SPRING_INSTRUMENT_TOMCAT=org.springframework.instrument.tomcat-3.0.5.RELEASE.jar
+
SPRING_JDBC=org.springframework.jdbc-3.0.5.RELEASE.jar
+
SPRING_JMS=org.springframework.jms-3.0.5.RELEASE.jar
+
SPRING_ORM=org.springframework.orm-3.0.5.RELEASE.jar
+
SPRING_OXM=org.springframework.oxm-3.0.5.RELEASE.jar
+
SPRING_TEST=org.springframework.test-3.0.5.RELEASE.jar
+
SPRING_TRANSACTION=org.springframework.transaction-3.0.5.RELEASE.jar
+
SPRING_WEB=org.springframework.web-3.0.5.RELEASE.jar
+
SPRING_PORTLET=org.springframework.web.portlet-3.0.5.RELEASE.jar
+
SPRING_SERVLET=org.springframework.web.servlet-3.0.5.RELEASE.jar
+
SPRING_STRUTS=org.springframework.web.struts-3.0.5.RELEASE.jar
+
  
 
===Eclipse 3.6 Setup===
 
===Eclipse 3.6 Setup===
Line 173: Line 206:
 
*Following '''Scenario SC3''' we will place our entities inside
 
*Following '''Scenario SC3''' we will place our entities inside
 
==Dependency Injection==
 
==Dependency Injection==
 +
===@Controller===
 +
====@Autowired====
 +
====@RequestMapping====
 +
===@Repository===
 +
===@Transactional===
 +
*Declarative transaction management - like [http://www.jcp.org/en/jsr/detail?id=220 JSR-220]/[http://www.jcp.org/en/jsr/detail?id=318 JSR-318] EJB 3.0/3.1 transactional stateless and stateful session bean annotations via the javax.ecj.SessionSychronization package updated for non-remote calls (2.0) and non-EE (SE) clients in (3.0)
 +
 
==Web.xml==
 
==Web.xml==
 
*The version of the xmlns:web namespace must be 2.5 not 2.4
 
*The version of the xmlns:web namespace must be 2.5 not 2.4
Line 190: Line 230:
 
*If you were using a Hibernate SessionFactory for ORM you could describe your entities in the '''AnnotationSessionFactoryBean''' bean element to match the '''class''' elements from persistence.xml - if auto-discovery was not enabled
 
*If you were using a Hibernate SessionFactory for ORM you could describe your entities in the '''AnnotationSessionFactoryBean''' bean element to match the '''class''' elements from persistence.xml - if auto-discovery was not enabled
  
*The
 
  
 
==Transaction Manager Configuration==
 
==Transaction Manager Configuration==
Line 208: Line 247:
  
  
 
'''Previous 2008 content - currently undergoing refactoring on 20101220'''
 
 
==Downloading EclipseLink Libraries==
 
===Download EclipseLink using HTTP - recommended===
 
*Proceed to the following URL and download the latest eclipselink.zip which contains everything you need.
 
**http://www.eclipse.org/eclipselink/downloads/index.php
 
***'''Click on the "EclipseLink 1.0.2 Installer Zip''' link which resolves to http://www.eclipse.org/downloads/download.php?file=/rt/eclipselink/releases/1.0.2/eclipselink-1.0.2.zip
 
*Expand the zip file and get the following 2 files
 
**eclipselink-1.0.2\eclipselink\jlib\eclipselink.jar
 
**eclipselink-1.0.2\eclipselink\jlib\jpa\javax.persistence_1.0.0.jar
 
===Download EclipseLink using Maven===
 
See the repository on http://www.eclipse.org/eclipselink/downloads/index.php
 
===Download EclipseLink using SVN - developers only===
 
*Get the following ''<font color="blue">eclipselink.jar</font>'' and ''<font color="blue">javax.persistence*.jar</font>'' from http://www.eclipselink.org ready for your EclipseLink shared library - ''(I am running rev 2.0.0.20090218-SNAPSHOT)''
 
**The following page details four different ways to either obtain the binary jars or download the source and build them yourself with an anon account.
 
**http://wiki.eclipse.org/EclipseLink/Source
 
 
 
http://www.springframework.org/download
 
http://sourceforge.net/project/downloading.php?group_id=73357&use_mirror=voxel&filename=spring-framework-2.5.5-with-dependencies.zip&50273885
 
 
==Eclipse Launch Targets==
 
<pre>
 
-javaagent:c:\opt\spring3\org.springframework.instrument-3.0.0.RELEASE.jar
 
</pre>
 
 
==Change Log==
 
==Change Log==
 
*20080922 - start tutorial template (no content)
 
*20080922 - start tutorial template (no content)
Line 239: Line 252:
  
 
==References==
 
==References==
 +
*[http://download.oracle.com/docs/cd/E12840_01/wls/docs103/programming/spring.html Oracle WebLogic Server - Spring Applications Reference]
 
*[http://oss.oracle.com/projects/pitchfork/ Oracle Pitchfork open source metadata translation project]
 
*[http://oss.oracle.com/projects/pitchfork/ Oracle Pitchfork open source metadata translation project]
 
*[http://download.oracle.com/docs/cd/E12839_01/web.1111/e14453/enable_spring.htm#CHDIIIGJ WebLogic support for Spring Dependency Injection]
 
*[http://download.oracle.com/docs/cd/E12839_01/web.1111/e14453/enable_spring.htm#CHDIIIGJ WebLogic support for Spring Dependency Injection]
Line 253: Line 267:
 
*Need to respond to...
 
*Need to respond to...
 
**http://old.nabble.com/Eclipselink-with-Spring-2.5.6-and-Weblogic-10.3-p24095716.html and http://dev.eclipse.org/mhonarc/lists/eclipselink-users/msg02836.html
 
**http://old.nabble.com/Eclipselink-with-Spring-2.5.6-and-Weblogic-10.3-p24095716.html and http://dev.eclipse.org/mhonarc/lists/eclipselink-users/msg02836.html
 +
-->

Latest revision as of 13:20, 25 December 2010

Back to the top