= spring-greeter: Greeter Example using Spring 4.x
:author: Marius Bogoevici
:productName: WildFly
:productNameFull: WildFly Application Server
:jbossHomeName: WILDFLY_HOME
:productVersion: 12
:buildRequirements: Java 8.0 (Java SDK 1.8) or later and Maven 3.3.1 or later
include::../shared-doc/attributes.adoc[]

:level: Beginner
:technologies: Spring MVC, JSP, JPA
:source: {githubRepoUrl}

[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

== 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.

//*************************************************
// Add System Requirements
//*************************************************
// == System Requirements
include::../shared-doc/system-requirements.adoc[leveloffset=+1]

//*************************************************
// Add Use of JBoss Home Name
//*************************************************
// == Use of {jbossHomeName}
include::../shared-doc/use-of-jboss-home-name.adoc[leveloffset=+1]

//*************************************************
// Start the server with the default profile
//*************************************************
// == Start the {productName} Standalone Server
include::../shared-doc/start-the-standalone-server.adoc[leveloffset=+1]

//*************************************************
// Build and deploy the quickstart WAR
//*************************************************
// == 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}/

//*************************************************
// Undeploy the quickstart archive
//*************************************************
// == 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
//*************************************************
// == Run the Arquillian Functional Tests
include::../shared-doc/run-arquillian-functional-tests.adoc[leveloffset=+1]

//*************************************************
// Add JBoss Developer Studio instructions
//*************************************************
// == Run the Quickstart in Red Hat JBoss Developer Studio or Eclipse
include::../shared-doc/run-the-quickstart-in-jboss-developer-studio.adoc[leveloffset=+1]

//*************************************************
// Deploy the quickstart to OpenShift
//*************************************************
// == Deploy the Quickstart to OpenShift Online
include::../shared-doc/deploy-to-openshift-online.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
----
