Question: I have a *Spring Security* configuration where I have to use encrypted properties. I have utility static method `PasswordUtil.decode()` by which I can decode a property for the further usage.

Following solution works, but the particular *SpEL* looks quite ugly to me. So, my question: **Is it possible to refactor given *SpEL* expression to something nicer/shorter/idiomatic?**

```java
@Configuration
@EnableWebSecurity
public class SecurityConfiguration extends WebSecurityConfigurerAdapter {

    @Value("#{T(my.package.PasswordUtil).decode('${signkey.password}')}")
    private String signKeyPassword;

}

```

Answer: 
Yes, it is possible as `@Value` may be used as meta annotation:

Option 1: Override @Value value:

```
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.FIELD)
@Value("")
public @interface SignKeyPassword {

    @AliasFor(annotation=Value.class, attribute="value")
    String value() default "#{T(my.package.PasswordUtil).decode('${signkey.password}')}";

}

```

Option 2: Separate annotation for each property:

```
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.FIELD)
@Value("#{T(my.package.PasswordUtil).decode('${signkey.password}')}")
public @interface SignKeyPassword {
}

@Configuration
@EnableWebSecurity
public class SecurityConfiguration extends WebSecurityConfigurerAdapter {

    @SignKeyPassword
    private String signKeyPassword;

}

```

Option 3: Implement `InstantiationAwareBeanPostProcessor` to define own injection login
An alternative to [@dimitrisli](https://stackoverflow.com/users/185723/dimitrisli)'s *SpEL* function could be a bean reference as described in the [reference guide](https://docs.spring.io/spring/docs/current/spring-framework-reference/core.html#expressions-bean-references). This looks more comprehensible to me, because the bean is defined in the same `@Configuration`. (Plus, the decrypting method doesn't have to be `static`.)

I'm just wondering if the bean resolving could be done in simpler way.

**Bean resolving**

```java
public class PassportUtilResolver implements BeanFactoryPostProcessor {

    @Override
    public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
        beanFactory.setBeanExpressionResolver(new StandardBeanExpressionResolver() {

            @Override
            protected void customizeEvaluationContext(StandardEvaluationContext evalContext) {
                evalContext.setBeanResolver(new BeanResolver() {

                    @Override
                    public Object resolve(EvaluationContext context, String beanName) throws AccessException {
                        if ("passwordUtil".equals(beanName)) {
                            return new PasswordUtil();
                        }

                        return null;
                    }
                });
            }
        });
    }
}

```

**Usage**

```java
@Configuration
@EnableWebSecurity
public class SecurityConfiguration extends WebSecurityConfigurerAdapter {

    @Value("#{@passwordUtil.decode('${regis.saml.signkey.password}')}")
    private String signKeyPassword;

    @Bean
    public PasswordUtil passwordUtil() {
        return new PasswordUtil();
    }

}

```