title: Spring AOP : Can we access bean object by getBean("beanName") method after applying ProxyFactoryBean on that Bean?
body: <p>I have applied a 'BeforeAdvice' through 'ProxyFactoryBean' on a Bean of type "MyXMLApplication" now I am not able to access the Bean object directly{by getBean(MyXMLApplication.class)}, it is giving error :-</p>
  
  <p>by setter dependency injection myxml
  Exception in thread "main" org.springframework.beans.factory.NoUniqueBeanDefinitionException: No qualifying bean of type [com.journaldev.spring.di.consumer.MyXMLApplication] is defined: expected single matching bean but found 2: MyXMLApp,proxy</p>
  
  <p>However I am able to get the bean object by "proxy" bean object{(MyXMLApplication)context.getBean("proxy")}. Now my question is after applying proxy on any bean is there any way to access it directly without proxy bean.</p>
  
  <p>My code is:</p>
  
  <pre><code>********Before Advisor*********
  
  
  
  
   public class MyBeforeAdvisor implements MethodBeforeAdvice{
          public void before(Method arg0, Object[] arg1, Object arg2) throws Throwable {
              // TODO Auto-generated method stub
              System.out.println("before advice run");
          }
      }
  
  *********applicationContext.xml********
  
  
  &lt;bean id="twitter" class="com.journaldev.spring.di.services.TwitterService"&gt;&lt;/bean&gt;
  &lt;bean id="MyXMLApp" class="com.journaldev.spring.di.consumer.MyXMLApplication" autowire="byType"/&gt;
  &lt;bean id="beforeAdvice" class="com.journaldev.spring.aop.advisor.MyBeforeAdvisor"&gt;&lt;/bean&gt;
  &lt;bean id="proxy" class="org.springframework.aop.framework.ProxyFactoryBean"&gt;
          &lt;property name="target" ref="MyXMLApp"&gt;&lt;/property&gt;
          &lt;property name="interceptorNames"&gt;
            &lt;list&gt;
               &lt;value&gt;beforeAdvice&lt;/value&gt;
            &lt;/list&gt;
          &lt;/property&gt;
  &lt;/bean&gt;
  
  
  **********Main Bean Class************
  
  
    public class MyXMLApplication {
          private MessageService service;
          public void setService(MessageService svc){
              System.out.println("by setter dependency injection myxml");
              this.service=svc;
          }
          public boolean processMessage(String msg, String rec) {
              return this.service.sendMessage(msg, rec);
          }
      }
  
  
  
  **********Autowired Bean Interface ******* 
  
  
      public interface MessageService {
              boolean sendMessage(String msg, String rec);
          }
  
  **********Autowired Bean Impl*********
  
  
   public class TwitterService implements MessageService {
          public boolean sendMessage(String msg, String rec) {
              System.out.println("Twitter message Sent to "+rec+ " with Message="+msg);
              return true;
          }
      }
  
  
  
   ************* Main function**********
  
  
        public static void main(String[] args) {
                  ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
                          "applicationContext.xml");
       MyXMLApplication app = context.getBean(MyXMLApplication.class); --&gt; Not Working
  
      //MyXMLApplication app = (MyXMLApplication)context.getBean("proxy"); --&gt;working
  
                  app.processMessage("Hi", "abc@abc.com");
                  context.close();
              }
  </code></pre>