Merge pull request #1 from lordofthejars/error

Introduce Autowired
This commit is contained in:
Burr Sutter 2020-10-19 09:50:45 -04:00 committed by GitHub
commit 798cccfb37
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 56 additions and 6 deletions

BIN
build-config.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 34 KiB

BIN
create-project.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 287 KiB

BIN
db-params.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 240 KiB

BIN
db.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 302 KiB

BIN
mysql-ephimeral.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 292 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 194 KiB

BIN
output-ui.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 356 KiB

BIN
petclinic-deploy.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 162 KiB

BIN
petclinic-url.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 75 KiB

View file

@ -1,3 +1,7 @@
# Sprint PetClinic and OpenShift
## Local Development
``` ```
mvn package mvn package
@ -50,11 +54,54 @@ http://localhost:8080
![Screenshot](screenshot.png) ![Screenshot](screenshot.png)
## For OpenShift:
For OpenShift ### Dev Console
![MySQL Template](mysql-template-settings.png) Create a new OpenShift `Project` with `spring-petclinic-devconsole` name.
Edit the DeploymentConfig for the application pod ![Create Project](create-project.png)
Then move to Developer perspective:
![Dev Perspective](switch-perspective.png)
And create a new MySQL instance by clicking the `+Add` button and choose the `Database` option:
![Add DB](db.png)
Choose MySQL Ephimeral:
![MySQL Ephimeral](mysql-ephimeral.png)
and Push `Instantiate Template`.
Then fill the wizard with the following parameters:
![MySQL Template](db-params.png)
Push the `Create` button.
Let's deploy the Pet Clinic app.
Click the `+Add` button and choose `From Git` type:
Fill the Git repo with the following value `https://github.com/burrsutter/spring-petclinic` and select the project as Java project:
![Pet Clinic Deploy](petclinic-deploy.png)
Push the `Build Configuration` link:
![Build Configuration](build-config.png)
Add the following environment variables for the application Pod:
![DC Env Vars](app-env-vars.png) ![DC Env Vars](app-env-vars.png)
Finally push the `Create` button and wait until the Build is done and the Pod is up and running (dark blue around the deployment bubble).
Then push the Open URL button to view the Pet Clinic app:
![Pet Clinic Deployment](petclinic-url.png)
![Pet Clinic UI](output-ui.png)

View file

@ -15,6 +15,7 @@
*/ */
package org.springframework.samples.petclinic.owner; package org.springframework.samples.petclinic.owner;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.samples.petclinic.visit.VisitRepository; import org.springframework.samples.petclinic.visit.VisitRepository;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.ui.Model; import org.springframework.ui.Model;
@ -41,12 +42,13 @@ class OwnerController {
private static final String VIEWS_OWNER_CREATE_OR_UPDATE_FORM = "owners/createOrUpdateOwnerForm"; private static final String VIEWS_OWNER_CREATE_OR_UPDATE_FORM = "owners/createOrUpdateOwnerForm";
private final OwnerRepository owners; // Comment Autowired
@Autowired
private OwnerRepository owners;
private VisitRepository visits; private VisitRepository visits;
public OwnerController(OwnerRepository clinicService, VisitRepository visits) { public OwnerController(VisitRepository visits) {
this.owners = clinicService;
this.visits = visits; this.visits = visits;
} }
@ -82,6 +84,7 @@ class OwnerController {
@GetMapping("/owners") @GetMapping("/owners")
public String processFindForm(Owner owner, BindingResult result, Map<String, Object> model) { public String processFindForm(Owner owner, BindingResult result, Map<String, Object> model) {
System.out.println("***" + owner.getLastName());
// allow parameterless GET request for /owners to return all records // allow parameterless GET request for /owners to return all records
if (owner.getLastName() == null) { if (owner.getLastName() == null) {
owner.setLastName(""); // empty string signifies broadest possible search owner.setLastName(""); // empty string signifies broadest possible search

BIN
switch-perspective.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 311 KiB