Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Added simple example of referencing a client bean declared in Spring

...

The second bean definition is for the client. In this case it implements the HelloWorld interface and is created by the proxyFactory <bean> by calling the create() method. You can then reference this "client" bean and inject it anywhere into your application. Here is an example of a very simple Java class which accesses the client bean:

Code Block
java
java

include org.springframework.context.support.ClassPathXmlApplicationContext;

public final class HelloWorldClient {

     private HelloWorldClient() { }

     public static void main(String args[]) throws Exception {
         ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
             new String[]{"my/path/to/client-beans.xml"});

         HelloWorld client = (HelloWorld)context.getBean("client");

         String response = client.sayHi("Dan");
         System.out.println("Response: " + response);
         System.exit(0);
     }
} 

The ProxyFactoryBean supports many other properties:

...