[jboss-cvs] JBossAS SVN: r110995 - projects/docs/enterprise/WFK/Spring_Developer_Guide/en-US.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Tue Mar 22 09:17:50 EDT 2011


Author: marius.bogoevici
Date: 2011-03-22 09:17:50 -0400 (Tue, 22 Mar 2011)
New Revision: 110995

Added:
   projects/docs/enterprise/WFK/Spring_Developer_Guide/en-US/Appendix_A.xml
   projects/docs/enterprise/WFK/Spring_Developer_Guide/en-US/Appendix_B.xml
Modified:
   projects/docs/enterprise/WFK/Spring_Developer_Guide/en-US/Getting_Started_Introductory_Example.xml
   projects/docs/enterprise/WFK/Spring_Developer_Guide/en-US/Spring_Developer_Guide.xml
   projects/docs/enterprise/WFK/Spring_Developer_Guide/en-US/Spring_On_JBoss_Best_Practices.xml
Log:
Further content

Added: projects/docs/enterprise/WFK/Spring_Developer_Guide/en-US/Appendix_A.xml
===================================================================
--- projects/docs/enterprise/WFK/Spring_Developer_Guide/en-US/Appendix_A.xml	                        (rev 0)
+++ projects/docs/enterprise/WFK/Spring_Developer_Guide/en-US/Appendix_A.xml	2011-03-22 13:17:50 UTC (rev 110995)
@@ -0,0 +1,105 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE chapter PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN"
+"http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd" [
+<!ENTITY % BOOK_ENTITIES SYSTEM "Spring_Developer_Guide.ent">
+%BOOK_ENTITIES;
+]>
+<appendix>
+  <title id="appendix_maven_deps">Maven dependencies for the introductory
+  example</title>
+
+  <section>
+    <para>In order to </para>
+
+    <programlisting> &lt;dependencies&gt;
+    &lt;dependency&gt;
+      &lt;groupId&gt;junit&lt;/groupId&gt;
+      &lt;artifactId&gt;junit&lt;/artifactId&gt;
+      &lt;version&gt;4.7&lt;/version&gt;
+      &lt;scope&gt;test&lt;/scope&gt;
+    &lt;/dependency&gt;
+    &lt;dependency&gt;
+    	&lt;groupId&gt;org.hibernate&lt;/groupId&gt;
+    	&lt;artifactId&gt;hibernate-core&lt;/artifactId&gt;
+    	&lt;version&gt;3.3.0.GA&lt;/version&gt;
+    	&lt;scope&gt;provided&lt;/scope&gt;
+    &lt;/dependency&gt;
+    &lt;dependency&gt;
+    	&lt;groupId&gt;org.hibernate&lt;/groupId&gt;
+    	&lt;artifactId&gt;hibernate-entitymanager&lt;/artifactId&gt;
+    	&lt;version&gt;3.4.0.GA&lt;/version&gt;
+    	&lt;scope&gt;provided&lt;/scope&gt;
+    &lt;/dependency&gt;
+    &lt;dependency&gt;
+    	&lt;groupId&gt;taglibs&lt;/groupId&gt;
+    	&lt;artifactId&gt;standard&lt;/artifactId&gt;
+    	&lt;version&gt;1.1.2&lt;/version&gt;
+    &lt;/dependency&gt;
+    &lt;dependency&gt;
+        &lt;groupId&gt;commons-logging&lt;/groupId&gt;
+    	&lt;artifactId&gt;commons-logging&lt;/artifactId&gt;
+    	&lt;version&gt;1.1.1&lt;/version&gt;
+    &lt;/dependency&gt;
+    &lt;dependency&gt;
+        &lt;groupId&gt;aopalliance&lt;/groupId&gt;
+    	&lt;artifactId&gt;aopalliance&lt;/artifactId&gt;
+    	&lt;version&gt;1.0&lt;/version&gt;
+    &lt;/dependency&gt;
+    &lt;dependency&gt;
+    	&lt;groupId&gt;org.springframework&lt;/groupId&gt;
+    	&lt;artifactId&gt;spring-asm&lt;/artifactId&gt;
+    	&lt;version&gt;3.0.5.RELEASE&lt;/version&gt;
+    &lt;/dependency&gt;
+    &lt;dependency&gt;
+    	&lt;groupId&gt;org.springframework&lt;/groupId&gt;
+    	&lt;artifactId&gt;spring-aop&lt;/artifactId&gt;
+    	&lt;version&gt;3.0.5.RELEASE&lt;/version&gt;
+    &lt;/dependency&gt;
+    &lt;dependency&gt;
+    	&lt;groupId&gt;org.springframework&lt;/groupId&gt;
+    	&lt;artifactId&gt;spring-expression&lt;/artifactId&gt;
+    	&lt;version&gt;3.0.5.RELEASE&lt;/version&gt;
+    &lt;/dependency&gt;
+     &lt;dependency&gt;
+    	&lt;groupId&gt;org.springframework&lt;/groupId&gt;
+    	&lt;artifactId&gt;spring-beans&lt;/artifactId&gt;
+    	&lt;version&gt;3.0.5.RELEASE&lt;/version&gt;
+    &lt;/dependency&gt;
+     &lt;dependency&gt;
+    	&lt;groupId&gt;org.springframework&lt;/groupId&gt;
+    	&lt;artifactId&gt;spring-context&lt;/artifactId&gt;
+    	&lt;version&gt;3.0.5.RELEASE&lt;/version&gt;
+    &lt;/dependency&gt;
+     &lt;dependency&gt;
+    	&lt;groupId&gt;org.springframework&lt;/groupId&gt;
+    	&lt;artifactId&gt;spring-context-support&lt;/artifactId&gt;
+    	&lt;version&gt;3.0.5.RELEASE&lt;/version&gt;
+    &lt;/dependency&gt;
+    &lt;dependency&gt;
+    	&lt;groupId&gt;org.springframework&lt;/groupId&gt;
+    	&lt;artifactId&gt;spring-tx&lt;/artifactId&gt;
+    	&lt;version&gt;3.0.5.RELEASE&lt;/version&gt;
+    &lt;/dependency&gt;
+    &lt;dependency&gt;
+    	&lt;groupId&gt;org.springframework&lt;/groupId&gt;
+    	&lt;artifactId&gt;spring-core&lt;/artifactId&gt;
+    	&lt;version&gt;3.0.5.RELEASE&lt;/version&gt;
+    &lt;/dependency&gt;
+    &lt;dependency&gt;
+    	&lt;groupId&gt;org.springframework&lt;/groupId&gt;
+    	&lt;artifactId&gt;spring-jdbc&lt;/artifactId&gt;
+    	&lt;version&gt;3.0.5.RELEASE&lt;/version&gt;
+    &lt;/dependency&gt;
+    &lt;dependency&gt;
+    	&lt;groupId&gt;org.springframework&lt;/groupId&gt;
+    	&lt;artifactId&gt;spring-web&lt;/artifactId&gt;
+    	&lt;version&gt;3.0.5.RELEASE&lt;/version&gt;
+    &lt;/dependency&gt;
+    &lt;dependency&gt;
+    	&lt;groupId&gt;org.springframework&lt;/groupId&gt;
+    	&lt;artifactId&gt;spring-webmvc&lt;/artifactId&gt;
+    	&lt;version&gt;3.0.5.RELEASE&lt;/version&gt;
+    &lt;/dependency&gt;
+  &lt;/dependencies&gt;</programlisting>
+  </section>
+</appendix>

