Thespring-greeter
quickstart is based on thegreeter
quickstart, but differs in that it uses Spring MVC for MappingGET
andPOST
requests.
The application this project produces is designed to be run on WildFly Application Server 12 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 thesrc/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
andGreetController
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
andtx: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.
If you do not have Maven configured you can manually copy target/spring-greeter.war
to WILDFLY_HOME/standalone/deployments/
directory.
The application will be running at the following URL: http://localhost:8080/{artifactId}/
Or you can manually remove the application by removing {artifactId}.war
from the WILDFLY_HOME/standalone/deployments/
directory.