[jboss-cvs] JBossAS SVN: r111004 - 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 19:47:21 EDT 2011
Author: marius.bogoevici
Date: 2011-03-22 19:47:21 -0400 (Tue, 22 Mar 2011)
New Revision: 111004
Modified:
projects/docs/enterprise/WFK/Spring_Developer_Guide/en-US/Appendix_A.xml
projects/docs/enterprise/WFK/Spring_Developer_Guide/en-US/Getting_Started_Introductory_Example.xml
projects/docs/enterprise/WFK/Spring_Developer_Guide/en-US/Spring_On_JBoss_Best_Practices.xml
Log:
Cleanup
Modified: projects/docs/enterprise/WFK/Spring_Developer_Guide/en-US/Appendix_A.xml
===================================================================
--- projects/docs/enterprise/WFK/Spring_Developer_Guide/en-US/Appendix_A.xml 2011-03-22 22:56:14 UTC (rev 111003)
+++ projects/docs/enterprise/WFK/Spring_Developer_Guide/en-US/Appendix_A.xml 2011-03-22 23:47:21 UTC (rev 111004)
@@ -5,101 +5,124 @@
%BOOK_ENTITIES;
]>
<appendix>
- <title id="appendix_maven_deps">Maven dependencies for the introductory
- example</title>
+ <title id="appendix_maven_deps">POM.xml for the introductory example</title>
<section>
- <para>In order to </para>
+ <para>In order to</para>
- <programlisting> <dependencies>
- <dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- <version>4.7</version>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.hibernate</groupId>
- <artifactId>hibernate-core</artifactId>
- <version>3.3.0.GA</version>
- <scope>provided</scope>
- </dependency>
- <dependency>
- <groupId>org.hibernate</groupId>
- <artifactId>hibernate-entitymanager</artifactId>
- <version>3.4.0.GA</version>
- <scope>provided</scope>
- </dependency>
- <dependency>
- <groupId>taglibs</groupId>
- <artifactId>standard</artifactId>
- <version>1.1.2</version>
- </dependency>
- <dependency>
- <groupId>commons-logging</groupId>
- <artifactId>commons-logging</artifactId>
- <version>1.1.1</version>
- </dependency>
- <dependency>
- <groupId>aopalliance</groupId>
- <artifactId>aopalliance</artifactId>
- <version>1.0</version>
- </dependency>
- <dependency>
- <groupId>org.springframework</groupId>
- <artifactId>spring-asm</artifactId>
- <version>3.0.5.RELEASE</version>
- </dependency>
- <dependency>
- <groupId>org.springframework</groupId>
- <artifactId>spring-aop</artifactId>
- <version>3.0.5.RELEASE</version>
- </dependency>
- <dependency>
- <groupId>org.springframework</groupId>
- <artifactId>spring-expression</artifactId>
- <version>3.0.5.RELEASE</version>
- </dependency>
- <dependency>
- <groupId>org.springframework</groupId>
- <artifactId>spring-beans</artifactId>
- <version>3.0.5.RELEASE</version>
- </dependency>
- <dependency>
- <groupId>org.springframework</groupId>
- <artifactId>spring-context</artifactId>
- <version>3.0.5.RELEASE</version>
- </dependency>
- <dependency>
- <groupId>org.springframework</groupId>
- <artifactId>spring-context-support</artifactId>
- <version>3.0.5.RELEASE</version>
- </dependency>
- <dependency>
- <groupId>org.springframework</groupId>
- <artifactId>spring-tx</artifactId>
- <version>3.0.5.RELEASE</version>
- </dependency>
- <dependency>
- <groupId>org.springframework</groupId>
- <artifactId>spring-core</artifactId>
- <version>3.0.5.RELEASE</version>
- </dependency>
- <dependency>
- <groupId>org.springframework</groupId>
- <artifactId>spring-jdbc</artifactId>
- <version>3.0.5.RELEASE</version>
- </dependency>
- <dependency>
- <groupId>org.springframework</groupId>
- <artifactId>spring-web</artifactId>
- <version>3.0.5.RELEASE</version>
- </dependency>
- <dependency>
- <groupId>org.springframework</groupId>
- <artifactId>spring-webmvc</artifactId>
- <version>3.0.5.RELEASE</version>
- </dependency>
- </dependencies></programlisting>
+ <programlisting><project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>org.jboss.snowdrop.getting.started</groupId>
+ <artifactId>getting-started</artifactId>
+ <packaging>war</packaging>
+ <version>1.0</version>
+ <name>getting-started Maven Webapp</name>
+ <url>http://maven.apache.org</url>
+ <dependencies>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>4.7</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.hibernate</groupId>
+ <artifactId>hibernate-core</artifactId>
+ <version>3.3.0.GA</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.hibernate</groupId>
+ <artifactId>hibernate-entitymanager</artifactId>
+ <version>3.4.0.GA</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>taglibs</groupId>
+ <artifactId>standard</artifactId>
+ <version>1.1.2</version>
+ </dependency>
+ <dependency>
+ <groupId>commons-logging</groupId>
+ <artifactId>commons-logging</artifactId>
+ <version>1.1.1</version>
+ </dependency>
+ <dependency>
+ <groupId>aopalliance</groupId>
+ <artifactId>aopalliance</artifactId>
+ <version>1.0</version>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-asm</artifactId>
+ <version>3.0.5.RELEASE</version>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-aop</artifactId>
+ <version>3.0.5.RELEASE</version>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-expression</artifactId>
+ <version>3.0.5.RELEASE</version>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-beans</artifactId>
+ <version>3.0.5.RELEASE</version>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-context</artifactId>
+ <version>3.0.5.RELEASE</version>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-context-support</artifactId>
+ <version>3.0.5.RELEASE</version>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-tx</artifactId>
+ <version>3.0.5.RELEASE</version>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-beans</artifactId>
+ <version>3.0.5.RELEASE</version>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-core</artifactId>
+ <version>3.0.5.RELEASE</version>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-jdbc</artifactId>
+ <version>3.0.5.RELEASE</version>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-web</artifactId>
+ <version>3.0.5.RELEASE</version>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-orm</artifactId>
+ <version>3.0.5.RELEASE</version>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-webmvc</artifactId>
+ <version>3.0.5.RELEASE</version>
+ </dependency>
+ </dependencies>
+ <build>
+ <finalName>getting-started</finalName>
+ </build>
+</project>
+</programlisting>
</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 22:56:14 UTC (rev 111003)
+++ projects/docs/enterprise/WFK/Spring_Developer_Guide/en-US/Getting_Started_Introductory_Example.xml 2011-03-22 23:47:21 UTC (rev 111004)
@@ -40,21 +40,14 @@
<section>
<title>Assumptions and placeholder names</title>
- <para>During this tutorial, we are going to assume that:</para>
+ <para>During this tutorial, we are going to assume that the location of
+ JBoss Enterprise Application is $EAP_HOME, which represents the
+ top-level directory of the extracted distribution (usually
+ <emphasis>jboss-eap-5.1</emphasis>).</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 <profile> to indicate the JBoss
- AS profile with which the application is launched (usually
- default);</para>
- </listitem>
- </itemizedlist>
+ <para>We use the placeholder <profile> to indicate the JBoss AS
+ profile with which the application is launched (usually
+ <emphasis>default</emphasis>).</para>
</section>
</section>
@@ -70,17 +63,17 @@
<itemizedlist>
<listitem>
<para>The general project structure of a Spring-based web
- application</para>
+ application;</para>
</listitem>
<listitem>
<para>A simple set of domain classes, MVC controllers and web
- pages</para>
+ pages;</para>
</listitem>
<listitem>
<para>The data infrastructure configuration (including database, JPA
- and transactions) for running Spring applications in JBoss</para>
+ and transactions) for running Spring applications in JBoss.</para>
</listitem>
</itemizedlist>
</section>
@@ -180,7 +173,7 @@
</row>
<row>
- <entry>Spring Modules</entry>
+ <entry>Spring modules</entry>
<entrytbl cols="1">
<tbody>
@@ -234,11 +227,15 @@
</tgroup>
</table></para>
- <para>Appendin</para>
+ <para>You can add these dependencies using the Dependencies tab of the
+ POM editor, or copy them directly to the pom.xml file. An example of the
+ POM file, including the list of dependencies can be found in Appendix
+ A.</para>
- <para>The artifact may not create the Java source folder, so you may
- have to add it yourself. Go to 'New'->Source Folder and enter a value
- of 'src/main/java', and then 'Finish'.</para>
+ <para>When creating the project, the Java source folder may not be added
+ automatically, case in which you have to add it yourself. Go to
+ 'New'->Source Folder and enter a value of 'src/main/java', and then
+ click '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
@@ -262,7 +259,7 @@
<example>
<title>Domain entity definition</title>
- <para><programlisting>package org.jboss.spring.getting.started.domain;
+ <para><programlisting language="java">package org.jboss.spring.getting.started.domain;
import javax.persistence.Column;
import javax.persistence.Entity;
@@ -310,12 +307,13 @@
</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>
+ be installed as a Spring bean. The interface for this component
+ is:</para>
<example>
<title>Interface for the User DAO</title>
- <para><programlisting>package org.jboss.spring.getting.started.domain;
+ <para><programlisting language="java">package org.jboss.spring.getting.started.domain;
public interface UserDao {
User getForUsername(String username);
@@ -335,22 +333,33 @@
Spring supports different transaction propagation modes).</para>
<example>
- <title></title>
+ <title>UserDao implementation</title>
- <para><programlisting>
+ <para><programlisting language="java">package org.jboss.spring.getting.started.domain;
+
+import javax.persistence.EntityManager;
+import javax.persistence.PersistenceContext;
+import javax.persistence.Query;
+
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+
@Service
public class UserDaoImpl implements UserDao {
- @Autowired
- private EntityManager entityManager;
+ @PersistenceContext
+ private EntityManager entityManager;
- @Transactional
- public User getForUsername(String username) {
- Query query = entityManager.createQuery("select u from User u where u.username = ?");
- query.setParameter(1, username);
- return (User)query.getSingleResult();
- }
-}</programlisting></para>
+ @Transactional
+ public User getForUsername(String username) {
+ Query query = entityManager
+ .createQuery("select u from User u where u.username = ?");
+ query.setParameter(1, username);
+ return (User) query.getSingleResult();
+ }
+
+}
+</programlisting></para>
</example>
<para>In the web tier, we will need a controller and a web page for
@@ -358,27 +367,38 @@
first.</para>
<example>
- <title></title>
+ <title>The MVC Controller class</title>
- <para><programlisting>@Controller
+ <para><programlisting language="java">package org.jboss.spring.getting.started.mvc;
+
+import org.jboss.spring.getting.started.domain.User;
+import org.jboss.spring.getting.started.domain.UserDao;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Controller;
+import org.springframework.web.bind.annotation.ModelAttribute;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
+import org.springframework.web.bind.annotation.RequestParam;
+
+ at Controller
@RequestMapping("say-hello")
public class UserController {
- @Autowired
- private UserDao userDao;
-
- @RequestMapping(method = RequestMethod.GET)
- public @ModelAttribute("message") String getInitialMessage()
- {
- return "Enter a Valid Name";
- }
-
- @RequestMapping(method = RequestMethod.POST)
- public @ModelAttribute("message") String getGreeting(@RequestParam("username") String username)
- {
- User user = userDao.getForUsername(username);
- return "Hello, " + user.getFirstName() + " " + user.getLastName() + "!";
- }
+ @Autowired
+ private UserDao userDao;
+
+ @RequestMapping(method = RequestMethod.GET)
+ public @ModelAttribute("message")
+ String getInitialMessage() {
+ return "Enter a Valid Name";
+ }
+
+ @RequestMapping(method = RequestMethod.POST)
+ public @ModelAttribute("message")
+ String getGreeting(@RequestParam("username") String username) {
+ User user = userDao.getForUsername(username);
+ return "Hello, " + user.getFirstName() + " " + user.getLastName() + "!";
+ }
}</programlisting></para>
</example>
@@ -414,11 +434,11 @@
new JSP page as /src/main/webapp/WEB-INF/views/say-hello.jsp.</para>
<example>
- <title></title>
+ <title>The Web page that renders the results</title>
- <para><programlisting><%@ page language="java" contentType="text/html; charset=UTF-8"
+ <para><programlisting language="jsp"><%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
-<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %>
+<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
@@ -426,11 +446,10 @@
<title>Hello</title>
</head>
<body>
-<form method="post" action="say-hello">
-Enter username: <input type="text" name="username" value="<c:out value="${username}"/>">
-<c:out value="${message}"/>
-<p>
-<input type="submit" value="Submit">
+<form method="post" action="say-hello">Enter username: <input
+ type="text" name="username" value="<c:out value="${username}"/>">
+<c:out value="${message}" />
+<p><input type="submit" value="Submit">
</form>
</body>
@@ -445,20 +464,37 @@
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>
+ named init-db.sql underneath src/main/resources.</para>
<example>
- <title></title>
+ <title>The database initialization script</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>
+ <para><programlisting language="sql">DROP TABLE USERS IF EXISTS CASCADE;
+CREATE TABLE USERS (
+ ID BIGINT GENERATED BY DEFAULT AS IDENTITY(START WITH 1) NOT NULL PRIMARY KEY,
+ USERNAME VARCHAR(255),
+ FIRSTNAME VARCHAR(255),
+ LASTNAME VARCHAR(255));
+
+INSERT INTO USERS (ID, USERNAME, FIRSTNAME, LASTNAME) VALUES (1, 'jdoe', 'John', 'Doe');
+INSERT INTO USERS (ID, USERNAME, FIRSTNAME, LASTNAME) VALUES (2, 'emuster', 'Erika', 'Mustermann');
+</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>
+ <title>The persistence unit definition file</title>
- <para><programlisting></programlisting></para>
+ <para><programlisting language="xml"><persistence xmlns="http://java.sun.com/xml/ns/persistence" version="1.0">
+ <persistence-unit name="helloPU" transaction-type="JTA">
+ <jta-data-source>java:/DefaultDS</jta-data-source>
+ <properties>
+ <property name="jboss.entity.manager.jndi.name" value="java:/hello/EntityManager"/>
+ <property name="hibernate.show_sql" value="true"/>
+ </properties>
+ </persistence-unit>
+</persistence></programlisting></para>
</example>
</section>
@@ -486,7 +522,10 @@
<para>For configuring the web application, update the web.xml as
follows:</para>
- <programlisting><!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
+ <example>
+ <title>The web.xml definition</title>
+
+ <para><programlisting language="xml"><!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
<display-name>Getting Started with Spring</display-name>
@@ -512,7 +551,8 @@
</servlet-mapping>
</web-app>
-</programlisting>
+</programlisting></para>
+ </example>
<para>The ContextLoaderListener will boostrap an application context
containing the business components, while the DispatcherServlet will
@@ -525,34 +565,33 @@
the 'Next' option and select the following namespaces: bean, context,
jbdc, jee and tx. The content of the file is as follows;</para>
- <programlisting><beans xmlns="http://www.springframework.org/schema/beans"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xmlns:context="http://www.springframework.org/schema/context"
- xmlns:jee="http://www.springframework.org/schema/jee"
- xmlns:jdbc="http://www.springframework.org/schema/jdbc"
- xmlns:tx="http://www.springframework.org/schema/tx"
- xmlns:util="http://www.springframework.org/schema/util"
- xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
- http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
- http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee.xsd
- http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
- http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc.xsd
- http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd">
-
- <context:component-scan base-package="org.jboss.spring.getting.started.domain"/>
-
- <jee:jndi-lookup jndi-name="java:/DefaultDS" id="dataSource" expected-type="javax.sql.DataSource"/>
-
- <jee:jndi-lookup jndi-name="java:/hello/EntityManager" id="entityManager" expected-type="javax.persistence.EntityManager"/>
-
- <tx:jta-transaction-manager/>
-
- <tx:annotation-driven/>
-
- <jdbc:initialize-database data-source="dataSource">
- <jdbc:script location="classpath*:init-db.sql"/>
- </jdbc:initialize-database>
-
+ <programlisting lang="xml"><beans xmlns="http://www.springframework.org/schema/beans"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
+ xmlns:jee="http://www.springframework.org/schema/jee" xmlns:jdbc="http://www.springframework.org/schema/jdbc"
+ xmlns:tx="http://www.springframework.org/schema/tx" xmlns:util="http://www.springframework.org/schema/util"
+ xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
+ http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
+ http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee.xsd
+ http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
+ http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc.xsd
+ http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd">
+
+ <context:component-scan base-package="org.jboss.spring.getting.started.domain" />
+
+ <jee:jndi-lookup jndi-name="java:/DefaultDS" id="dataSource"
+ expected-type="javax.sql.DataSource" />
+
+ <jee:jndi-lookup jndi-name="java:/hello/EntityManager"
+ id="entityManager" expected-type="javax.persistence.EntityManager" />
+
+ <tx:jta-transaction-manager />
+
+ <tx:annotation-driven />
+
+ <jdbc:initialize-database data-source="dataSource">
+ <jdbc:script location="classpath*:init-db.sql" />
+ </jdbc:initialize-database>
+
</beans></programlisting>
<para>First, we instructed Spring to scan the package
@@ -573,24 +612,28 @@
context and mvc in the dialog. The configuration file is structured as
follows:</para>
- <programlisting><beans xmlns="http://www.springframework.org/schema/beans"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xmlns:context="http://www.springframework.org/schema/context"
- xmlns:mvc="http://www.springframework.org/schema/mvc"
- xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
- http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
- http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">
+ <example>
+ <title>Dispatcher servlet configuration file</title>
- <context:component-scan base-package="org.jboss.spring.getting.started.mvc"/>
-
- <mvc:annotation-driven/>
-
- <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
- <property name="prefix" value="/WEB-INF/views/"/>
- <property name="suffix" value=".jsp"></property>
- </bean>
+ <para><programlisting language="xml"><beans xmlns="http://www.springframework.org/schema/beans"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
+ xmlns:mvc="http://www.springframework.org/schema/mvc"
+ xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
+ http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
+ http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">
+
+ <context:component-scan base-package="org.jboss.spring.getting.started.mvc" />
+
+ <mvc:annotation-driven />
+
+ <bean
+ class="org.springframework.web.servlet.view.InternalResourceViewResolver">
+ <property name="prefix" value="/WEB-INF/views/" />
+ <property name="suffix" value=".jsp"></property>
+ </bean>
</beans>
-</programlisting>
+</programlisting></para>
+ </example>
<para>Using this context definition, Spring will scan for component
beans (such as the UserController), and will use the mappings defined by
@@ -633,6 +676,14 @@
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>
+
+ <simplesect>
+ <title>Accessing the running example</title>
+
+ <para>After deploying the example and starting JBoss EAP, the example
+ can be accessed at
+ <uri>http://localhost:8080/getting-started</uri>.</para>
+ </simplesect>
</section>
</section>
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 22:56:14 UTC (rev 111003)
+++ projects/docs/enterprise/WFK/Spring_Developer_Guide/en-US/Spring_On_JBoss_Best_Practices.xml 2011-03-22 23:47:21 UTC (rev 111004)
@@ -8,10 +8,9 @@
<title>Best practices and integration guidelines</title>
<para>The Spring Framework is a flexible environment for developing
- enterprise applications, with respect to the middleware integration.This
- means that the developer has the benefit of being able to choose between a
- number of alternatives when it comes to accessing middleware
- services.</para>
+ enterprise applications. .This means that the developer has the benefit of
+ being able to choose between a number of alternatives when it comes to
+ accessing middleware services.</para>
<para>JBoss is a feature-rich application server, that provides a complex
and performant set of middleware services. Spring developers can take
@@ -83,7 +82,7 @@
<example>
<title>Defining a managed datasource Spring bean</title>
- <programlisting><jee:jndi-lookup id="dataSource" jndi-name="java:/ExampleDsJndiName"/></programlisting>
+ <programlisting lang="xml"><jee:jndi-lookup id="dataSource" jndi-name="java:/ExampleDsJndiName"/></programlisting>
</example>
<para>Such a datasource bean can be injected in any regular Spring bean
@@ -105,7 +104,7 @@
<example>
<title>SessionFactory bean definition</title>
- <para><programlisting><bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
+ <para><programlisting lang="xml"><bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource" ref="dataSource"/>
...
</bean></programlisting></para>
@@ -117,7 +116,7 @@
<example>
<title>JTA session management setup properties</title>
- <programlisting>hibernate.current_session_context_class=jta
+ <programlisting language="xml">hibernate.current_session_context_class=jta
hibernate.transaction.manager_lookup_class=org.hibernate.transaction.JBossTransactionManagerLookup
hibernate.transaction.factory_class=org.hibernate.transaction.JTATransactionFactory</programlisting>
</example>
@@ -130,8 +129,7 @@
<title>Hibernate-based DAO: a SessionFactory is injected directly in
the bean</title>
- <para><programlisting>public class HibernateAccountDao
-{
+ <para><programlisting language="java">public class HibernateAccountDao {
@Autowired SessionFactory sessionFactory;
public List<Account> getAllAccounts() {
@@ -140,6 +138,10 @@
...
}</programlisting></para>
</example>
+
+ <para>A comprehensive example of using Hibernate-driven data access in
+ Spring-based applications can be found in the Sportsclub demo
+ application, included in the Web Framework Kit distribution.</para>
</section>
<section>
@@ -154,7 +156,7 @@
<example>
<title>Persistence unit definition</title>
- <programlisting><persistence xmlns="http://java.sun.com/xml/ns/persistence" version="1.0">
+ <programlisting language="xml"><persistence xmlns="http://java.sun.com/xml/ns/persistence" version="1.0">
<persistence-unit name="sportsclubPU">
<jta-data-source>java:/ExampleDsJndiName</jta-data-source>
<properties>
@@ -176,7 +178,7 @@
<title>Spring bean representing a container-managed entity
manager</title>
- <programlisting><jee:jndi-lookup id="entityManager" jndi-name="java:/example/em"/></programlisting>
+ <programlisting language="xml"><jee:jndi-lookup id="entityManager" jndi-name="java:/example/em"/></programlisting>
</example>
<para>Such an EntityManager can be used directly if injected in
@@ -186,8 +188,7 @@
<title>Hibernate-based DAO: a SessionFactory is injected directly in
the bean</title>
- <para><programlisting>public class HibernateAccountDao
-{
+ <para><programlisting language="xml">public class HibernateAccountDao {
@Autowired EntityManager entityManager;
public List<Account> getAllAccounts() {
@@ -206,7 +207,7 @@
<example>
<title>Spring bean representing an entity manager factory</title>
- <programlisting><jee:jndi-lookup id="entityManagerFactory" jndi-name="java:/example/emf"/></programlisting>
+ <programlisting language="xml"><jee:jndi-lookup id="entityManagerFactory" jndi-name="java:/example/emf"/></programlisting>
</example>
<para>In general, for implementing transaction-aware components (for
@@ -216,6 +217,10 @@
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>
+ <para>A comprehensive example of using JPA-driven data access in
+ Spring-based applications can be found in the Sportsclub demo
+ application, included in the Web Framework Kit distribution.</para>
+
<para>One important limitation of working with JNDI-bound EntityManagers
and EntityManagerFactories is the lack of support for read-only
transactions in Spring. When declaring transactions, Spring applications
@@ -226,8 +231,8 @@
<programlisting>@Transaction(readOnly = true)
public List<Account> getAllAccounts() {
- return entityManager.createQuery("SELECT a FROM Account").getResultList();
- }</programlisting>
+ return entityManager.createQuery("SELECT a FROM Account").getResultList();
+}</programlisting>
</example>
<para>A common misconception is that the readOnly flag will prevent the
@@ -256,18 +261,18 @@
<example>
<title>A Spring-defined JTA-based entity manager factory</title>
- <para><programlisting> <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
- <property name="jpaVendorAdapter">
- <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"/>
- </property>
- <property name="jpaProperties">
- <props>
- <prop key="hibernate.transaction.manager_lookup_class">
- org.hibernate.transaction.JBossTransactionManagerLookup
- </prop>
- </props>
- </property>
- </bean></programlisting></para>
+ <para><programlisting><bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
+ <property name="jpaVendorAdapter">
+ <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"/>
+ </property>
+ <property name="jpaProperties">
+ <props>
+ <prop key="hibernate.transaction.manager_lookup_class">
+ org.hibernate.transaction.JBossTransactionManagerLookup
+ </prop>
+ </props>
+ </property>
+</bean></programlisting></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
@@ -280,7 +285,7 @@
<example>
<title>Using an alternative location for persistence.xml</title>
- <para><programlisting lang="XML" language="XML"><bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
+ <para><programlisting lang="XML" language="xml"><bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="persistenceXmlLocation" value="classpath*:META-INF/persistence-booking.xml"/>
<!-- other properties (ommitted) -->
</bean></programlisting></para>
@@ -320,7 +325,7 @@
<title>Example of a PersistenceUnitPostProcessor implementation that
adds all classes annotated with @Entity</title>
- <programlisting>package org.springframework.webflow.samples.booking;
+ <programlisting language="java">package org.springframework.webflow.samples.booking;
import java.io.IOException;
@@ -367,7 +372,7 @@
<title>Adding the PersistenceUnitPostProcessor to the context
definition</title>
- <para><programlisting><bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
+ <para><programlisting language="xml"><bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<!-- other properties -->
<property name="persistenceUnitPostProcessors">
<list>
@@ -384,27 +389,52 @@
<title>Messaging (JMS) integration</title>
<para>Spring applications have two distinct mechanisms of integrating with
- JMS. One is by using the JmsTemplate which accessing the JMS API directly
- for both sending and receiving messages, and the other is by implementing
- message-driven POJOs. The best practice in JBoss is to use the JmsTemplate
- for sending messages but not for receiving them, as the
- message-driven/event-driven paradigm is a superior approach both as a
- programming style and performance-wise than polling/blocking via
+ JMS. One is by using the JmsTemplate which simplifies the usage of the JMS
+ API for both sending and receiving messages, and the other is by
+ implementing message-driven POJOs.</para>
+
+ <para>The best practice in JBoss is to use the JmsTemplate for sending
+ messages, but not for receiving them, as the message-driven/event-driven
+ paradigm is a superior approach both as a programming style and
+ performance-wise than polling/blocking via
JmsTemplate.receiveMessage().</para>
<para>Spring applications can implement message-driven POJOs by wiring
MessageListener beans (or POJOs via a MessageListenerAdapter) into a
- MessageListenerContainer. MessageListenerContainers come in two flavours:
+ MessageListenerContainer.</para>
+
+ <para>An typical of a message-driven POJO can be seen in example <xref
+ linkend="listing-message-driven-pojo" />.</para>
+
+ <example id="listing-message-driven-pojo">
+ <title>A message-driven POJO is a simple Java class</title>
+
+ <programlisting>
+public class MessageDrivenPojo
+{
+ @Autowire PaymentProcessor paymentProcessor;
+
+ public void pojoHandlerMethod(PaymentNotification paymentNotification)
+ {
+ paymentProcessor.processPayment(paymentNotification.getAccountNumber(), paymentNotification.getAmount());
+ }
+}
+</programlisting>
+ </example>
+
+ <para>Spring provides two dfferent types of MessageListenerContainers:
'native' JMS and JCA-based. On JBoss AS we recommend using the JCA
MessageListenerContainer, due to the better integration with the
- container. In order to minimize the amount of proprietary code, you can
- use Snowdrop's namespace support for JMS/JCA integration.</para>
+ container, in what concerns message delivery and session, connection, and
+ message consumer management. In order to minimize the amount of
+ proprietary code, you can use Snowdrop's namespace support for JMS/JCA
+ integration (see Snowdrop documentation for details).</para>
<example>
<title>Using the JCA message listener containers and namespace support
in JBoss</title>
- <para><programlisting> <jms:jca-listener-container resource-adapter="resourceAdapter" acknowledge="auto"
+ <para><programlisting language="xml"> <jms:jca-listener-container resource-adapter="resourceAdapter" acknowledge="auto"
activation-spec-factory="activationSpecFactory">
<jms:listener destination="/someDestination" ref="messageDrivenPojo"
method="pojoHandlerMethod"/>
@@ -426,36 +456,19 @@
converting message content to the expected argument type. For a JCA-based
container, the invocation will be automatically enrolled in a JTA
transaction.</para>
-
- <para>A message-driven POJO is provided in the following listing:</para>
-
- <para><example>
- <title>A message-driven POJO is a regular bean type</title>
-
- <para></para>
-
- <programlisting>
-public class MessageDrivenPojo
-{
- @Autowire PaymentProcessor paymentProcessor;
-
- public void pojoHandlerMethod(PaymentNotification paymentNotification)
- {
- paymentProcessor.processPayment(paymentNotification.getAccountNumber(), paymentNotification.getAmount());
- }
-}
-</programlisting>
- </example></para>
</section>
<section>
<title>Transaction management</title>
- <para>The recommended transaction management strategy for JBoss is by
- using JTA whose performance is close to native JDBC in single-resource
- scenarios and XA-capable in multiple-resource scenarios. One of the
- significant advantages of JTA is integration with other components of the
- application stack - such as EJBs and third-party components.</para>
+ <para>Transactions are central to data integrity, and using transactions
+ is critical for implementing a robust and reliable applications. The
+ Spring framework In addition to, the transaction manager included with
+ JBoss provides a performance close to native JDBC in single-resource
+ database access scenarios and being XA-capable in multiple-resource
+ scenarios (such as, for example mixing JMa. One of the significant
+ advantages of JTA is integration with other components of the application
+ stack - such as EJBs and third-party components.</para>
<para>Spring provides a declarative transaction model including
transaction propagation semantics, so that applications can declare
@@ -473,7 +486,7 @@
<example>
<title>JTA transaction manager definition in Spring</title>
- <programlisting><tx:jta-transaction-manager/></programlisting>
+ <programlisting lang="xml"><tx:jta-transaction-manager/></programlisting>
</example>
<para>The use of this transaction manager allows Spring to create JTA
@@ -489,33 +502,8 @@
</section>
<section>
- <title>Web Services integration (JAX-WS)</title>
+ <title>EJB integration</title>
- <para>Spring applications can create web services in a variety of way. In
- the simplest case, Spring applications can register JAX-WS web services
- out of the box, by simply defining an annotated class and registering it
- as a servlet.</para>
-
<para></para>
</section>
-
- <section>
- <title>EJB integration</title>
-
- <para>This needs content to build.</para>
- </section>
-
- <section>
- <title>Security integration</title>
-
- <para>This needs content to build</para>
-
- <para>This needs content to build</para>
- </section>
-
- <section>
- <title>This needs content to build</title>
-
- <para>This needs content to build.</para>
- </section>
</chapter>
More information about the jboss-cvs-commits
mailing list