Added: projects/docs/enterprise/WFK/Spring_Developer_Guide/en-US/Appendix_B.xml
===================================================================
--- projects/docs/enterprise/WFK/Spring_Developer_Guide/en-US/Appendix_B.xml	                        (rev 0)
+++ projects/docs/enterprise/WFK/Spring_Developer_Guide/en-US/Appendix_B.xml	2011-03-22 13:17:50 UTC (rev 110995)
@@ -0,0 +1,69 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE chapter PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN"
+"http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd" [
+<!ENTITY % BOOK_ENTITIES SYSTEM "Spring_Developer_Guide.ent">
+%BOOK_ENTITIES;
+]>
+<appendix>
+  <title id="Appendix_JBDS_Setup">Setting up JBDS</title>
+
+  <section>
+    <title>Installing m2eclipse</title>
+
+    <para>Detailed instructions for installing m2eclipse can be found at
+    <uri>http://m2eclipse.sonatype.org/installing-m2eclipse.html</uri>.For
+    this version of the document, For the example (and in general for building
+    WTP applications), you need to install at least the following Core and
+    Extras m2eclipse components, as follows:</para>
+
+    <itemizedlist>
+      <listitem>
+        <para>From the Core update site
+        (<uri>http://m2eclipse.sonatype.org/sites/m2e</uri>):</para>
+
+        <itemizedlist>
+          <listitem>
+            <para>Install "Maven Integration for Eclipse (Required)"</para>
+          </listitem>
+        </itemizedlist>
+      </listitem>
+
+      <listitem>
+        <para>From the Extras update
+        site(<uri>http://m2eclipse.sonatype.org/sites/m2e-extras</uri>)</para>
+
+        <itemizedlist>
+          <listitem>
+            <para>Install "Maven Integration for WTP"</para>
+          </listitem>
+        </itemizedlist>
+      </listitem>
+    </itemizedlist>
+
+    <para>The list above contains the <emphasis>minimal</emphasis> set of
+    plugins required for the example. Any plugins from the provided update
+    sites can be installed as well, if needed.</para>
+  </section>
+
+  <section>
+    <title>Setting up Maven for m2eclipse</title>
+
+    <para>The m2eclipse plugin is bundled with a SNAPSHOT version of Maven.
+    You can configure it to use a specific Maven version. In order to do so,
+    go to Preferences, select Maven-&gt;Instalations and click "Add...", after
+    which you will be prompted to select the directory which contains the
+    Maven distribution that you intend to use. After doing so, a new Maven
+    version is added to the list. Make sure that the checkbox besides it is
+    selected (which means that this particular version of Maven will be used
+    by default by m2eclipse).</para>
+  </section>
+
+  <section>
+    <title>Adding a JBoss EAP instance</title>
+
+    <para>A regular installation of JBoss Developer Studio will set up one or
+    more JBoss EAP instances. However, it is possible to add more instances
+    after the installation if that is necessary. Please consult the JBoss
+    Developer Studio documentation on how to do that.</para>
+  </section>
+</appendix>

Modified: projects/docs/enterprise/WFK/Spring_Developer_Guide/en-US/Getting_Started_Introductory_Example.xml
===================================================================
--- projects/docs/enterprise/WFK/Spring_Developer_Guide/en-US/Getting_Started_Introductory_Example.xml	2011-03-22 12:55:10 UTC (rev 110994)
+++ projects/docs/enterprise/WFK/Spring_Developer_Guide/en-US/Getting_Started_Introductory_Example.xml	2011-03-22 13:17:50 UTC (rev 110995)
@@ -18,7 +18,7 @@
 
     <itemizedlist>
       <listitem>
-        <para>Maven 3.0.1 (optional, for maven-based examples only)</para>
+        <para>Maven 3.0.3 (optional, for maven-based examples only)</para>
       </listitem>
 
       <listitem>
@@ -27,14 +27,35 @@
       </listitem>
 
       <listitem>
-        <para>JBoss Developer Studio 3 with m2eclipse (including WTP
-        integration)</para>
+        <para>JBoss Developer Studio 4 with m2eclipse (including WTP
+        integration) - see Appendix B for JBoss Developer Studio configuration
+        details</para>
       </listitem>
 
       <listitem>
-        <para>JBoss Enterprise Application Platform 5.1.1</para>
+        <para>JBoss Enterprise Application Platform 5.1.2</para>
       </listitem>
     </itemizedlist>
+
+    <section>
+      <title>Assumptions and placeholder names</title>
+
+      <para>During this tutorial, we are going to assume that:</para>
+
+      <itemizedlist>
+        <listitem>
+          <para>The location of JBoss Enterprise Application is $EAP_HOME,
+          which represents the top-level directory of the extracted
+          distribution (usually jboss-eap-5.1) ;</para>
+        </listitem>
+
+        <listitem>
+          <para>We use the placeholder &lt;profile&gt; to indicate the JBoss
+          AS profile with which the application is launched (usually
+          default);</para>
+        </listitem>
+      </itemizedlist>
+    </section>
   </section>
 
   <section>
@@ -75,7 +96,7 @@
       <title>Creating the Maven project structure</title>
 
       <para>Creating a Maven-based web application from JBDS is fairly easy,
-      if the m2eclipse plugin (both core an WTP integration) is
+      if the m2eclipse plugin (both core and WTP integration) is
       installed.</para>
 
       <para>Go to New-&gt;Maven Project (may need to select the 'Other' option
@@ -93,119 +114,138 @@
       at this point, so the option is not in use.</para>
 
       <para>The following dependencies need to be included in your
-      application:</para>
+      application:<table>
+          <title>Dependencies needed by the example</title>
 
-      <example>
-        <title>Dependency set for the example</title>
+          <tgroup cols="4">
+            <tbody>
+              <row>
+                <entry>Dependency</entry>
 
-        <para></para>
+                <entry>Maven Identifier</entry>
 
-        <programlisting> &lt;dependencies&gt;
-    &lt;dependency&gt;
-      &lt;groupId&gt;junit&lt;/groupId&gt;
-      &lt;artifactId&gt;junit&lt;/artifactId&gt;
-      &lt;version&gt;4.7&lt;/version&gt;
-      &lt;scope&gt;test&lt;/scope&gt;
-    &lt;/dependency&gt;
-    &lt;dependency&gt;
-    	&lt;groupId&gt;org.hibernate&lt;/groupId&gt;
-    	&lt;artifactId&gt;hibernate-core&lt;/artifactId&gt;
-    	&lt;version&gt;3.3.0.GA&lt;/version&gt;
-    	&lt;scope&gt;provided&lt;/scope&gt;
-    &lt;/dependency&gt;
-    &lt;dependency&gt;
-    	&lt;groupId&gt;org.hibernate&lt;/groupId&gt;
-    	&lt;artifactId&gt;hibernate-entitymanager&lt;/artifactId&gt;
-    	&lt;version&gt;3.4.0.GA&lt;/version&gt;
-    	&lt;scope&gt;provided&lt;/scope&gt;
-    &lt;/dependency&gt;
-    &lt;dependency&gt;
-    	&lt;groupId&gt;taglibs&lt;/groupId&gt;
-    	&lt;artifactId&gt;standard&lt;/artifactId&gt;
-    	&lt;version&gt;1.1.2&lt;/version&gt;
-    &lt;/dependency&gt;
-    &lt;dependency&gt;
-        &lt;groupId&gt;commons-logging&lt;/groupId&gt;
-    	&lt;artifactId&gt;commons-logging&lt;/artifactId&gt;
-    	&lt;version&gt;1.1.1&lt;/version&gt;
-    &lt;/dependency&gt;
-    &lt;dependency&gt;
-        &lt;groupId&gt;aopalliance&lt;/groupId&gt;
-    	&lt;artifactId&gt;aopalliance&lt;/artifactId&gt;
-    	&lt;version&gt;1.0&lt;/version&gt;
-    &lt;/dependency&gt;
-    &lt;dependency&gt;
-    	&lt;groupId&gt;org.springframework&lt;/groupId&gt;
-    	&lt;artifactId&gt;spring-asm&lt;/artifactId&gt;
-    	&lt;version&gt;3.0.5.RELEASE&lt;/version&gt;
-    &lt;/dependency&gt;
-    &lt;dependency&gt;
-    	&lt;groupId&gt;org.springframework&lt;/groupId&gt;
-    	&lt;artifactId&gt;spring-aop&lt;/artifactId&gt;
-    	&lt;version&gt;3.0.5.RELEASE&lt;/version&gt;
-    &lt;/dependency&gt;
-    &lt;dependency&gt;
-    	&lt;groupId&gt;org.springframework&lt;/groupId&gt;
-    	&lt;artifactId&gt;spring-expression&lt;/artifactId&gt;
-    	&lt;version&gt;3.0.5.RELEASE&lt;/version&gt;
-    &lt;/dependency&gt;
-     &lt;dependency&gt;
-    	&lt;groupId&gt;org.springframework&lt;/groupId&gt;
-    	&lt;artifactId&gt;spring-beans&lt;/artifactId&gt;
-    	&lt;version&gt;3.0.5.RELEASE&lt;/version&gt;
-    &lt;/dependency&gt;
-     &lt;dependency&gt;
-    	&lt;groupId&gt;org.springframework&lt;/groupId&gt;
-    	&lt;artifactId&gt;spring-context&lt;/artifactId&gt;
-    	&lt;version&gt;3.0.5.RELEASE&lt;/version&gt;
-    &lt;/dependency&gt;
-     &lt;dependency&gt;
-    	&lt;groupId&gt;org.springframework&lt;/groupId&gt;
-    	&lt;artifactId&gt;spring-context-support&lt;/artifactId&gt;
-    	&lt;version&gt;3.0.5.RELEASE&lt;/version&gt;
-    &lt;/dependency&gt;
-    &lt;dependency&gt;
-    	&lt;groupId&gt;org.springframework&lt;/groupId&gt;
-    	&lt;artifactId&gt;spring-tx&lt;/artifactId&gt;
-    	&lt;version&gt;3.0.5.RELEASE&lt;/version&gt;
-    &lt;/dependency&gt;
-    &lt;dependency&gt;
-    	&lt;groupId&gt;org.springframework&lt;/groupId&gt;
-    	&lt;artifactId&gt;spring-beans&lt;/artifactId&gt;
-    	&lt;version&gt;3.0.5.RELEASE&lt;/version&gt;
-    &lt;/dependency&gt;
-    &lt;dependency&gt;
-    	&lt;groupId&gt;org.springframework&lt;/groupId&gt;
-    	&lt;artifactId&gt;spring-core&lt;/artifactId&gt;
-    	&lt;version&gt;3.0.5.RELEASE&lt;/version&gt;
-    &lt;/dependency&gt;
-    &lt;dependency&gt;
-    	&lt;groupId&gt;org.springframework&lt;/groupId&gt;
-    	&lt;artifactId&gt;spring-jdbc&lt;/artifactId&gt;
-    	&lt;version&gt;3.0.5.RELEASE&lt;/version&gt;
-    &lt;/dependency&gt;
-    &lt;dependency&gt;
-    	&lt;groupId&gt;org.springframework&lt;/groupId&gt;
-    	&lt;artifactId&gt;spring-web&lt;/artifactId&gt;
-    	&lt;version&gt;3.0.5.RELEASE&lt;/version&gt;
-    &lt;/dependency&gt;
-    &lt;dependency&gt;
-    	&lt;groupId&gt;org.springframework&lt;/groupId&gt;
-    	&lt;artifactId&gt;spring-webmvc&lt;/artifactId&gt;
-    	&lt;version&gt;3.0.5.RELEASE&lt;/version&gt;
-    &lt;/dependency&gt;
-  &lt;/dependencies&gt;</programlisting>
-      </example>
+                <entry>Version</entry>
 
+                <entry>Scope</entry>
+              </row>
+
+              <row>
+                <entry>Hibernate Core</entry>
+
+                <entry>org.hibernate:hibernate-core</entry>
+
+                <entry>3.3.0.GA</entry>
+
+                <entry>provided</entry>
+              </row>
+
+              <row>
+                <entry>Hibernate Entity Manager</entry>
+
+                <entry>org.hibernate:hibernate-entitymanager</entry>
+
+                <entry>3.4.0.GA</entry>
+
+                <entry>provided</entry>
+              </row>
+
+              <row>
+                <entry>Standard Taglibs</entry>
+
+                <entry>taglibs:standard</entry>
+
+                <entry>1.1.2</entry>
+
+                <entry>compile</entry>
+              </row>
+
+              <row>
+                <entry>Commons Logging</entry>
+
+                <entry>commons-logging:commons-logging</entry>
+
+                <entry>1.1.1</entry>
+
+                <entry>compile</entry>
+              </row>
+
+              <row>
+                <entry>AOP Alliance API</entry>
+
+                <entry>aopalliance:aopalliance</entry>
+
+                <entry>1.0</entry>
+
+                <entry>compile</entry>
+              </row>
+
+              <row>
+                <entry>Spring Modules</entry>
+
+                <entrytbl cols="1">
+                  <tbody>
+                    <row>
+                      <entry>org.springframework:spring-aop</entry>
+                    </row>
+
+                    <row>
+                      <entry>org.springframework:spring-asm</entry>
+                    </row>
+
+                    <row>
+                      <entry>org.springframework:spring-expression</entry>
+                    </row>
+
+                    <row>
+                      <entry>org.springframework:spring-beans</entry>
+                    </row>
+
+                    <row>
+                      <entry>org.springframework:spring-context</entry>
+                    </row>
+
+                    <row>
+                      <entry>org.springframework:spring-context-support</entry>
+                    </row>
+
+                    <row>
+                      <entry>org.springframework:spring-tx</entry>
+                    </row>
+
+                    <row>
+                      <entry>org.springframework:spring-core</entry>
+                    </row>
+
+                    <row>
+                      <entry>org.springframework:spring-jdbc</entry>
+                    </row>
+
+                    <row>
+                      <entry>org.springframework:spring-orm</entry>
+                    </row>
+                  </tbody>
+                </entrytbl>
+
+                <entry>3.0.5.RELEASE</entry>
+
+                <entry>compile</entry>
+              </row>
+            </tbody>
+          </tgroup>
+        </table></para>
+
+      <para>Appendin</para>
+
       <para>The artifact may not create the Java source folder, so you may
       have to add it yourself. Go to 'New'-&gt;Source Folder and enter a value
-      of 'src/main/java'.</para>
+      of 'src/main/java', and then 'Finish'.</para>
 
       <para>The final step is to add the Spring Project nature to your
       project. While this is not strictly necessary for your application, it
       will enable integration with the Spring IDE, which includes visualizing
       your application context definitions and syntactical and semantical
-      checks.</para>
+      checks. Open the contextual menu for the project (click right on the
+      project) and select Spring Tools-&gt;Add Spring Project nature.</para>
     </section>
 
     <section>
@@ -219,8 +259,11 @@
       information about a User. It is a persistent class, so it also contains
       JPA mappings.</para>
 
-      <programlisting>package org.jboss.spring.getting.started.domain;
+      <example>
+        <title>Domain entity definition</title>
 
+        <para><programlisting>package org.jboss.spring.getting.started.domain;
+
 import javax.persistence.Column;
 import javax.persistence.Entity;
 import javax.persistence.Id;
@@ -263,16 +306,21 @@
    this.lastName = lastName;
  }
  
-}</programlisting>
+}</programlisting></para>
+      </example>
 
       <para>Data access will be provided through a JPA-based DAO, which will
       be installed as Spring Bean. The interface for this component is:</para>
 
