Skip to content

Latest commit

 

History

History
114 lines (83 loc) · 5.21 KB

README.adoc

File metadata and controls

114 lines (83 loc) · 5.21 KB

spring-greeter: Greeter Example using Spring 4.x

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

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:

  1. Enter a name in the username field and click on Greet!.

  2. If you enter a username that is not in the database, you get a message No such user exists!`.

  3. If you enter a valid username, you get a message "Hello, " followed by the user’s first and last name.

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

  5. 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 {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.

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)

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

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.

+

$ mvn dependency:sources
$ mvn dependency:resolve -Dclassifier=javadoc