title: Why is applicationContext.getBean(beanName) returning null, when it clearly exists?
body: <p>I'm working on an experimental method that will take a bean name, property name, and value expression, and use the Spring SPeL to assign that property of that bean with that value.  The class with this method is a ManagedResource, so I can reach it from JMX.</p>
  
  <p>I then defined another simple class, gave it a property and a Component annotation.  I also Autowire this class into the jmx bean class, just to verify the bean of that type exists.</p>
  
  <p>I then fired up the SpringBoot service.</p>
  
  <p>I then called the method from VisualVM.</p>
  
  <p>It failed, saying it couldn't find the bean with that name.</p>
  
  <p>So, now with more detail.</p>
  
  <p>Here's the first class:</p>
  
  <pre><code>@Component
  @ManagedResource
  public class JMXDemonstration {
      @Autowired
      private ApplicationContext  applicationContext;
      @Autowired
      private SomeRandomThing thing;
  
      @Value("${jmxDemonstration.name}")
      private String name;
  
      @ManagedAttribute
      public String getName() { return name; }
  
      @ManagedAttribute
      public void setName(String name) { this.name = name; }
  
      @ManagedOperation
      public String buildHelloWorldMessage() {
          return "Hello, " + name + ": " + thing.getId();
      }
  
      @ManagedOperation
      public void assignValueToBeanProperty(String beanName, String propertyName, String expression) {
          Object  bean    = applicationContext.getBean(beanName);
  
          ExpressionParser        parser      = new SpelExpressionParser();
          SimpleEvaluationContext evalContext = SimpleEvaluationContext.forReadWriteDataBinding().build();
  
          parser.parseExpression(propertyName).setValue(evalContext, bean, expression);
      }
  }
  </code></pre>
  
  <p>And here's the other class:</p>
  
  <pre><code>@Component
  public class SomeRandomThing {
      private String  id;
  
      public String getId() { return id; }
  
      public void setId(String id) { this.id = id; }
  }
  </code></pre>
  
  <p>When I call the method from VisualVM, I pass "SomeRandomThing", "id", and "xxx".</p>
  
  <p>This fails with:</p>
  
  <pre><code>org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'SomeRandomThing' available
  at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanDefinition(DefaultListableBeanFactory.java:685)
  </code></pre>
  
  <p>I also set a breakpoint in the method and looked at "this", and confirmed that there is a valid "thing" property (if there wasn't, the service wouldn't have started).</p>
  
  <p>So do I have the default bean name algorithm wrong?  It seems hard to believe, because I also ran a test of "JMXDemonstration", "name", and "George", and that worked perfectly fine.</p>
  
  <p><strong>Update</strong>:</p>
  
  <p>Also note that calling "applicationContext.getBean(SomeRandomThing.class)" returns the bean instance of that class, and also calling "applicationContext.getBeanDefinitionNames()" returns an array that does not contain "SomeRandomThing", but it does contain "JMXDemonstration".</p>
  
  <p>Why is SomeRandomThing available as a bean through autowiring and through the type, but not through it's bean name?</p>
  
  <p><strong>Update</strong>:</p>
  
  <p>Oh, because the bean name is "someRandomThing", not "SomeRandomThing".  I guess I would have expected the former originally, but when I saw that the bean name for "JMXDemonstration" was "JMXDemonstration", I assumed it would then be "SomeRandomThing", not "someRandomThing".</p>