-      <programlisting>package org.jboss.spring.getting.started.domain;
+      <example>
+        <title>Interface for the User DAO</title>
 
+        <para><programlisting>package org.jboss.spring.getting.started.domain;
+
 public interface UserDao {
   User getForUsername(String username);
-}</programlisting>
+}</programlisting></para>
+      </example>
 
       <para>We encourage using plain JPA for the implementation. The class is
       annotated with @Service, which means that it can be used by Spring to
@@ -286,7 +334,11 @@
       isn't started yet (this may change with other configuration options, as
       Spring supports different transaction propagation modes).</para>
 
-      <programlisting>@Service
+      <example>
+        <title></title>
+
+        <para><programlisting>
+ at Service
 public class UserDaoImpl implements UserDao {
 
   @Autowired
@@ -298,13 +350,17 @@
    query.setParameter(1, username);
    return (User)query.getSingleResult();
   }
-}</programlisting>
+}</programlisting></para>
+      </example>
 
       <para>In the web tier, we will need a controller and a web page for
       displaying the results. So we will create the UserController class
       first.</para>
 
-      <programlisting>@Controller
+      <example>
+        <title></title>
+
+        <para><programlisting>@Controller
 @RequestMapping("say-hello")
 public class UserController {
 
@@ -321,9 +377,10 @@
  public @ModelAttribute("message") String getGreeting(@RequestParam("username") String username)
  {
    User user = userDao.getForUsername(username);
-   return "Hello, " + user.getFirstName() + " " + user.getLastName() + "!"q;
+   return "Hello, " + user.getFirstName() + " " + user.getLastName() + "!";
  }
-}</programlisting>
+}</programlisting></para>
+      </example>
 
       <para>The @Controller annotation is similar to @Service, but targeted
       for MVC controller components. It instructs Spring to create a
@@ -356,7 +413,10 @@
       display a welcome message with the full name of the user. So, create a
       new JSP page as /src/main/webapp/WEB-INF/views/say-hello.jsp.</para>
 
-      <programlisting>&lt;%@ page language="java" contentType="text/html; charset=UTF-8"
+      <example>
+        <title></title>
+
+        <para><programlisting>&lt;%@ page language="java" contentType="text/html; charset=UTF-8"
     pageEncoding="UTF-8"%&gt;
 &lt;%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %&gt;
 &lt;!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"&gt;
@@ -374,10 +434,35 @@
 &lt;/form&gt;
 
 &lt;/body&gt;
-&lt;/html&gt;</programlisting>
+&lt;/html&gt;</programlisting></para>
+      </example>
     </section>
 
     <section>
+      <title>Persistence Setup</title>
+
+      <para>Setting up persistence for the example requires creating a
+      database initialization script and creating a persistence unit.</para>
+
+      <para>For creating a database initialization script, add a new file
+      named init-db.sql underneath src/main/resources/.</para>
+
+      <example>
+        <title></title>
+
+        <para><programlisting></programlisting>As well, we need to create a
+        persistence unit definition file. Create the persistence.xml file
+        underneath src/main/resources/META-INF.</para>
+      </example>
+
+      <example>
+        <title></title>
+
+        <para><programlisting></programlisting></para>
+      </example>
+    </section>
+
+    <section>
       <title>Adding the Spring configuration files</title>
 
       <para>A Spring MVC application is using the Front Controller pattern
