#1
If you're building a Dropwizard service and want to use OracleDB as your persistent store, this guide shows you how—using Docker for easy local development, and Kubernetes to manage secure credentials in production. By separating your configuration into config-dev.yml and config-prod.yml, you’ll keep everything tidy and environment-specific.

1. Add Dependencies to pom.xml

Start by including these core dependencies:
<dependencies>
  <!-- Dropwizard framework -->
  <dependency>
    <groupId>io.dropwizard</groupId>
    <artifactId>dropwizard-core</artifactId>
    <version>${dropwizard.version}</version>
  </dependency>

  <!-- Oracle JDBC driver -->
  <dependency>
    <groupId>com.oracle.database.jdbc</groupId>
    <artifactId>ojdbc8</artifactId>
    <version>${oracle.jdbc.version}</version>
  </dependency>

  <!-- Kubernetes client (optional) -->
  <dependency>
    <groupId>io.fabric8</groupId>
    <artifactId>kubernetes-client</artifactId>
    <version>${fabric8.version}</version>
  </dependency>
</dependencies>
You’ll get Dropwizard’s services, Oracle driver support, and optional Kubernetes integration for production settings.

2. Run OracleDB Locally with Docker

Use Docker to spin up a local Oracle instance:
docker run -d --name oracle-dev \
  -p 1521:1521 \
  -e ORACLE_PWD=DevPass123 \
  gvenzl/oracle-xe:latest
This provides Oracle Express Edition listening on localhost:1521 with a password you can use for your dev database.

3. Create config-dev.yml for Development

Define the connection properties for local use:
server:
  applicationConnectors:
    - type: http
      port: 8080

database:
  driverClass: oracle.jdbc.OracleDriver
  user: system
  password: DevPass123
  url: jdbc:oracle:thin:@localhost:1521/XEPDB1
  validationQuery: SELECT 1 FROM DUAL
Extend the configuration class:
public class DbConfig {
  @JsonProperty public String driverClass;
  @JsonProperty public String user;
  @JsonProperty public String password;
  @JsonProperty public String url;
  @JsonProperty public String validationQuery;
}
public class AppConfig extends Configuration {
  @JsonProperty("database")
  public DbConfig database = new DbConfig();
}
Create and manage the connection in your Application:
ManagedDataSource ds = database.build(environment.metrics(), "db");
environment.lifecycle().manage(ds);
Run the app locally:
java -jar target/myapp.jar server config-dev.yml
Now your Dropwizard service is connected to OracleDB for dev testing.

4. Prepare for Kubernetes in Production

In production, store sensitive data using Kubernetes ConfigMaps and Secrets:
kubectl create configmap oracledb-config \
  --from-literal=DB_URL=jdbc:oracle:thin:@oracle-svc:1521/ORCLPDB1 \
  --from-literal=DB_DRIVER=oracle.jdbc.OracleDriver \
  --from-literal=DB_VALIDATION_QUERY=SELECT+1+FROM+DUAL

kubectl create secret generic oracledb-secret \
  --from-literal=DB_USER=produser \
  --from-literal=DB_PASSWORD=ProdPass456
Secrets and ConfigMaps store connection details outside of your code base.

5. Create config-prod.yml for Secure Production Config

Your production config reads environment variables:
server:
  applicationConnectors:
    - type: http
      port: 8080

database:
  driverClass: ${DB_DRIVER}
  user: ${DB_USER}
  password: ${DB_PASSWORD}
  url: ${DB_URL}
  validationQuery: ${DB_VALIDATION_QUERY}
Dropwizard substitutes these at runtime.

6. Kubernetes Deployment Snippet

Inject configuration into your container:
env:
  - name: DB_URL
    valueFrom:
      configMapKeyRef:
        name: oracledb-config
        key: DB_URL
  - name: DB_DRIVER
    valueFrom:
      configMapKeyRef:
        name: oracledb-config
        key: DB_DRIVER
  - name: DB_VALIDATION_QUERY
    valueFrom:
      configMapKeyRef:
        name: oracledb-config
        key: DB_VALIDATION_QUERY
  - name: DB_USER
    valueFrom:
      secretKeyRef:
        name: oracledb-secret
        key: DB_USER
  - name: DB_PASSWORD
    valueFrom:
      secretKeyRef:
        name: oracledb-secret
        key: DB_PASSWORD
Deploy with:
java -jar myapp.jar server config-prod.yml
Your application reads securely from Kubernetes in production.

7. Why This Setup Works Well

  • Local development is simplified with Docker and a clear config file.
  • Production is secure, with credentials in Kubernetes Secrets, not code.
  • Clean environment separation, thanks to custom config files per environment.
  • Scalable and maintainable, ready for rugged, enterprise use cases.
By combining Dropwizard’s flexible configuration, OracleDB's enterprise-grade database, Docker for dev environments, and Kubernetes for secure production deployment, you get a scalable, secure, and manageable architecture. With clear separation between local and production configurations, your Dropwizard app is ready for real-world business needs with confidence.

image quote pre code