Spring Boot application.properties – Complete guide to configuring databases, messaging, and security
When you build modern microservices with Spring Boot, your application typically interacts with databases, caches, messaging brokers, authentication services, and more. Instead of hardcoding configurations, Spring Boot uses an externalized configuration mechanism through application.properties or application.yml. At Q2BSTUDIO, a custom software and application development company specializing in artificial intelligence, cybersecurity, AWS and Azure cloud services, business intelligence services, AI for enterprises, AI agents, and Power BI, we design custom software solutions and consulting to get your microservices production-ready.
1 MySQL Configuration
Spring Boot auto-configures DataSource and JPA if it detects spring-boot-starter-data-jpa on the classpath. Example application.properties
# =============================== MySQL Database Configuration ===============================
spring.datasource.url=jdbc:mysql://localhost:3306/mydb?useSSL=false&serverTimezone=UTC
spring.datasource.username=root
spring.datasource.password=secret
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.jpa.hibernate.ddl-auto=update
spring.jpa.show-sql=true
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL8Dialect
Best practice notes: ddl-auto update is useful in development; in production use validate or none. For secrets, use environment variables, AWS Secrets Manager, or HashiCorp Vault. Q2BSTUDIO implements cybersecurity policies and secret management in AWS and Azure cloud deployments.
Equivalent YAML
spring: datasource: url: jdbc:mysql://localhost:3306/mydb?useSSL=false&serverTimezone=UTC username: root password: secret driver-class-name: com.mysql.cj.jdbc.Driver jpa: hibernate: ddl-auto: update show-sql: true properties: hibernate: dialect: org.hibernate.dialect.MySQL8Dialect
2 MongoDB Configuration
If you add spring-boot-starter-data-mongodb, Spring Boot automatically creates MongoTemplate. Example application.properties
# =============================== MongoDB Configuration ===============================
spring.data.mongodb.uri=mongodb://localhost:27017/mydatabase
spring.data.mongodb.database=mydatabase
Equivalent YAML
spring: data: mongodb: uri: mongodb://localhost:27017/mydatabase database: mydatabase
3 Redis Configuration
For caching or key-value storage with spring-boot-starter-data-redis
# =============================== Redis Configuration ===============================
spring.data.redis.host=localhost
spring.data.redis.port=6379
spring.data.redis.password=
spring.data.redis.timeout=60000
Equivalent YAML
spring: data: redis: host: localhost port: 6379 password: timeout: 60000
4 Apache Kafka Configuration
For event-driven microservices with spring-kafka
# =============================== Kafka Configuration ===============================
spring.kafka.bootstrap-servers=localhost:9092
spring.kafka.consumer.group-id=my-group
spring.kafka.consumer.auto-offset-reset=earliest
spring.kafka.consumer.key-deserializer=org.apache.kafka.common.serialization.StringDeserializer
spring.kafka.consumer.value-deserializer=org.apache.kafka.common.serialization.StringDeserializer
spring.kafka.producer.key-serializer=org.apache.kafka.common.serialization.StringSerializer
spring.kafka.producer.value-serializer=org.apache.kafka.common.serialization.StringSerializer
Equivalent YAML
spring: kafka: bootstrap-servers: localhost:9092 consumer: group-id: my-group auto-offset-reset: earliest key-deserializer: org.apache.kafka.common.serialization.StringDeserializer value-deserializer: org.apache.kafka.common.serialization.StringDeserializer producer: key-serializer: org.apache.kafka.common.serialization.StringSerializer value-serializer: org.apache.kafka.common.serialization.StringSerializer
5 JWT Configuration
JWT is not auto-configured; define properties for your custom security layer
# =============================== JWT Configuration ===============================
jwt.secret=my-super-secret-key
jwt.expiration=3600000 # 1 hour in milliseconds
jwt.refresh-expiration=604800000 # 7 days
In production environments, use keys managed by secret services with periodic rotation. Q2BSTUDIO integrates identity and cybersecurity solutions with JWT and MFA for custom applications and custom software.
Equivalent YAML
jwt: secret: my-super-secret-key expiration: 3600000 refresh-expiration: 604800000
6 OAuth2 Configuration
For OAuth2 login with Google, GitHub, or external providers using spring-boot-starter-oauth2-client
# =============================== OAuth2 Configuration Google Example ===============================
spring.security.oauth2.client.registration.google.client-id=your-client-id
spring.security.oauth2.client.registration.google.client-secret=your-client-secret
spring.security.oauth2.client.registration.google.scope=email,profile
spring.security.oauth2.client.registration.google.redirect-uri={baseUrl}/login/oauth2/code/{registrationId}
spring.security.oauth2.client.provider.google.authorization-uri=https://accounts.google.com/o/oauth2/auth
spring.security.oauth2.client.provider.google.token-uri=https://oauth2.googleapis.com/token
spring.security.oauth2.client.provider.google.user-info-uri=https://www.googleapis.com/oauth2/v3/userinfo
Equivalent YAML
spring: security: oauth2: client: registration: google: client-id: your-client-id client-secret: your-client-secret scope: email,profile redirect-uri: {baseUrl}/login/oauth2/code/{registrationId} provider: google: authorization-uri: https://accounts.google.com/o/oauth2/auth token-uri: https://oauth2.googleapis.com/token user-info-uri: https://www.googleapis.com/oauth2/v3/userinfo
7 Logging for Debugging
Detailed logging is invaluable when integrating multiple services
# =============================== Logging Configuration ===============================
logging.level.root=INFO
logging.level.org.springframework=DEBUG
logging.level.org.hibernate.SQL=DEBUG
logging.level.org.hibernate.type.descriptor.sql.BasicBinder=TRACE
Equivalent YAML
logging: level: root: INFO org.springframework: DEBUG org.hibernate.SQL: DEBUG org.hibernate.type.descriptor.sql.BasicBinder: TRACE
8 Profile-based Configuration
Use environment-specific files to separate development and production configurations. Example file names: application-dev.properties, application-prod.properties. You can also use application-dev.yml and application-prod.yml and activate profiles with spring.profiles.active. At Q2BSTUDIO, we implement CI/CD pipelines that manage profiles and secrets in AWS and Azure cloud environments for secure deployments.
Additional best practices
Use environment variables for credentials, encrypt secrets, audit access, and apply least-privilege principles. Monitor connections and metrics with cloud tools and observability solutions. For projects requiring artificial intelligence or data analytics, use business intelligence services and Power BI integration. Q2BSTUDIO offers comprehensive services in artificial intelligence, AI for enterprises, AI agent development, and Power BI consulting to improve decision-making.
Conclusion
Externalizing configuration with application.properties and application.yml makes it easier to port applications between environments and maintain good operational practices. If you need help configuring Spring Boot, cloud architectures, cybersecurity solutions, or developing custom software and custom applications with artificial intelligence capabilities, contact Q2BSTUDIO, specialists in AWS and Azure cloud services, business intelligence services, AI agents, and Power BI.