@@ -435,10 +520,10 @@
       having access to its bean definitions).</para>
 
       <para>From src/main/webapp/WEB-INF, create a Spring bean definition
-      file, by selecting New-&gt;Spring Bean Definition File and enter a file
-      name of 'spring-business-context.xml'. Make sure that you follow the
-      'Next' option and select the following namespaces: bean, context, jbdc,
-      jee and tx. The content of the file is as follows;</para>
+      file, by selecting New-&gt;Spring Bean Configuration File and enter a
+      file name of 'spring-business-context.xml'. Make sure that you follow
+      the 'Next' option and select the following namespaces: bean, context,
+      jbdc, jee and tx. The content of the file is as follows;</para>
 
       <programlisting>&lt;beans xmlns="http://www.springframework.org/schema/beans"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
@@ -513,8 +598,41 @@
       is executed, the InternalResourceViewResolver will determine a jsp page
       that DispatcherServlet will forward the request for rendering the
       response.</para>
+    </section>
 
-      <para></para>
+    <section>
+      <title>Running the example</title>
+
+      <para>Finally, you need to run the example. You can do this either from
+      the command line or from JBDS. Here is what you need to do in each
+      case.</para>
+
+      <simplesect>
+        <title>Running the example from command line</title>
+
+        <para>You need to build the example with Maven. Afterwards you can
+        deploy it by copying it into
+        $EAP_HOME/jboss-as/server/&lt;profile&gt;/deploy.</para>
+
+        <example>
+          <title>Building and deploying example from the command line</title>
+
+          <programlisting>cd $EXAMPLE_HOME; 
+mvn clean package
+cp target/getting-started.war $EAP_HOME/jboss-as/server/&lt;profile&gt;/deploy
+</programlisting>
+        </example>
+      </simplesect>
+
+      <simplesect>
+        <title>Running the example from JBDS</title>
+
+        <para>You can also run the example from JBDS directly. In order to do
+        so open the contextual menu for the project (i.e. click right on the
+        project in the projects list), then 'Run As'-&gt;'Run on Server',
+        choose a JBoss EAP 5.1 instance and click Finish. If you don't find a
+        JBoss EAP instance, please refer to Appendix B for details.</para>
+      </simplesect>
     </section>
   </section>
 

