Hackforge Academy

Category: java

Spel in spring value and bean configuration

Published on 30 Sep 2026

Explanation

SpEL can be used with @Value to calculate or dynamically resolve values during Spring bean creation.

Code:

@Value("#{10 + 20}")
private int total;

// total = 30

Explanation

SPEL can reference another Spring bean using the @beanName syntax.

Code:

@Value("#{@pricingService.getDiscount()}")
private double discount;

Explanation

SpEL can access properties from application configuration and combine them with expressions.

Code:

@Value("${app.max-users}")
private int maxUsers;

Explanation

Conditional expressions can be used inside @Value to select different values.

Code:

@Value("#{${app.enabled} ? 'ACTIVE' : 'INACTIVE'}")
private String status;

Explanation

SpEL can be used in bean configuration when a bean property needs to be calculated dynamically.

Code:

@Bean
public String applicationMode() {
    return "#{systemProperties['app.mode']}";
}

πŸš€ Learn Spring Boot with real-world projects

πŸ’‘ Build REST APIs step by step

🧠 Improve backend development skills

🎯 Get career-ready practical training

Join Our Free WhatsApp Community

Direct access to niche-specific mentors and peers on WhatsApp.

🐍

Python Community

Discuss Django, FastAPI, AI integration, and automation scripts with 15k+ developers.

Join Python Community
βš›οΈ

React Community

Master Next.js, Framer Motion, and State Management. Share your latest UI components.

Join React Community
β˜•

Java Community

Deep dives into Spring Boot, Microservices architecture, and high-performance backend ops.

Join Java Community