0.10. Infrastructure Code

From the book:

Most of us have used dynamic proxies, often without realizing it. A lot of frameworks and tools are built on dynamic proxies. Even the humble annotation is implemented with dynamic proxies. These examples are a small sample of where we might find them in use.

Build tools like Gradle use proxies for models, tasks, actions, and listeners. Examples include BuildOperationListenerStandardOutputListener, and ProgressListener. Maven uses them for plugin management through the MavenPluginManager and CircularDependencyProxy.

Application containers like JBoss and Spring Framework use proxies for dependency injection. Some examples are @Inject@Qualifier@Autowired, and @Bean. Scoping and lifecycle management also use dynamic proxies.

Persistence management with JPA within these containers uses proxies — for example, @Entity@Id@GeneratedValue@Table, and @JoinColumn. In Spring, we can derive a custom repository by extending the Repository interface. In the background, a multi-interface dynamic decorating proxy takes care of the details.

If we choose Hibernate for ORM, then proxies surround HibernateEntityManagerFactoryHibernateEntityManager, and EntityManagerProxy. Spring’s ConnectionProxy is a dynamic proxy of java.sql.Connection.

Again in Spring, a dynamic proxy for InitBinder binds HTTP form fields with a data model. Dynamic proxies are used under the hood by many of the frameworks we use every day: Spring Framework, WildFly, NetBeans Platform, Apache Tomcat, and OpenJDK, among many others.

Complete and Continue  
Discussion

0 comments