Modified: projects/docs/enterprise/WFK/Spring_Developer_Guide/en-US/Spring_Developer_Guide.xml
===================================================================
--- projects/docs/enterprise/WFK/Spring_Developer_Guide/en-US/Spring_Developer_Guide.xml	2011-03-22 12:55:10 UTC (rev 110994)
+++ projects/docs/enterprise/WFK/Spring_Developer_Guide/en-US/Spring_Developer_Guide.xml	2011-03-22 13:17:50 UTC (rev 110995)
@@ -9,6 +9,8 @@
   <xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="Getting_Started_Introductory_Example.xml"/>
   <xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="Spring_On_JBoss_Best_Practices.xml"/>
   <xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="Migration_Guide.xml"/>
+  <xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="Appendix_A.xml"/>
+  <xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="Appendix_B.xml"/>
   <xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="Revision_History.xml"/>
   <!-- <index/> -->
 </book>

Modified: projects/docs/enterprise/WFK/Spring_Developer_Guide/en-US/Spring_On_JBoss_Best_Practices.xml
===================================================================
--- projects/docs/enterprise/WFK/Spring_Developer_Guide/en-US/Spring_On_JBoss_Best_Practices.xml	2011-03-22 12:55:10 UTC (rev 110994)
+++ projects/docs/enterprise/WFK/Spring_Developer_Guide/en-US/Spring_On_JBoss_Best_Practices.xml	2011-03-22 13:17:50 UTC (rev 110995)
@@ -57,10 +57,10 @@
 
       <para>The definition for such a datasource would be included in a file
       whose name ends in -ds.xml (e.g. sportsclub-ds.xml) and can either
