[id="sbo-deploying-the-spring-petclinic-sample-application_{context}"]
= Deploying the Spring PetClinic sample application

To deploy the Spring PetClinic sample application on an {product-title} cluster, you must use a deployment configuration and configure your local environment to be able to test the application.

[discrete]
.Procedure

. Deploy the `spring-petclinic-rest` application with the `PostgresCluster` custom resource (CR) by running the following command in shell:
+
----
$ oc apply -f - << EOD
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: spring-petclinic-rest
  namespace: my-postgresql
  labels:
    app: spring-petclinic-rest
spec:
  replicas: 1
  selector:
    matchLabels:
      app: spring-petclinic-rest
  template:
    metadata:
      labels:
        app: spring-petclinic-rest
    spec:
      containers:
        - name: application
          image: quay.io/baijum/spring-petclinic-rest:latest
          env:
          - name: SPRING_PROFILES_ACTIVE
            value: postgresql,spring-data-jpa
          ports:
          - name: http
            containerPort: 9966
---
apiVersion: v1
kind: Service
metadata:
  name: spring-petclinic-rest
  namespace: my-postgresql
spec:
  ports:
  - port: 80
    targetPort: 9966
  selector:
    app: spring-petclinic-rest
EOD
----
+
The output verifies that the Spring PetClinic sample application is created and deployed:
+
.Example output
----
deployment.apps/spring-petclinic-rest created
service/spring-petclinic-rest created
----

. Set up port forwarding from the application port to access the sample application from your local environment:
+
----
$ oc port-forward --address 0.0.0.0 svc/spring-petclinic-rest 9966:80 -n my-postgresql
----

. Access link:http://localhost:9966/petclinic[http://localhost:9966/petclinic].
+
You can now remotely access the Spring PetClinic sample application at localhost:9966.
+
[NOTE]
====
The application is not yet connected to the database service. If you try to interact with the application, it will return errors.
====
+
For example, if you try to access the list of all pets using `curl`, you can see an error message similar to the following sample message:
+
----
$ curl -X GET "http://localhost:9966/petclinic/api/pets" -H "accept: application/json"

{"className":"org.springframework.transaction.CannotCreateTransactionException","exMessage":"Could
not open JPA EntityManager for transaction; nested exception is
org.hibernate.exception.JDBCConnectionException: Unable to acquire JDBC
Connection"}
----

You can now use the {servicebinding-title} to connect the application to the database service.
