https://github.com/opengood-aio/spring-constants
Library containing reusable constants for Spring and Spring Boot
https://github.com/opengood-aio/spring-constants
library protected-branches-true update-copyright-current-year
Last synced: 6 months ago
JSON representation
Library containing reusable constants for Spring and Spring Boot
- Host: GitHub
- URL: https://github.com/opengood-aio/spring-constants
- Owner: opengood-aio
- License: mit
- Created: 2023-11-12T23:02:07.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2025-05-23T00:28:49.000Z (about 1 year ago)
- Last Synced: 2025-05-23T01:09:47.963Z (about 1 year ago)
- Topics: library, protected-branches-true, update-copyright-current-year
- Language: Kotlin
- Homepage:
- Size: 84 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
- Codeowners: .github/CODEOWNERS
Awesome Lists containing this project
README
# Spring Constants Library
[](https://github.com/opengood-aio/spring-constants/actions?query=workflow%3Abuild)
[](https://github.com/opengood-aio/spring-constants/actions?query=workflow%3Arelease)
[](https://github.com/opengood-aio/spring-constants/actions/workflows/codeql.yml)
[](https://codecov.io/gh/opengood-aio/spring-constants)
[](https://github.com/opengood-aio/spring-constants/releases/latest)
[](https://search.maven.org/search?q=g:%22io.opengood.constants%22%20AND%20a:%22spring-constants%22)
[](https://raw.githubusercontent.com/opengood-aio/spring-constants/master/LICENSE)
Library containing reusable constants for Spring and Spring Boot
## Compatibility
* Java 21
* Spring Boot 3
## Setup
### Add Dependency
#### Gradle
```groovy
implementation("io.opengood.constants:spring-constants:VERSION")
```
#### Maven
```xml
io.opengood.constants
spring-constants
VERSION
```
**Note:** See *Release* version badge above for latest version.
## Features
**Note:** All examples are provided in Kotlin
### Reusable Spring Properties
Common Spring properties are often referenced in code for importing
configuration values. Rather than defining these constantly, simply refer to
them as constants.
| Constant | Spring Property |
|------------------------------------------|--------------------------------|
| `SpringProperties.APPLICATION_NAME` | `spring.application.name` |
| `SpringProperties.DATA_MONGODB_DATABASE` | `spring.data.mongodb.database` |
| `SpringProperties.DATA_MONGODB_HOST` | `spring.data.mongodb.host` |
| `SpringProperties.DATA_MONGODB_PASSWORD` | `spring.data.mongodb.password` |
| `SpringProperties.DATA_MONGODB_PORT` | `spring.data.mongodb.port` |
| `SpringProperties.DATA_MONGODB_URI` | `spring.data.mongodb.uri` |
| `SpringProperties.DATA_MONGODB_USERNAME` | `spring.data.mongodb.username` |
---
### Reusable Spring Property Placeholders
Similarly, when using `@Value` to import Spring property values, one needs to
wrap `${}` around the property. These are also provided as constants one can
simply refer.
| Constant | Spring Property Placeholder |
|----------------------------------------------------|-----------------------------------|
| `SpringPropertyPlaceholders.APPLICATION_NAME` | `${spring.application.name}` |
| `SpringPropertyPlaceholders.DATA_MONGODB_DATABASE` | `${spring.data.mongodb.database}` |
| `SpringPropertyPlaceholders.DATA_MONGODB_HOST` | `${spring.data.mongodb.host}` |
| `SpringPropertyPlaceholders.DATA_MONGODB_PASSWORD` | `${spring.data.mongodb.password}` |
| `SpringPropertyPlaceholders.DATA_MONGODB_PORT` | `${spring.data.mongodb.port}` |
| `SpringPropertyPlaceholders.DATA_MONGODB_URI` | `${spring.data.mongodb.uri}` |
| `SpringPropertyPlaceholders.DATA_MONGODB_USERNAME` | `${spring.data.mongodb.username}` |
Example:
```kotlin
import io.opengood.constants.spring.SpringPropertyPlaceholders
@Configuration
class AppConfig {
@Bean
fun bean(@Value(SpringPropertyPlaceholders.APPLICATION_NAME) value: String): String {
// configure bean
}
}
```
---
### Reusable Spring Property Settings
Sometimes one needs to use defined Spring property settings and remembering a
specific property is hard. Constants are provided to simplify this:
| Constant | Spring Property Setting |
|---------------------------------------------------|-----------------------------------------------------|
| `SpringPropertySettings.BEAN_DEFINITION_OVERRIDE` | `spring.main.allow-bean-definition-overriding=true` |
Example:
```kotlin
import io.opengood.constants.spring.SpringPropertySettings
@SpringBootTest(
classes = [TestApplication::class],
properties = [SpringPropertySettings.BEAN_DEFINITION_OVERRIDE],
webEnvironment = WebEnvironment.RANDOM_PORT
)
class ControllerTest : WordSpec() {
// do stuff
}
```