-      copied in the deploy directory of the target JBoss AS configuration,
-      case in which it will be deployed at startup, or it can be included in
-      the META-INF directory of the application, case in which the managed
-      datasource will be created after deployment.</para>
+      copied in the deploy directory of the target JBoss AS configuration for
+      deployment at startup, or it can be included in the META-INF directory
+      of the application for being deployed together with the
+      application.</para>
 
       <example>
         <title>Managed datasource configuration</title>
@@ -83,9 +83,11 @@
       <example>
         <title>Defining a managed datasource Spring bean</title>
 
-        <para>&lt;jee:jndi-lookup id="dataSource"
-        jndi-name="java:/ExampleDsJndiName"/&gt;</para>
+        <programlisting>&lt;jee:jndi-lookup id="dataSource" jndi-name="java:/ExampleDsJndiName"/&gt;</programlisting>
       </example>
+
+      <para>Such a datasource bean can be injected in any regular Spring bean
+      (e.g. a JBDS DAO).</para>
     </section>
 
     <section>
@@ -189,7 +191,7 @@
   @Autowired EntityManager entityManager;
 
   public List&lt;Account&gt; getAllAccounts() {
-     return return entityManager.createQuery("SELECT a FROM Account").getResultList();;
+     return entityManager.createQuery("SELECT a FROM Account").getResultList();
   }
   ...
 }</programlisting></para>
@@ -212,7 +214,7 @@
       enrolled in the same transaction), it is not typical to access
       EntityManagerFactories directly. Rather, components should access the
       JNDI-bound EntityManager, as it is JTA-synchronized and will be shared
-      with non-Spring components that use JPA as well (e.g. EJBs). </para>
+      with non-Spring components that use JPA as well (e.g. EJBs).</para>
 
       <para>One important limitation of working with JNDI-bound EntityManagers
       and EntityManagerFactories is the lack of support for read-only
@@ -224,7 +226,7 @@
 
         <programlisting>@Transaction(readOnly = true)
 public List&lt;Account&gt; getAllAccounts() {
-     return return entityManager.createQuery("SELECT a FROM Account").getResultList();;
+     return entityManager.createQuery("SELECT a FROM Account").getResultList();
   }</programlisting>
       </example>
 
@@ -265,28 +267,116 @@
                 &lt;/prop&gt;
             &lt;/props&gt;
         &lt;/property&gt;
-    &lt;/bean&gt;</programlisting>The above definition relies upon a
-        META-INF/persistence.xml file being provided in the deployment.
-        However, in such a case it may be worth considering whether it is
-        necessary to have a container-deployed persistence unit as well, since
-        the Spring application will not use it. If that is not the case, you
-        can use another location as shown here:e</para>
+    &lt;/bean&gt;</programlisting></para>
 
-        <para>When doing so, it is worth considering whether the application
-        still needs JBoss to deploy a persistence unit. If not, the
-        persistence unit definition file can be placed in an alternative
-        location, and the Spring bean definition can be changed as in the
-        following example. </para>
+        <para>The above definition relies upon a META-INF/persistence.xml file
+        being provided in the deployment. However, in such a case it may be
+        worth considering whether it is necessary to have a container-deployed
+        persistence unit as well, since the Spring application will not use
+        it. If that is not the case, you can use another location as shown in
+        example <xref linkend="alt-location" />.</para>
       </example>
 
       <example>
-        <title>Using an alternative location for persistence.xml </title>
+        <title>Using an alternative location for persistence.xml</title>
 
