Skip to content

io microsphere spring config context annotation ResourcePropertySource

github-actions[bot] edited this page Jun 18, 2026 · 18 revisions

ResourcePropertySource

Type: Annotation | Module: microsphere-spring-context | Package: io.microsphere.spring.config.context.annotation | Since: 1.0.0

Source: microsphere-spring-context/src/main/java/io/microsphere/spring/config/context/annotation/ResourcePropertySource.java

Overview

A variant of the PropertySource @PropertySource annotation that has some limitations:

- The `PropertySource @PropertySource` annotation can't meta-annotate the another annotation
- The `PropertySource @PropertySource` annotation can't control the order of `org.springframework.core.env.PropertySource`
- The `PropertySource @PropertySource` annotation can't be `Inherited inherited`
- The `PropertySource#value PropertySource#value()` attribute does not support the `Resource resource` location wildcards
- The `PropertySource#encoding() PropertySource#encoding()` attribute does not specify the default encoding for the `Resource resource`

This annotation provides additional features not available with the standard PropertySource, such as:

- Support for meta-annotation usage
- Control over the order in which property sources are added to Spring's Environment
- Inheritance through the use of the `Inherited` annotation
- Support for resource location wildcards in the resource paths
- Ability to specify default encoding for property resources

Examples Usage

Basic Usage

To load a simple properties file from the classpath:

{@code

### Declaration

```java
public @interface ResourcePropertySource
```

**Author:** Mercy

## Version Information

- **Introduced in:** `1.0.0`
- **Current Project Version:** `0.2.27-SNAPSHOT`

## Version Compatibility

This component is tested and compatible with the following Java versions:

| Java Version | Status |
|:---:|:---:|
| Java 17 | ✅ Compatible |
| Java 21 | ✅ Compatible |
| Java 25 | ✅ Compatible |

## Examples

### Example 1

```java
@ResourcePropertySource("classpath:/com/example/config/app.properties")
public class AppConfig {
}
```

### Example 2

```java
// Make this property source first in the list
@ResourcePropertySource(value = "classpath:/com/example/config/app.properties", first = true)
public class AppConfig {
}
```

### Example 3

```java
@ResourcePropertySource(
    value = "classpath:/com/example/config/*.properties",
    resourceComparator = MyCustomResourceComparator.class
)
public class AppConfig {
}
```

### Example 4

```java
@ResourcePropertySource(
    value = "classpath:/com/example/config/app.properties",
    ignoreResourceNotFound = true
)
public class AppConfig {
}
```

### Example 5

```java
@ResourcePropertySource(
    value = "classpath:/com/example/config/app.properties",
    encoding = "ISO-8859-1"
)
public class AppConfig {
}
```

### Example 6

```java
@ResourcePropertySource(
    value = "classpath:/com/example/config/app.properties",
    factory = MyCustomPropertySourceFactory.class
)
public class AppConfig {
}
```

## Usage

### Maven Dependency

Add the following dependency to your `pom.xml`:

```xml

    io.github.microsphere-projects
    microsphere-spring-context
    ${microsphere-spring.version}

```

> **Tip:** Use the BOM (`microsphere-spring-dependencies`) for consistent version management. See the [Getting Started](https://github.com/microsphere-projects/microsphere-spring#getting-started) guide.

### Import

```java
import io.microsphere.spring.config.context.annotation.ResourcePropertySource;
```

## See Also

- `PropertySource`
- `org.springframework.core.env.PropertySource`
- `Configuration`

---

*This documentation was auto-generated from the source code of [microsphere-spring](https://github.com/microsphere-projects/microsphere-spring).*

Home

spring-context

spring-guice

spring-jdbc

spring-test

spring-web

spring-webflux

spring-webmvc

Clone this wiki locally