Skip to content

DurgeshOnStack/FactoryBean03_Image_Processer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

2 Commits
Β 
Β 
Β 
Β 

Repository files navigation

πŸ–ΌοΈ Spring FactoryBean Image Processor

A professional Spring Core mini project demonstrating the use of FactoryBean, Java-Based Configuration, and Dynamic Bean Creation using properties.

This project dynamically creates different image processor objects like:

  • βœ… Resize Processor
  • βœ… Filter Processor
  • βœ… Watermark Processor

based on the value provided inside the application.properties file.


πŸš€ Features

  • Spring FactoryBean implementation
  • Dynamic object creation
  • Property-based configuration
  • Java annotation configuration
  • Loose coupling using interfaces
  • Easy to extend architecture
  • Beginner-friendly project structure

πŸ› οΈ Technologies Used

  • Java
  • Spring Core
  • FactoryBean
  • Maven
  • Annotation Configuration

πŸ“‚ Project Structure

src/main/java
β”‚
β”œβ”€β”€ com.nit.config
β”‚   └── AppConfig.java
β”‚
β”œβ”€β”€ com.nit.factory
β”‚   └── ImageProcessorFactoryBean.java
β”‚
β”œβ”€β”€ com.nit.main
β”‚   └── TestApp.java
β”‚
β”œβ”€β”€ com.nit.sbeans
β”‚   β”œβ”€β”€ ImageProcessor.java
β”‚   β”œβ”€β”€ ResizeProcessor.java
β”‚   β”œβ”€β”€ FilterProcessor.java
β”‚   └── WatermarkProcessor.java
β”‚
└── com.nit.properties
    └── application.properties

βš™οΈ How It Works

The application reads a property from:

image.process=resize

The FactoryBean checks this value and dynamically creates the required implementation object.

Property Value Generated Bean
resize ResizeProcessor
filter FilterProcessor
watermark WatermarkProcessor

🧠 Core Concept Used

FactoryBean

This project uses Spring's FactoryBean interface for custom object creation.

public class ImageProcessorFactoryBean implements FactoryBean<ImageProcessor>

Instead of Spring directly creating objects, the factory decides which implementation to return at runtime.


πŸ“Œ Important Code Snippets

ImageProcessor Interface

public interface ImageProcessor {
    public void process();
}

Provides abstraction for all processors. :contentReference[oaicite:0]{index=0}


FactoryBean Logic

@Override
public ImageProcessor getObject() throws Exception {

    if("resize".equalsIgnoreCase(imageProcessorType)) {
        return new ResizeProcessor();
    }
    else if("filter".equalsIgnoreCase(imageProcessorType)) {
        return new FilterProcessor();
    }
    if("watermark".equalsIgnoreCase(imageProcessorType)) {
        return new WatermarkProcessor();
    }
    else {
        throw new IllegalArgumentException("This service is not available");
    }
}

Dynamic object creation using property values. :contentReference[oaicite:1]{index=1}


Java Configuration

@Configuration
@PropertySource("com/nit/properties/application.properties")

Loads external properties into Spring container. :contentReference[oaicite:2]{index=2}


Main Class

public static void main(String[] args) {

    AnnotationConfigApplicationContext ctx =
            new AnnotationConfigApplicationContext(AppConfig.class);

    ImageProcessor imageProcessor =
            ctx.getBean(ImageProcessor.class);

    imageProcessor.process();
}

Runs the application and executes the dynamically generated bean. :contentReference[oaicite:3]{index=3}


▢️ How To Run

1️⃣ Clone Repository

git clone https://github.com/your-username/spring-factorybean-imageprocessor.git

2️⃣ Open Project

Open in:

  • IntelliJ IDEA
  • Eclipse
  • VS Code

3️⃣ Configure Processor Type

Inside application.properties

image.process=resize

Available options:

image.process=resize
image.process=filter
image.process=watermark

4️⃣ Run Application

Execute:

TestApp.java

πŸ–₯️ Sample Outputs

Resize Processor

Image resized successfully!

Filter Processor

Image Filtered successfully!

Watermark Processor

Image Watermarked successfully!

πŸ“š Concepts Covered

  • FactoryBean
  • Dynamic Bean Creation
  • Spring Core
  • Java Configuration
  • Dependency Injection
  • Interface-Based Design
  • Loose Coupling

πŸ”₯ Future Improvements

  • Add grayscale processor
  • Add compression processor
  • Real image processing support
  • Convert into Spring Boot application
  • REST API integration
  • File upload support

🀝 Contributing

Contributions are welcome.

  1. Fork repository
  2. Create feature branch
  3. Commit changes
  4. Push code
  5. Open Pull Request

πŸ“œ License

This project is licensed under the MIT License.


πŸ‘¨β€πŸ’» Author

Developed using Java & Spring Core ❀️


⭐ Support

If you found this project useful, give it a ⭐ on GitHub.

About

A Spring Core project demonstrating dynamic bean creation using `FactoryBean` and Java-based configuration. The application dynamically selects and executes different image processors like resize, filter, and watermark based on property configuration.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages