title: Register bean (with a custom bean name) programmatically
body: <p>My goal is to register bean (with a custom bean name) programmatically.</p>
  
  <pre><code>@ComponentScan({ "com.test" })
  public class AppConfiguration {
  
      //@Bean("test-bean")
      @Bean
      public Definition definition() {
          return () -&gt; Test.class;
      }
  }
  
  @Named
  @Scope("prototype")
  public class Test extends DefinitionActor&lt;?&gt; {
     ....
  }
  </code></pre>
  
  <p>Here, I use Akka and hence I have to go with @Scope("prototype").</p>
  
  <p>I don't want to hard code the bean name to test-bean for some reason.</p>
  
  <p>Hence, I am using the BeanPostProcessor.</p>
  
  <pre><code>@Component
  public class BeanDefinitionRegistryPP implements BeanDefinitionRegistryPostProcessor, EnvironmentAware {
      private Environment env;
  
      @Override
      public void setEnvironment(final Environment environment) {
          this.env = environment;
      }
  
      @Override
      public void postProcessBeanDefinitionRegistry(final BeanDefinitionRegistry registry) throws BeansException {
  }
  </code></pre>
  
  <p>I am getting AKKA error if I go with this way.</p>
  
  <pre><code>Caused by: akka.actor.ActorInitializationException: You cannot create an instance of [com.test.Test] explicitly using the constructor (new). You have to use one of the 'actorOf' factory methods to create a new actor. See the documentation.
      at akka.actor.ActorInitializationException$.apply(Actor.scala:181) ~[akka-actor_2.11-2.4.19.jar:na]
  </code></pre>
  
  <p>The bean post processor work with non-Akka project. Is there any other way to set the bean name programmatically even I use prototype scope.</p>