spring value # vs $

In the Spring framework, # and $ are used as prefixes to denote different types of expressions in various contexts. The # prefix is used for SpEL (Spring Expression Language), while the $ prefix is used for property placeholder resolution.

  1. # (SpEL - Spring Expression Language):

    • The # prefix is used to denote Spring Expression Language (SpEL) expressions.
    • SpEL is a powerful expression language that allows you to query and manipulate objects during the runtime.
    • Example: @Value("#{someBean.someProperty}")
  2. $ (Property Placeholder):

    • The $ prefix is used for property placeholder resolution in Spring.
    • It is commonly used in XML-based configuration files and @Value annotations to inject values from properties files or system properties.
    • Example: @Value("${database.url}")