title: How to test if @PreAuthorize with custom bean-spel is valid?
body: <p>I have a many <code>@RestController</code>s with methods like:</p>
  
  <pre><code>@PreAuthorize("@myBean.myMethod(#param1, #param2)")
  public void foo(String param1, Long param2) {}
  </code></pre>
  
  <p>And somewhere </p>
  
  <pre><code>@Component
  public class MyBean {
      public boolean myMethod(String param1, Long param2) {
  
          return importantSecurityCheck();
      }
  }
  </code></pre>
  
  <p><strong>It works very well</strong>, <em>but</em> I want to avoid possible stupid bugs after refactoring (because as far as I know spring doesn't detect error until method is invoked), so my idea was to write test which will check if expression is valid (e.g. parameters have same type and names are valid).</p>
  
  <p>I tried to do something like this:</p>
  
  <pre><code>@Test
  public void checkSecurityExpressions() {
   Map&lt;String, Object&gt; beansWithAnnotation = applicationContext.getBeansWithAnnotation(RestController.class);
  
      beansWithAnnotation.forEach((name, bean) -&gt; {
          Method[] methods = AopUtils.getTargetClass(bean).getMethods();
  
          for (Method method : methods) {
              PreAuthorize annotation = method.getAnnotation(PreAuthorize.class);
  
              if (annotation != null) {
  
                  String securityExpression = annotation.value();
  
                  System.out.println(securityExpression);
              }
  
          }
      });
  }
  </code></pre>
  
  <p>Which finds expressions nicely, but all <code>ExpressionParser</code> examples which I found work with simpler expressions (without security context, even without <code>@</code> at the beginning).</p>
  
  <p>How to check it's correctness? Or maybe there are better solutions for this problem?</p>