-        <para><programlisting>&lt;bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"&gt;
-        &lt;property name="persistenceXmlLocation" value="classpath*:META-INF/persistence-booking.xml"/&gt;
-&lt;!-- other properties (ommitted) --&gt;
-    &lt;/bean&gt;</programlisting></para>
+        <para><programlisting lang="XML" language="XML">&lt;bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"&gt;
+   &lt;property name="persistenceXmlLocation" value="classpath*:META-INF/persistence-booking.xml"/&gt;
+   &lt;!-- other properties (ommitted) --&gt;
+&lt;/bean&gt;</programlisting></para>
       </example>
+
+      <para>When using the LocalContainerManagedEntityFactoryBean in JBoss,
+      the WEB-INF/classes location will not be scanned for persistent
+      entities, even if the persistence unit definition file is located in
+      WEB-INF/classes/META-INF. This happens irrespective of whether the file
+      is named persistence.xml or otherwise. In such cases, the list of
+      entities must be provided explicitely through one of the following
+      methods:</para>
+
+      <itemizedlist>
+        <listitem>
+          <para>By enumerating the persistent classes in persistence.xml (or
+          however the persistence unit configuration file is named);</para>
+        </listitem>
+
+        <listitem>
+          <para>By packaging the entities in a jar file and provide a
+          &lt;jar-file/&gt; configuration entry in persistence.xml;</para>
+        </listitem>
+
+        <listitem>
+          <para>Using a PersistenceUnitPostprocessor;</para>
+        </listitem>
+      </itemizedlist>
+
+      <para>The first two solutions are based on the standard functionality of
+      JPA. The third solution, however, is Spring-specific and involves
+      implementing a PersistenceUnitPostprocessor class that will add the
+      persistent classes directly to the PersistenceUnitInfo object, as in the
+      following example.</para>
+
+      <example>
+        <title>Example of a PersistenceUnitPostProcessor implementation that
+        adds all classes annotated with @Entity</title>
+
+        <programlisting>package org.springframework.webflow.samples.booking;
+
+import java.io.IOException;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.core.io.Resource;
+import org.springframework.core.io.support.ResourcePatternResolver;
+import org.springframework.core.type.classreading.CachingMetadataReaderFactory;
+import org.springframework.core.type.classreading.MetadataReader;
+import org.springframework.orm.jpa.persistenceunit.MutablePersistenceUnitInfo;
+import org.springframework.orm.jpa.persistenceunit.PersistenceUnitPostProcessor;
+
+public class MyPersistenceUnitPostProcessor implements PersistenceUnitPostProcessor
+{
+
+   @Autowired
+   private ResourcePatternResolver resourceLoader;
+
+   public void postProcessPersistenceUnitInfo(MutablePersistenceUnitInfo mutablePersistenceUnitInfo)
+   {
+      try
+      {
+         Resource[] resources = resourceLoader.getResources("classpath:org/myexample/*.class");
+         for (Resource resource : resources)
+         {
+            CachingMetadataReaderFactory cachingMetadataReaderFactory = new CachingMetadataReaderFactory();
+            MetadataReader metadataReader = cachingMetadataReaderFactory.getMetadataReader(resource);
+            if (metadataReader.getAnnotationMetadata().isAnnotated(javax.persistence.Entity.class.getName()))
+            {
+               mutablePersistenceUnitInfo.addManagedClassName(metadataReader.getClassMetadata().getClassName());
+            }
+         }
+         mutablePersistenceUnitInfo.setExcludeUnlistedClasses(true);
+      }
+      catch (IOException e)
+      {
+         throw new RuntimeException(e);
+      }
+   }
+}
+</programlisting>
+
+        <para>A bean of this class can be injected in the
+        LocalContainerEntityManagerFactoryBean as follows:<example>
+            <title>Adding the PersistenceUnitPostProcessor to the context
+            definition</title>
+
+            <para><programlisting>&lt;bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"&gt;
+&lt;!-- other properties --&gt;
+  &lt;property name="persistenceUnitPostProcessors"&gt;
+    &lt;list&gt;
+      &lt;bean class="org.springframework.webflow.samples.booking.MyPersistenceUnitPostProcessor"/&gt;
+    &lt;/list&gt;
+  &lt;/property&gt;
+&lt;/bean&gt;</programlisting></para>
+          </example></para>
+      </example>
     </section>
   </section>
 
@@ -347,15 +437,12 @@
         <programlisting>
 public class MessageDrivenPojo
 {
-   @Autowire PaymentProcessor paymentProcessor;
+  @Autowire PaymentProcessor paymentProcessor;
 
-
-   public void pojoHandlerMethod(PaymentNotification paymentNotification)
-   {
-      paymentProcessor.processPayment(paymentNotification.getAccountNumber(), paymentNotification.getAmount());
-
-   }
-
+  public void pojoHandlerMethod(PaymentNotification paymentNotification)
+  {
+    paymentProcessor.processPayment(paymentNotification.getAccountNumber(), paymentNotification.getAmount());
+  }
 }
 </programlisting>
       </example></para>



More information about the jboss-cvs-commits mailing list