include::../shared-doc/attributes.adoc[]

= spring-greeter: Greeter Example using Spring 4.x
:author: Marius Bogoevici
:level: Beginner
:technologies: Spring MVC, JSP, JPA

[abstract]
The `spring-greeter` quickstart is based on the `greeter` quickstart, but differs in that it uses Spring MVC for Mapping `GET` and `POST` requests.

:standalone-server-type: default
:archiveType: war

//*************************************************
// Shared CD and Product Release content
//*************************************************

== What is it?

The application this project produces is designed to be run on {productNameFull} {productVersion} or later.

The `spring-greeter` quickstart is based on the `greeter` quickstart, but differs in that it uses Spring MVC for Mapping `GET` and `POST` requests:

* The `mvc:annotation-driven` element configured in the `src/main/webapp/WEB-INF/spring-mvc-context.xml` file tells Spring to look for `@RequestMapping` in the controllers.
* Spring then routes the HTTP requests to the correct methods in `CreateController.java` and `GreetController`

Spring's XML configurations are used to get hold of the database and entity manager (via jndi) to perform transactional operations:

* The `tx:jta-transaction-manager` and `tx:annotation-driven` elements are configured in the `/src/main/webapp/WEB-INF/spring-business-context.xml` file.
* Methods in UserDaoImpl are marked as `@Transactional`, which Spring, using aspect oriented programming, surrounds with
boilerplate code to make the methods transactional

When you deploy this example, two users are automatically created for you: emuster and jdoe. This data is located in the
`src/main/resources/init-db.sql` file.

To test this example:

. Enter a name in the username field and click on *Greet!*.
. If you enter a username that is not in the database, you get a message `No such user exists!``.
. If you enter a valid username, you get a message "Hello, " followed by the user's first and last name.
. To create a new user, click the *Add a new user* link. Enter the *username*, *first name*, and *last name*, and then click *Add User*.
The user is added and a message displays the new user ID number.
. Click on the *Greet a user!* link to return to the *Greet!* page.

//*************************************************
// Product Release content only
//*************************************************

ifndef::EAPCDRelease[]

// System Requirements
include::../shared-doc/system-requirements.adoc[leveloffset=+1]
// Use of {jbossHomeName}
include::../shared-doc/use-of-jboss-home-name.adoc[leveloffset=+1]
// Start the {productName} Standalone Server
include::../shared-doc/start-the-standalone-server.adoc[leveloffset=+1]
// Build and Deploy the Quickstart
include::../shared-doc/build-and-deploy-the-quickstart.adoc[leveloffset=+1]

// Additional deployment information
If you do not have Maven configured you can manually copy `target/spring-greeter.war` to `__{jbossHomeName}__/standalone/deployments/` directory.

== Access the application

The application will be running at the following URL: http://localhost:8080/{artifactId}/

== Server Log: Expected Warnings and Errors

You will see the following warnings in the server log. You can ignore these warnings.

[source,options="nowrap"]
----
WARN  [org.jboss.as.ee] (MSC service thread 1-5) WFLYEE0007: Not installing optional component org.springframework.http.server.ServletServerHttpAsyncRequestControl due to an exception (enable DEBUG log level to see the cause)
WARN  [org.jboss.as.ee] (MSC service thread 1-5) WFLYEE0007: Not installing optional component org.springframework.web.context.request.async.StandardServletAsyncWebRequest due to an exception (enable DEBUG log level to see the cause)
----

// Undeploy the Quickstart
include::../shared-doc/undeploy-the-quickstart.adoc[leveloffset=+1]

// Additional undeploy information.
Or you can manually remove the application by removing `{artifactId}.war` from the `__{jbossHomeName}__/standalone/deployments/` directory.

// Run the Arquillian Functional Tests
include::../shared-doc/run-arquillian-functional-tests.adoc[leveloffset=+1]
// Run the Quickstart in Red Hat Developer Studio or Eclipse
include::../shared-doc/run-the-quickstart-in-jboss-developer-studio.adoc[leveloffset=+1]

== Debug the Application

If you want to debug the source code or look at the Javadocs of any library in the project, run either of the following commands to pull them into your local repository. The IDE should then detect them.
+
[source,options="nowrap"]
----
$ mvn dependency:sources
$ mvn dependency:resolve -Dclassifier=javadoc
----

endif::[]

//*************************************************
// CD Release content only
//*************************************************

ifdef::EAPCDRelease[]

// Getting Started with OpenShift
include::../shared-doc/cd-openshift-getting-started.adoc[leveloffset=+1]
//Prepare OpenShift for Quickstart Deployment
include::../shared-doc/cd-create-project.adoc[leveloffset=+1]
// Import the Latest {xpaasproduct-shortname} Image Streams and Templates
include::../shared-doc/cd-import-imagestreams-templates.adoc[leveloffset=+1]
// Deploy the {ProductShortName} Source-to-Image (S2I) Quickstart to OpenShift
include::../shared-doc/cd-deploy-project.adoc[leveloffset=+1]
// OpenShift Post Deployment Tasks: This is not currently needed.
// include::../shared-doc/cd-post-deployment-tasks.adoc[leveloffset=+1]

endif::[]
